Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 3
0
        public static async Task Parse(IServiceProvider serviceProvider, IAzureTableStorage azureTableStorage,
                                       GlobalSearchTermRepository globalSearchTermRepository, ILocalization localization)
        {
            var playerHandbookManager = new PlayerHandbookManager(serviceProvider, localization);
            var wretchedHivesManager  = new WretchedHivesManager(serviceProvider, localization);
            var starshipManager       = new StarshipsOfTheGalaxyManager(serviceProvider, localization);
            var monsterManualManager  =
                new MonsterManualManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentSpeciesManager =
                new ExpandedContentSpeciesManager(serviceProvider, localization);
            var extendedContentBackgroundManager =
                new ExpandedContentBackgroundsManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentEquipmentManager =
                new ExpandedContentEquipmentManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentArchetypesManager =
                new ExpandedContentArchetypesManager(serviceProvider, localization);
            var extendedContentVariantRulesManager =
                new ExpandedContentVariantRulesManager(serviceProvider, localization);
            var expandedContentManager =
                new ExpandedContentManager(serviceProvider, localization);
            var extendedContentCustomizationOptionsManager =
                new ExpandedContentCustomizationOptionsManager(azureTableStorage, globalSearchTermRepository,
                                                               localization);
            var extendedContentForcePowersManager =
                new ExpandedContentForcePowersManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentTechPowersManager =
                new ExpandedContentTechPowersManager(azureTableStorage, globalSearchTermRepository, localization);
            var referenceTableManager = new ReferenceTableManager(azureTableStorage, localization);
            var creditsManager        = new CreditsManager(serviceProvider, localization);
            var extendedContentEnhancedItemManager =
                new ExpandedContentEnhancedItemsManager(azureTableStorage, globalSearchTermRepository, localization);

            var referenceTables = await referenceTableManager.Parse();

            var powers = await playerHandbookManager.Parse();

            powers.AddRange(await extendedContentTechPowersManager.Parse());
            powers.AddRange(await extendedContentForcePowersManager.Parse());
            await wretchedHivesManager.Parse();

            await starshipManager.Parse(referenceTables);

            await monsterManualManager.Parse(powers);

            await extendedContentSpeciesManager.Parse();

            await extendedContentBackgroundManager.Parse();

            await extendedContentEquipmentManager.Parse();

            await extendedContentArchetypesManager.Parse();

            await extendedContentVariantRulesManager.Parse();

            await expandedContentManager.Parse();

            await extendedContentCustomizationOptionsManager.Parse();

            await creditsManager.Parse();

            await extendedContentEnhancedItemManager.Parse();

            try
            {
                var searchServiceClient = serviceProvider.GetService <SearchIndexClient>();

                if (searchServiceClient != null)
                {
                    var searchManager = new SearchManager(serviceProvider, localization);
                    await searchManager.Upload();
                }
            }
            catch (StorageException)
            {
                var searchTerms = globalSearchTermRepository.SearchTerms;
                var dupes       = searchTerms
                                  .GroupBy(i => i.RowKey)
                                  .Where(g => g.Count() > 1)
                                  .Select(g => g.Key);

                foreach (var dupe in dupes)
                {
                    Console.WriteLine($"Dupe: {dupe}");
                }

                var nonConformingNames = searchTerms.Where(s => Regex.IsMatch(s.RowKey, @"[\\]|[/]|[#]|[?] "));
                foreach (var nonConformingName in nonConformingNames)
                {
                    Console.WriteLine($"Non-conforming: {nonConformingName}");
                }

                Console.WriteLine("Failed to upload search terms.");
            }

            try
            {
                var features        = serviceProvider.GetService <FeatureRepository>()?.Features;
                var sheetOperations = new SheetOperations(serviceProvider);

                if (features != null && serviceProvider.GetService <IConfiguration>()?["FeaturesSheetId"] != null)
                {
                    var featureSheetData = features.Select(c => new List <object> {
                        c.RowKey, c.Level
                    } as IList <object>).ToList();
                    await sheetOperations.UpdateFeatureSheetAsync(featureSheetData);

                    Console.WriteLine("Successfully wrote features to Features Parsed sheet.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to write features to sheet.");
            }

            try
            {
                var currentVersion =
                    (await azureTableStorage.GetAsync <DataVersion>($"dataVersion{localization.Language}", ContentType.Core.ToString(),
                                                                    "MASTERVERSION"))?.Version;

                var dataNames = new List <string>
                {
                    "MASTERVERSION", "archetypes", "armorProperties", "backgrounds", "classes", "credits",
                    "enhancedItems", "equipment", "feats", "features", "monsters", "powers", "referenceTables", "species", "starshipBaseSizes",
                    "starshipDeployments", "starshipEquipment", "starshipModifications", "starshipVentures", "weaponProperties",
                    "player-handbook-rules", "starships-rules", "variant-rules", "wretched-hives-rules",
                    "characterAdvancementLU", "conditionsLU", "featureDataLU", "featureLevelLU", "skillsLU", "fightingStyle",
                    "fightingMastery", "expanded-content"
                };
                var dataVersions = dataNames.Select(d => new DataVersion
                {
                    LastUpdated  = DateTime.Now,
                    Name         = d,
                    PartitionKey = ContentType.Core.ToString(),
                    RowKey       = d,
                    Version      = currentVersion + 1 ?? 1
                });

                await azureTableStorage.AddBatchAsync <DataVersion>($"dataVersion{localization.Language}", dataVersions,
                                                                    new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to update data versions.");
            }
        }
Esempio n. 4
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>());
            }
        }
