public async Task Parse() { try { var equipment = await _playerHandbookEquipmentProcessor.Process(_phbFilesNames .Where(p => p.Equals("PHB.phb_05.txt")).ToList(), _localization); foreach (var equipment1 in equipment) { equipment1.ContentSourceEnum = ContentSource.PHB; 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(); } } await _tableStorage.AddBatchAsync <Equipment>($"equipment{_localization.Language}", equipment, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB equipment."); } try { var backgrounds = await _playerHandbookBackgroundsProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_04.txt")) .ToList(), _localization); foreach (var background in backgrounds) { background.ContentSourceEnum = ContentSource.PHB; var backgroundSearchTerm = _globalSearchTermRepository.CreateSearchTerm(background.Name, GlobalSearchTermType.Background, ContentType.Core, $"/characters/backgrounds/{background.Name}"); _globalSearchTermRepository.SearchTerms.Add(backgroundSearchTerm); } await _tableStorage.AddBatchAsync <Background>($"backgrounds{_localization.Language}", backgrounds, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB backgrounds."); } try { var speciesImageUrlsLus = await _tableStorage.GetAllAsync <SpeciesImageUrlLU>("speciesImageUrlsLU"); var playerHandbookSpeciesProcessor = new PlayerHandbookSpeciesProcessor(speciesImageUrlsLus.ToList()); var species = await playerHandbookSpeciesProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_02.txt")) .ToList(), _localization); foreach (var specie in species) { specie.ContentSourceEnum = ContentSource.PHB; var specieSearchTerm = _globalSearchTermRepository.CreateSearchTerm(specie.Name, GlobalSearchTermType.Species, ContentType.Core, $"/characters/species/{specie.Name}"); _globalSearchTermRepository.SearchTerms.Add(specieSearchTerm); } await _tableStorage.AddBatchAsync <Species>($"species{_localization.Language}", species, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB species."); } try { var featureLevels = (await _tableStorage.GetAllAsync <FeatureDataLU>("featureLevelLU")).ToList(); var classImageLus = await _tableStorage.GetAllAsync <ClassImageLU>("classImageLU"); var casterRatioLus = await _tableStorage.GetAllAsync <CasterRatioLU>("casterRatioLU"); var multiclassProficiencyLus = await _tableStorage.GetAllAsync <MulticlassProficiencyLU>("multiclassProficiencyLU"); var playerHandbookClassProcessor = new PlayerHandbookClassProcessor(classImageLus.ToList(), casterRatioLus.ToList(), multiclassProficiencyLus.ToList()); var classes = await playerHandbookClassProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_03.txt")) .ToList(), _localization); foreach (var swClass in classes) { swClass.ContentSourceEnum = ContentSource.PHB; var classSearchTerm = _globalSearchTermRepository.CreateSearchTerm(swClass.Name, GlobalSearchTermType.Class, ContentType.Core, $"/characters/classes/{swClass.Name}"); _globalSearchTermRepository.SearchTerms.Add(classSearchTerm); } await _tableStorage.AddBatchAsync <Class>($"classes{_localization.Language}", classes, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); try { var archetypes = classes.SelectMany(s => s.Archetypes).ToList(); foreach (var archetype in archetypes) { archetype.ContentSourceEnum = ContentSource.PHB; var archetypeSearchTerm = _globalSearchTermRepository.CreateSearchTerm(archetype.Name, GlobalSearchTermType.Archetype, ContentType.Core, $"/characters/archetypes/{archetype.Name}"); _globalSearchTermRepository.SearchTerms.Add(archetypeSearchTerm); } try { var archetypeFeatures = archetypes.SelectMany(f => f.Features).ToList(); foreach (var archetypeFeature in archetypeFeatures) { var featureLevel = featureLevels.SingleOrDefault(f => f.FeatureRowKey == archetypeFeature.RowKey); if (featureLevel != null) { archetypeFeature.Level = featureLevel.Level; } } await _tableStorage.AddBatchAsync <Feature>($"features{_localization.Language}", archetypeFeatures, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException se) { Console.WriteLine($"Failed to upload PHB archetype features: {se}"); } var dupes = archetypes .GroupBy(i => i.RowKey) .Where(g => g.Count() > 1) .Select(g => g.Key); await _tableStorage.AddBatchAsync <Archetype>($"archetypes{_localization.Language}", archetypes, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException se) { Console.WriteLine($"Failed to upload PHB archetypes: {se}"); } try { var classFeatures = classes.SelectMany(f => f.Features).ToList(); foreach (var classFeature in classFeatures) { var featureLevel = featureLevels.SingleOrDefault(f => f.FeatureRowKey == classFeature.RowKey); if (featureLevel != null) { classFeature.Level = featureLevel.Level; } } await _tableStorage.AddBatchAsync <Feature>($"features{_localization.Language}", classFeatures, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException se) { Console.WriteLine($"Failed to upload PHB class features: {se}"); } } catch (StorageException) { Console.WriteLine("Failed to upload PHB classes."); } try { var playerHandbookPowersProcessor = new PlayerHandbookPowersProcessor(_localization); var powers = await playerHandbookPowersProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_11.txt") || p.Equals("PHB.phb_12.txt")) .ToList(), _localization); foreach (var power in powers) { power.ContentSourceEnum = ContentSource.PHB; switch (power.PowerTypeEnum) { case PowerType.None: break; case PowerType.Force: var forcePowerSearchTerm = _globalSearchTermRepository.CreateSearchTerm(power.Name, GlobalSearchTermType.ForcePower, ContentType.Core, $"/characters/forcePowers/?search={power.Name}"); _globalSearchTermRepository.SearchTerms.Add(forcePowerSearchTerm); break; case PowerType.Tech: var techPowerSearchTerm = _globalSearchTermRepository.CreateSearchTerm(power.Name, GlobalSearchTermType.TechPower, ContentType.Core, $"/characters/techPowers/?search={power.Name}"); _globalSearchTermRepository.SearchTerms.Add(techPowerSearchTerm); break; default: throw new ArgumentOutOfRangeException(); } } await _tableStorage.AddBatchAsync <Power>($"powers{_localization.Language}", powers, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB powers."); } try { var feats = await _playerHandbookFeatProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_06.txt")) .ToList(), _localization); foreach (var feat in feats) { feat.ContentSourceEnum = ContentSource.PHB; 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."); } try { var rules = await _playerHandbookChapterRulesProcessor.Process(_phbFilesNames, _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 PHB rules."); } try { var weaponProperties = await _weaponPropertyProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_05.txt")).ToList(), _localization); var specialProperty = weaponProperties.SingleOrDefault(w => w.Name == "Special"); if (specialProperty != null) { specialProperty.Content = "#### Special\r\nA weapon with the special property has unusual rules governing its use, explained in the weapon's description."; } await _tableStorage.AddBatchAsync <WeaponProperty>($"weaponProperties{_localization.Language}", weaponProperties, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB weapon properties."); } try { var armorProperties = await _armorPropertyProcessor.Process(_phbFilesNames.Where(p => p.Equals("PHB.phb_05.txt")).ToList(), _localization); await _tableStorage.AddBatchAsync <ArmorProperty>($"armorProperties{_localization.Language}", armorProperties, new BatchOperationOptions { BatchInsertMethod = BatchInsertMethod.InsertOrReplace }); } catch (StorageException) { Console.WriteLine("Failed to upload PHB weapon properties."); } foreach (var referenceName in SectionNames.ReferenceNames) { var referenceSearchTerm = _globalSearchTermRepository.CreateSearchTerm(referenceName.name, referenceName.globalSearchTermType, ContentType.Core, referenceName.pathOverride); _globalSearchTermRepository.SearchTerms.Add(referenceSearchTerm); } foreach (var variantRuleName in SectionNames.VariantRuleNames) { var variantRuleSearchTerm = _globalSearchTermRepository.CreateSearchTerm(variantRuleName.name, variantRuleName.globalSearchTermType, ContentType.Core, variantRuleName.pathOverride); _globalSearchTermRepository.SearchTerms.Add(variantRuleSearchTerm); } }
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."); } }