44using System ;
55using System . Collections . Generic ;
66using System . ComponentModel . Design ;
7- using System . Data . SqlClient ;
87using System . Linq ;
98using System . Threading . Tasks ;
9+ using Autofac ;
10+ using Microsoft . Extensions . Configuration ;
11+ using Microsoft . Extensions . DependencyInjection ;
1012using Microsoft . Extensions . Logging ;
1113using Microsoft . WindowsAzure . Storage ;
12- using Microsoft . WindowsAzure . Storage . Blob ;
1314using NuGet . Jobs ;
14- using NuGet . Services . KeyVault ;
15- using NuGet . Services . Sql ;
15+ using NuGet . Jobs . Configuration ;
1616
1717namespace Search . GenerateAuxiliaryData
1818{
19- internal class Job
20- : JobBase
19+ public class Job : JsonConfigurationJob
2120 {
2221 private const string DefaultContainerName = "ng-search-data" ;
2322
@@ -40,40 +39,62 @@ internal class Job
4039 private const string StatisticsReportName = "downloads.v1.json" ;
4140
4241 private List < Exporter > _exportersToRun ;
43- private CloudBlobContainer _destContainer ;
44- private CloudBlobContainer _statisticsContainer ;
42+
43+ private InitializationConfiguration Configuration { get ; set ; }
4544
4645 public override void Init ( IServiceContainer serviceContainer , IDictionary < string , string > jobArgsDictionary )
4746 {
48- var secretInjector = ( ISecretInjector ) serviceContainer . GetService ( typeof ( ISecretInjector ) ) ;
49-
50- var packageDbConnectionString = JobConfigurationManager . GetArgument ( jobArgsDictionary , JobArgumentNames . PackageDatabase ) ;
51- var packageDbConnectionFactory = new AzureSqlConnectionFactory ( packageDbConnectionString , secretInjector ) ;
52-
53- var statisticsDbConnectionString = JobConfigurationManager . GetArgument ( jobArgsDictionary , JobArgumentNames . StatisticsDatabase ) ;
54- var statisticsDbConnectionFactory = new AzureSqlConnectionFactory ( statisticsDbConnectionString , secretInjector ) ;
47+ base . Init ( serviceContainer , jobArgsDictionary ) ;
5548
56- var statisticsStorageAccount = CloudStorageAccount . Parse (
57- JobConfigurationManager . GetArgument ( jobArgsDictionary , JobArgumentNames . AzureCdnCloudStorageAccount ) ) ;
49+ Configuration = _serviceProvider . GetRequiredService < InitializationConfiguration > ( ) ;
5850
59- var statisticsReportsContainerName = JobConfigurationManager . GetArgument ( jobArgsDictionary , JobArgumentNames . AzureCdnCloudStorageContainerName ) ;
51+ var destinationContainer = CloudStorageAccount . Parse ( Configuration . PrimaryDestination )
52+ . CreateCloudBlobClient ( )
53+ . GetContainerReference ( Configuration . DestinationContainerName ?? DefaultContainerName ) ;
6054
61- var destination = CloudStorageAccount . Parse (
62- JobConfigurationManager . GetArgument ( jobArgsDictionary , JobArgumentNames . PrimaryDestination ) ) ;
63-
64- var destinationContainerName =
65- JobConfigurationManager . TryGetArgument ( jobArgsDictionary , JobArgumentNames . DestinationContainerName )
66- ?? DefaultContainerName ;
67-
68- _destContainer = destination . CreateCloudBlobClient ( ) . GetContainerReference ( destinationContainerName ) ;
69- _statisticsContainer = statisticsStorageAccount . CreateCloudBlobClient ( ) . GetContainerReference ( statisticsReportsContainerName ) ;
55+ var statisticsContainer = CloudStorageAccount . Parse ( Configuration . AzureCdnCloudStorageAccount )
56+ . CreateCloudBlobClient ( )
57+ . GetContainerReference ( Configuration . AzureCdnCloudStorageContainerName ) ;
7058
7159 _exportersToRun = new List < Exporter > {
72- new VerifiedPackagesExporter ( LoggerFactory . CreateLogger < VerifiedPackagesExporter > ( ) , packageDbConnectionFactory , _destContainer , ScriptVerifiedPackages , OutputNameVerifiedPackages ) ,
73- new NestedJArrayExporter ( LoggerFactory . CreateLogger < NestedJArrayExporter > ( ) , packageDbConnectionFactory , _destContainer , ScriptCuratedFeed , OutputNameCuratedFeed , Col0CuratedFeed , Col1CuratedFeed ) ,
74- new NestedJArrayExporter ( LoggerFactory . CreateLogger < NestedJArrayExporter > ( ) , packageDbConnectionFactory , _destContainer , ScriptOwners , OutputNameOwners , Col0Owners , Col1Owners ) ,
75- new RankingsExporter ( LoggerFactory . CreateLogger < RankingsExporter > ( ) , statisticsDbConnectionFactory , _destContainer , ScriptRankingsTotal , OutputNameRankings ) ,
76- new BlobStorageExporter ( LoggerFactory . CreateLogger < BlobStorageExporter > ( ) , _statisticsContainer , StatisticsReportName , _destContainer , StatisticsReportName )
60+ new VerifiedPackagesExporter (
61+ LoggerFactory . CreateLogger < VerifiedPackagesExporter > ( ) ,
62+ OpenSqlConnectionAsync < GalleryDbConfiguration > ,
63+ destinationContainer ,
64+ ScriptVerifiedPackages ,
65+ OutputNameVerifiedPackages ) ,
66+
67+ new NestedJArrayExporter (
68+ LoggerFactory . CreateLogger < NestedJArrayExporter > ( ) ,
69+ OpenSqlConnectionAsync < GalleryDbConfiguration > ,
70+ destinationContainer ,
71+ ScriptCuratedFeed ,
72+ OutputNameCuratedFeed ,
73+ Col0CuratedFeed ,
74+ Col1CuratedFeed ) ,
75+
76+ new NestedJArrayExporter (
77+ LoggerFactory . CreateLogger < NestedJArrayExporter > ( ) ,
78+ OpenSqlConnectionAsync < GalleryDbConfiguration > ,
79+ destinationContainer ,
80+ ScriptOwners ,
81+ OutputNameOwners ,
82+ Col0Owners ,
83+ Col1Owners ) ,
84+
85+ new RankingsExporter (
86+ LoggerFactory . CreateLogger < RankingsExporter > ( ) ,
87+ OpenSqlConnectionAsync < StatisticsDbConfiguration > ,
88+ destinationContainer ,
89+ ScriptRankingsTotal ,
90+ OutputNameRankings ) ,
91+
92+ new BlobStorageExporter (
93+ LoggerFactory . CreateLogger < BlobStorageExporter > ( ) ,
94+ statisticsContainer ,
95+ StatisticsReportName ,
96+ destinationContainer ,
97+ StatisticsReportName )
7798 } ;
7899 }
79100
@@ -100,5 +121,14 @@ public override async Task Run()
100121 throw new ExporterException ( $ "{ failedExporters . Count ( ) } tasks failed: { string . Join ( ", " , failedExporters ) } ") ;
101122 }
102123 }
124+
125+ protected override void ConfigureAutofacServices ( ContainerBuilder containerBuilder )
126+ {
127+ }
128+
129+ protected override void ConfigureJobServices ( IServiceCollection services , IConfigurationRoot configurationRoot )
130+ {
131+ ConfigureInitializationSection < InitializationConfiguration > ( services , configurationRoot ) ;
132+ }
103133 }
104134}
0 commit comments