private static void ConfigureCosmosDB(IServiceCollection services, IConfiguration configuration) { services.AddTransient <Func <string, CosmosDbSetting> >(serviceProvider => name => { var kvSetting = serviceProvider.GetRequiredService <KeyVaultSetting>(); var kvCert = CertUtil.FindCertificateByThumbprint(kvSetting.AuthCertThumbprint); var kvClient = new KeyVaultUtil(kvSetting.VaultName, kvSetting.AuthClientId, kvCert); switch (name) { case "graph": var graphDbKey = kvClient.GetSecret(kvSetting.GraphDbAuthKeySecretName).Result; var graphDbSetting = new CosmosDbSetting() { AccountName = configuration["graphDb:accountName"], DbName = configuration["graphDb:dbName"], CollectionName = configuration["graphDb:collectionName"], AuthKey = graphDbKey }; return(graphDbSetting); default: var docDbKey = kvClient.GetSecret(kvSetting.DocDbAuthKeySecretName).Result; var docDbSetting = new CosmosDbSetting() { AccountName = configuration["docDb:accountName"], DbName = configuration["docDb:dbName"], CollectionName = configuration["docDb:collectionName"], AuthKey = docDbKey }; return(docDbSetting); } }); }
public static void Run(TimerInfo myTimer, TraceWriter log) { try { var translatorSetting = new TranslatorSetting { APIKey = ConfigurationManager.AppSettings["TranslatorAPIKey"], }; var twitterSetting = new TwitterSetting { ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"], AccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"], AccessTokenSecret = ConfigurationManager.AppSettings["TwitterAccessTokenSecret"], }; var visionSetting = new VisionSetting { APIKey = ConfigurationManager.AppSettings["VisionAPIAPIKey"], Endpoint = ConfigurationManager.AppSettings["VisionAPIEndpoint"], }; var cosmosDbSetting = new CosmosDbSetting { EndpointUri = ConfigurationManager.AppSettings["CosmosDbEndpointUri"], PrimaryKey = ConfigurationManager.AppSettings["CosmosDbPrimaryKey"], }; var analyzeSetting = new AnalyzeSetting { Keyword = ConfigurationManager.AppSettings["AnalyzeKeyword"], }; // services var logger = new TraceWriterLogger(log); var translatorService = new TranslatorService(Options.Create(translatorSetting), logger); var twitterService = new TwitterService(Options.Create(twitterSetting), logger); var visionService = new VisionService(Options.Create(visionSetting), translatorService, logger); var categolizedImageRepository = new CategorizedImageRepository(Options.Create(cosmosDbSetting), logger); var analyzeService = new AnalyzeService(Options.Create(analyzeSetting), twitterService, visionService, categolizedImageRepository, logger); // initialize twitterService.InitializeAsync().Wait(); // run analyzeService.AnalyzeAsync().Wait(); } catch (Exception ex) { log.Error($"Error {ex.ToString()}"); } }