public async Task Parse()
        {
            try
            {
                var monsters = await _monsterProcessor.Process(_mmFileName, _localization);

                foreach (var monster in monsters)
                {
                    monster.ContentSourceEnum = ContentSource.SnV;

                    var monsterSearchTerm = _globalSearchTermRepository.CreateSearchTerm(monster.Name,
                                                                                         GlobalSearchTermType.Monster, ContentType.Core, $"/rules/snv/monsters/{monster.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(monsterSearchTerm);
                }

                await _tableStorage.AddBatchAsync <Monster>($"monsters{_localization.Language}", monsters,
                                                            new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload monsters.");
            }

            foreach (var monsterChapterName in SectionNames.MonsterChapterNames)
            {
                var monsterChapterSearchTerm = _globalSearchTermRepository.CreateSearchTerm(monsterChapterName.name,
                                                                                            monsterChapterName.globalSearchTermType, ContentType.Core, monsterChapterName.pathOverride);
                _globalSearchTermRepository.SearchTerms.Add(monsterChapterSearchTerm);
            }
        }
Beispiel #2
0
        public async Task ParsedSampleFile()
        {
            var result = await _monsterProcessor.Process(_filesToParse, new LocalizationEn());

            Assert.IsNotEmpty(result);
            Assert.AreEqual(2, result.Count);
        }
        public async Task <List <ReferenceTable> > Parse()
        {
            var tables = await _referenceTableProcessor.Process(_referenceTableFileNames, _localization);

            await _tableStorage.AddBatchAsync <ReferenceTable>($"referenceTables{_localization.Language}", tables,
                                                               new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });

            return(tables);
        }
        public async Task Parse(List <ReferenceTable> referenceTables = null)
        {
            try
            {
                var rules = await _starshipChapterRulesProcessor.Process(_sotgFilesName, _localization);

                if (referenceTables != null)
                {
                    foreach (var chapterRule in rules)
                    {
                        foreach (var referenceTable in referenceTables)
                        {
                            chapterRule.ContentMarkdown = Regex.Replace(chapterRule.ContentMarkdown,
                                                                        $@"(?<!#\s*){referenceTable.Name}", $"[{referenceTable.Name}](#{Uri.EscapeUriString(referenceTable.Name)})", RegexOptions.IgnoreCase);
                        }
                    }
                }

                await _blobContainerClient.CreateIfNotExistsAsync();

                foreach (var chapterRules in rules)
                {
                    var json       = JsonConvert.SerializeObject(chapterRules);
                    var blobClient = _blobContainerClient.GetBlobClient($"{chapterRules.ChapterName}.json");

                    var content = Encoding.UTF8.GetBytes(json);
                    using (var ms = new MemoryStream(content))
                    {
                        await blobClient.UploadAsync(ms, true);
                    }
                }
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload SOTG rules.");
            }

            try
            {
                var deployments =
                    await _starshipDeploymentProcessor.Process(_sotgFilesName.Where(f => f.Equals("SOTG.sotg_02.txt")).ToList(), _localization);

                foreach (var deployment in deployments)
                {
                    deployment.ContentSourceEnum = ContentSource.SotG;

                    var deploymentSearchTerm = _globalSearchTermRepository.CreateSearchTerm(deployment.Name, GlobalSearchTermType.Deployment, ContentType.Core,
                                                                                            $"/starships/deployments/{deployment.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(deploymentSearchTerm);
                }

                if (referenceTables != null)
                {
                    foreach (var deployment in deployments)
                    {
                        foreach (var referenceTable in referenceTables)
                        {
                            if (deployment.Features != null)
                            {
                                foreach (var deploymentFeature in deployment.Features)
                                {
                                    if (deploymentFeature.Content != null)
                                    {
                                        deploymentFeature.Content = Regex.Replace(deploymentFeature.Content,
                                                                                  $@"(?<!#\s*){referenceTable.Name}", $"[{referenceTable.Name}](#{Uri.EscapeUriString(referenceTable.Name)})",
                                                                                  RegexOptions.IgnoreCase);
                                    }
                                }
                            }
                        }
                    }
                }

                await _tableStorage.AddBatchAsync <StarshipDeployment>($"starshipDeployments{_localization.Language}", deployments,
                                                                       new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload SOTG deployments.");
            }

            try
            {
                var equipment = await _starshipEquipmentProcessor.Process(_sotgFilesName.Where(f => f.Equals("SOTG.sotg_05.txt")).ToList(), _localization);

                if (referenceTables != null)
                {
                    foreach (var starshipEquipment in equipment)
                    {
                        if (starshipEquipment.Description != null)
                        {
                            foreach (var referenceTable in referenceTables)
                            {
                                starshipEquipment.Description = Regex.Replace(starshipEquipment.Description,
                                                                              $@"(?<!#\s*){referenceTable.Name}", $"[{referenceTable.Name}](#{Uri.EscapeUriString(referenceTable.Name)})", RegexOptions.IgnoreCase);
                            }
                        }
                    }
                }

                var dupes = equipment
                            .GroupBy(i => i.RowKey)
                            .Where(g => g.Count() > 1)
                            .Select(g => g.Key);

                foreach (var starshipEquipment in equipment)
                {
                    starshipEquipment.ContentSourceEnum = ContentSource.SotG;

                    switch (starshipEquipment.TypeEnum)
                    {
                    case StarshipEquipmentType.Armor:
                    case StarshipEquipmentType.Shield:
                    case StarshipEquipmentType.Ammunition:
                    case StarshipEquipmentType.Hyperdrive:
                    case StarshipEquipmentType.Navcomputer:
                    case StarshipEquipmentType.PowerCoupling:
                    case StarshipEquipmentType.Reactor:
                        var equipmentSearchTerm = _globalSearchTermRepository.CreateSearchTerm(starshipEquipment.Name, GlobalSearchTermType.StarshipEquipment, ContentType.Core,
                                                                                               $"/starships/equipment?search={starshipEquipment.Name}");
                        _globalSearchTermRepository.SearchTerms.Add(equipmentSearchTerm);
                        break;

                    case StarshipEquipmentType.Weapon:
                        var weaponSearchTerm = _globalSearchTermRepository.CreateSearchTerm(starshipEquipment.Name, GlobalSearchTermType.StarshipWeapon, ContentType.Core,
                                                                                            $"/starships/weapons?search={starshipEquipment.Name}");
                        _globalSearchTermRepository.SearchTerms.Add(weaponSearchTerm);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                await _tableStorage.AddBatchAsync <StarshipEquipment>($"starshipEquipment{_localization.Language}", equipment,
                                                                      new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException e)
            {
                Console.WriteLine("Failed to upload SOTG equipment.");
            }

            try
            {
                var modifications = await _starshipModificationProcessor.Process(_sotgFilesName.Where(f => f.Equals("SOTG.sotg_04.txt")).ToList(), _localization);

                if (referenceTables != null)
                {
                    foreach (var modification in modifications)
                    {
                        if (modification.Content != null)
                        {
                            foreach (var referenceTable in referenceTables)
                            {
                                modification.Content = Regex.Replace(modification.Content,
                                                                     $@"(?<!#\s*){referenceTable.Name}", $"[{referenceTable.Name}](#{Uri.EscapeUriString(referenceTable.Name)})", RegexOptions.IgnoreCase);
                            }
                        }
                    }
                }

                foreach (var modification in modifications)
                {
                    modification.ContentSourceEnum = ContentSource.SotG;

                    var modificationSearchTerm = _globalSearchTermRepository.CreateSearchTerm(modification.Name, GlobalSearchTermType.StarshipModification, ContentType.Core,
                                                                                              $"/starships/modifications?search={modification.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(modificationSearchTerm);
                }

                await _tableStorage.AddBatchAsync <StarshipModification>($"starshipModifications{_localization.Language}", modifications,
                                                                         new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException e)
            {
                Console.WriteLine("Failed to upload SOTG modifications.");
            }

            try
            {
                var sizes = await _starshipSizeProcessor.Process(_sotgFilesName.Where(f => f.Equals("SOTG.sotg_03.txt")).ToList(), _localization);

                foreach (var size in sizes)
                {
                    size.ContentSourceEnum = ContentSource.SotG;

                    var sizeSearchTerm = _globalSearchTermRepository.CreateSearchTerm(size.Name, GlobalSearchTermType.StarshipSize, ContentType.Core,
                                                                                      $"/rules/sotg/starshipSizes/{size.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(sizeSearchTerm);
                }

                await _tableStorage.AddBatchAsync <StarshipBaseSize>($"starshipBaseSizes{_localization.Language}", sizes,
                                                                     new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload SOTG sizes.");
            }

            try
            {
                var ventures = await _starshipVentureProcessor.Process(_sotgFilesName.Where(f => f.Equals("SOTG.sotg_06.txt")).ToList(), _localization);

                foreach (var venture in ventures)
                {
                    venture.ContentSourceEnum = ContentSource.SotG;

                    var sizeSearchTerm = _globalSearchTermRepository.CreateSearchTerm(venture.Name, GlobalSearchTermType.Venture, ContentType.Core,
                                                                                      $"/starships/ventures?search={venture.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(sizeSearchTerm);
                }
                await _tableStorage.AddBatchAsync <StarshipVenture>($"starshipVentures{_localization.Language}", ventures,
                                                                    new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload SOTG ventures.");
            }
        }
Beispiel #5
0
        public async Task Parse()
        {
            try
            {
                var rules = await _wretchedHivesChapterRulesProcessor.Process(_whFilesName, _localization);

                await _cloudBlobContainer.CreateIfNotExistsAsync(BlobContainerPublicAccessType.Off, null, null);

                foreach (var chapterRules in rules)
                {
                    var json = JsonConvert.SerializeObject(chapterRules);
                    var blob = _cloudBlobContainer.GetBlockBlobReference($"{chapterRules.ChapterName}.json");

                    await blob.UploadTextAsync(json);
                }
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload WH rules.");
            }

            try
            {
                var enhancedItemProcessor = new EnhancedItemProcessor(_localization);
                var enhancedItems         = await enhancedItemProcessor.Process(_whFilesName.Where(f => f.Equals("WH.wh_aa.txt")).ToList(), _localization);

                foreach (var enhancedItem in enhancedItems)
                {
                    enhancedItem.ContentSourceEnum = ContentSource.WH;

                    var enhancedItemSearchTerm = _globalSearchTermRepository.CreateSearchTerm(enhancedItem.Name, GlobalSearchTermType.EnhancedItem, ContentType.Core,
                                                                                              $"/loot/enhancedItems?search={enhancedItem.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(enhancedItemSearchTerm);
                }

                await _tableStorage.AddBatchAsync <EnhancedItem>($"enhancedItems{_localization.Language}", enhancedItems,
                                                                 new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload WH enhanced items.");
            }

            try
            {
                var equipment =
                    await _wretchedHivesEquipmentProcessor.Process(new List <string> {
                    "WH.wh_05.txt"
                }, _localization);

                foreach (var equipment1 in equipment)
                {
                    equipment1.ContentSourceEnum = ContentSource.WH;

                    switch (equipment1.EquipmentCategoryEnum)
                    {
                    case EquipmentCategory.Unknown:
                    case EquipmentCategory.Ammunition:
                    case EquipmentCategory.Explosive:
                    case EquipmentCategory.Storage:
                    case EquipmentCategory.AdventurePack:
                    case EquipmentCategory.Communications:
                    case EquipmentCategory.DataRecordingAndStorage:
                    case EquipmentCategory.LifeSupport:
                    case EquipmentCategory.Medical:
                    case EquipmentCategory.WeaponOrArmorAccessory:
                    case EquipmentCategory.Tool:
                    case EquipmentCategory.Mount:
                    case EquipmentCategory.Vehicle:
                    case EquipmentCategory.TradeGood:
                    case EquipmentCategory.Utility:
                    case EquipmentCategory.GamingSet:
                    case EquipmentCategory.MusicalInstrument:
                    case EquipmentCategory.Droid:
                    case EquipmentCategory.Clothing:
                    case EquipmentCategory.Kit:
                        var equipmentSearchTerm = _globalSearchTermRepository.CreateSearchTerm(equipment1.Name,
                                                                                               GlobalSearchTermType.AdventuringGear, ContentType.Core,
                                                                                               $"/loot/adventuringGear/?search={equipment1.Name}");
                        _globalSearchTermRepository.SearchTerms.Add(equipmentSearchTerm);
                        break;

                    case EquipmentCategory.Weapon:
                        var weaponSearchTerm = _globalSearchTermRepository.CreateSearchTerm(equipment1.Name,
                                                                                            GlobalSearchTermType.Weapon, ContentType.Core,
                                                                                            $"/loot/weapons/?search={equipment1.Name}");
                        _globalSearchTermRepository.SearchTerms.Add(weaponSearchTerm);
                        break;

                    case EquipmentCategory.Armor:
                        var searchTermType = GlobalSearchTermType.Armor;
                        if (equipment1.ArmorClassificationEnum == ArmorClassification.Shield)
                        {
                            searchTermType = GlobalSearchTermType.Shield;
                        }

                        var armorSearchTerm = _globalSearchTermRepository.CreateSearchTerm(equipment1.Name,
                                                                                           searchTermType, ContentType.Core,
                                                                                           $"/loot/armor/?search={equipment1.Name}");
                        _globalSearchTermRepository.SearchTerms.Add(armorSearchTerm);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                var dupes = equipment
                            .GroupBy(i => i.RowKey)
                            .Where(g => g.Count() > 1)
                            .Select(g => g.Key);

                await _tableStorage.AddBatchAsync <Equipment>($"equipment{_localization.Language}", equipment,
                                                              new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException e)
            {
                Console.WriteLine("Failed to upload WH equipment.");
            }

            try
            {
                var weaponProperties = await _weaponPropertyProcessor.Process(new List <string> {
                    "WH.wh_05.txt"
                }, _localization);

                await _tableStorage.AddBatchAsync <WeaponProperty>($"weaponProperties{_localization.Language}", weaponProperties,
                                                                   new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload WH weapon properties.");
            }

            try
            {
                var armorProperties =
                    await _armorPropertyProcessor.Process(new List <string> {
                    "WH.wh_05.txt"
                }, _localization);

                await _tableStorage.AddBatchAsync <ArmorProperty>($"armorProperties{_localization.Language}", armorProperties,
                                                                  new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload WH weapon properties.");
            }

            try
            {
                var playerHandbookFeatProcessor = new PlayerHandbookFeatProcessor(_localization);
                var feats = await playerHandbookFeatProcessor.Process(new List <string> {
                    "WH.wh_06.txt"
                }, _localization);

                foreach (var feat in feats)
                {
                    feat.ContentSourceEnum = ContentSource.WH;

                    var featSearchTerm = _globalSearchTermRepository.CreateSearchTerm(feat.Name, GlobalSearchTermType.Feat, ContentType.Core,
                                                                                      $"/characters/feats/?search={feat.Name}");
                    _globalSearchTermRepository.SearchTerms.Add(featSearchTerm);
                }

                await _tableStorage.AddBatchAsync <Feat>($"feats{_localization.Language}", feats,
                                                         new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace });
            }
            catch (StorageException)
            {
                Console.WriteLine("Failed to upload PHB feats.");
            }
        }