Esempio n. 5
0
        public static async Task Parse(ITableStorage azureTableStorage, CloudStorageAccount cloudStorageAccount,
                                       GlobalSearchTermRepository globalSearchTermRepository, ILocalization localization)
        {
            var starshipManager = new StarshipsOfTheGalaxyManager(azureTableStorage, cloudStorageAccount,
                                                                  globalSearchTermRepository, localization);
            var monsterManualManager =
                new MonsterManualManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentSpeciesManager =
                new ExpandedContentSpeciesManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentBackgroundManager =
                new ExpandedContentBackgroundsManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentEquipmentManager =
                new ExpandedContentEquipmentManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentArchetypesManager =
                new ExpandedContentArchetypesManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentVariantRulesManager =
                new ExpandedContentVariantRulesManager(cloudStorageAccount, localization);
            var extendedContentCustomizationOptionsManager =
                new ExpandedContentCustomizationOptionsManager(azureTableStorage, globalSearchTermRepository,
                                                               localization);
            var extendedContentForcePowersManager =
                new ExpandedContentForcePowersManager(azureTableStorage, globalSearchTermRepository, localization);
            var extendedContentTechPowersManager =
                new ExpandedContentTechPowersManager(azureTableStorage, globalSearchTermRepository, localization);
            var playerHandbookManager = new PlayerHandbookManager(azureTableStorage, cloudStorageAccount,
                                                                  globalSearchTermRepository, localization);
            var referenceTableManager = new ReferenceTableManager(azureTableStorage, localization);
            var wretchedHivesManager  = new WretchedHivesManager(azureTableStorage, cloudStorageAccount,
                                                                 globalSearchTermRepository, localization);
            var creditsManager = new CreditsManager(cloudStorageAccount, localization);
            var extendedContentEnhancedItemManager =
                new ExpandedContentEnhancedItemsManager(azureTableStorage, globalSearchTermRepository, localization);

            var referenceTables = await referenceTableManager.Parse();

            await starshipManager.Parse(referenceTables);

            await monsterManualManager.Parse();

            await extendedContentSpeciesManager.Parse();

            await extendedContentBackgroundManager.Parse();

            await extendedContentEquipmentManager.Parse();

            await extendedContentArchetypesManager.Parse();

            await extendedContentVariantRulesManager.Parse();

            await extendedContentCustomizationOptionsManager.Parse();

            await extendedContentTechPowersManager.Parse();

            await extendedContentForcePowersManager.Parse();

            await wretchedHivesManager.Parse();

            await playerHandbookManager.Parse();

            await creditsManager.Parse();

            await extendedContentEnhancedItemManager.Parse();

            try
            {
                var searchManager = new SearchManager(azureTableStorage, globalSearchTermRepository);
                await searchManager.Upload();
            }
            catch (StorageException)
            {
                var searchTerms = globalSearchTermRepository.SearchTerms;
                var dupes       = searchTerms
                                  .GroupBy(i => i.RowKey)
                                  .Where(g => g.Count() > 1)
                                  .Select(g => g.Key);

                foreach (var dupe in dupes)
                {
                    Console.WriteLine($"Dupe: {dupe}");
                }

                var nonConformingNames = searchTerms.Where(s => Regex.IsMatch(s.RowKey, @"[\\]|[/]|[#]|[?] "));
                foreach (var nonConformingName in nonConformingNames)
                {
                    Console.WriteLine($"Non-conforming: {nonConformingName}");
                }

                Console.WriteLine("Failed to upload search terms.");
            }

            try
            {
                var currentVersion =
                    (await azureTableStorage.GetAsync <DataVersion>($"dataVersion{localization.Language}", ContentType.Core.ToString(),
                                                                    "MASTERVERSION"))?.Version;

                var dataNames = new List <string>
                {
                    "MASTERVERSION", "archetypes", "armorProperties", "backgrounds", "classes", "credits",
                    "enhancedItems", "equipment",
                    "feats", "features", "monsters", "powers", "referenceTables", "species", "starshipBaseSizes",
                    "starshipDeployments", "starshipEquipment", "starshipModifications", "starshipVentures",
                    "weaponProperties",
                    "player-handbook-rules", "starships-rules", "variant-rules", "wretched-hives-rules",
                    "characterAdvancementLU", "conditionsLU", "featureDataLU", "featureLevelLU", "skillsLU"
                };
                var dataVersions = dataNames.Select(d => new DataVersion
                {
                    LastUpdated  = DateTime.Now,
                    Name         = d,
                    PartitionKey = ContentType.Core.ToString(),
                    RowKey       = d,
                    Version      = currentVersion + 1 ?? 1
                });

                await azureTableStorage.AddBatchAsync <DataVersion>($"dataVersion{localization.Language}", dataVersions,
                                                                    new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to update data versions.");
            }
        }