예제 #1
0
        public static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appSettings.json", true, true)
                         .AddUserSecrets <Program>()
                         .Build();

            var tableStorage = new AzureTableStorage(config["StorageAccountConnectionString"]);

            var storageAccount             = CloudStorageAccount.Parse(config["StorageAccountConnectionString"]);
            var globalSearchTermRepository = new GlobalSearchTermRepository();

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <ITableStorage>(tableStorage)
                                  .AddSingleton(storageAccount)
                                  .AddSingleton(globalSearchTermRepository)
                                  .BuildServiceProvider();

            var languages = config["Languages"].Split(',');

            if (!languages.Any())
            {
                Console.WriteLine("No languages found.");
                return;
            }

            foreach (var language in languages)
            {
                var languageEnum = Enum.TryParse <Language>(language, true, out var parsedLanguage) ? parsedLanguage : Language.None;

                if (languageEnum == Language.None)
                {
                    Console.WriteLine($"Language {language} not supported.");
                    return;
                }

                var stringsClass = LocalizationFactory.Get(languageEnum);

                await ParseContent.Parse(serviceProvider.GetService <ITableStorage>(),
                                         serviceProvider.GetService <CloudStorageAccount>(),
                                         serviceProvider.GetService <GlobalSearchTermRepository>(), stringsClass);
            }
        }
예제 #2
0
        public static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appSettings.json", true, true)
                         .AddUserSecrets <Program>()
                         .Build();

            var tableStorage = new AzureTableStorage(config["StorageAccountConnectionString"]);

            var storageAccount  = CloudStorageAccount.Parse(config["StorageAccountConnectionString"]);
            var cloudBlobClient = new BlobServiceClient(config["StorageAccountConnectionString"]);

            var globalSearchTermRepository = new GlobalSearchTermRepository();
            var featureRepository          = new FeatureRepository();

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IAzureTableStorage>(tableStorage)
                                  .AddSingleton(storageAccount)
                                  .AddSingleton(globalSearchTermRepository)
                                  .AddSingleton(featureRepository)
                                  .AddSingleton(cloudBlobClient)
                                  .AddSingleton <IConfiguration>(config);

            await using var googleCredStream = Assembly.GetExecutingAssembly()
                                               .GetManifestResourceStream("StarWars5e.Parser.google_credentials.json");

            if (googleCredStream != null && googleCredStream.Length > 0)
            {
                await using var stream = Assembly.GetExecutingAssembly()
                                         .GetManifestResourceStream("StarWars5e.Parser.google_credentials.json");
                var googleCredential = GoogleCredential.FromStream(stream).CreateScoped(SheetsService.ScopeConstants.Spreadsheets);

                var sheetsService = new SheetsService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = googleCredential,
                    ApplicationName       = "SW5E Sheets API"
                });

                serviceProvider.AddSingleton(sheetsService);
            }

            if (!string.IsNullOrWhiteSpace(config["SearchKey"]))
            {
                var searchIndexClient = new SearchIndexClient(new Uri("https://sw5esearch.search.windows.net"),
                                                              new AzureKeyCredential(config["SearchKey"]));
                var searchIndexerClient = new SearchIndexerClient(new Uri("https://sw5esearch.search.windows.net"),
                                                                  new AzureKeyCredential(config["SearchKey"]));

                serviceProvider.AddSingleton(searchIndexClient);
                serviceProvider.AddSingleton(searchIndexerClient);
            }

            var serviceProviderBuilt = serviceProvider.BuildServiceProvider();

            var languages = config["Languages"].Split(',');

            if (!languages.Any())
            {
                Console.WriteLine("No languages found.");
                return;
            }

            foreach (var language in languages)
            {
                var languageEnum = Enum.TryParse <Language>(language, true, out var parsedLanguage) ? parsedLanguage : Language.None;

                if (languageEnum == Language.None)
                {
                    Console.WriteLine($"Language {language} not supported.");
                    return;
                }

                var stringsClass = LocalizationFactory.Get(languageEnum);

                await ParseContent.Parse(serviceProviderBuilt, serviceProviderBuilt.GetService <IAzureTableStorage>(),
                                         serviceProviderBuilt.GetService <GlobalSearchTermRepository>(), stringsClass);
            }
        }
예제 #3
0
        public static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appSettings.json", true, true)
                         .AddUserSecrets <Program>()
                         .Build();

            var tableStorage = new AzureTableStorage(config["StorageAccountConnectionString"]);

            var storageAccount             = CloudStorageAccount.Parse(config["StorageAccountConnectionString"]);
            var globalSearchTermRepository = new GlobalSearchTermRepository();

            var searchClient = new SearchServiceClient("sw5esearch", new SearchCredentials(config["SearchKey"]));

            var clientSecrets = new ClientSecrets
            {
                ClientId     = config["GoogleApiClientId"],
                ClientSecret = config["GoogleApiClientSecret"]
            };

            var googleCredential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                clientSecrets,
                Scopes,
                "user",
                CancellationToken.None);

            // Create Google Sheets API service.
            var sheetsService = new SheetsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = googleCredential,
                ApplicationName       = ApplicationName
            });

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <ITableStorage>(tableStorage)
                                  .AddSingleton(storageAccount)
                                  .AddSingleton(globalSearchTermRepository)
                                  .AddSingleton(searchClient)
                                  .AddSingleton(sheetsService)
                                  .BuildServiceProvider();

            var languages = config["Languages"].Split(',');

            if (!languages.Any())
            {
                Console.WriteLine("No languages found.");
                return;
            }

            foreach (var language in languages)
            {
                var languageEnum = Enum.TryParse <Language>(language, true, out var parsedLanguage) ? parsedLanguage : Language.None;

                if (languageEnum == Language.None)
                {
                    Console.WriteLine($"Language {language} not supported.");
                    return;
                }

                var stringsClass = LocalizationFactory.Get(languageEnum);

                await ParseContent.Parse(serviceProvider.GetService <ITableStorage>(),
                                         serviceProvider.GetService <CloudStorageAccount>(),
                                         serviceProvider.GetService <GlobalSearchTermRepository>(), stringsClass, serviceProvider.GetService <SearchServiceClient>());
            }
        }