private static void ExecuteDelete(ProgramParameters parameters, CloudTable cardsTable, CloudTable indexTable) { TableUtils <MonsterCardEntity> cardUtils = new TableUtils <MonsterCardEntity>(cardsTable); TableUtils <IndexByMonsterEntity> indexUtils = new TableUtils <IndexByMonsterEntity>(indexTable); Console.Write("Retrieving entities to be deleted..."); var cards = cardsTable.ExecuteQuery <MonsterCardEntity>(new TableQuery <MonsterCardEntity>()).Where(e => { return(e.RowKey.StartsWith(parameters.CardName)); }).ToList(); Console.WriteLine($"done\n{cards.Count} entries found."); foreach (MonsterCardEntity card in cards) { string option; Console.WriteLine($"**************\n{card}\n**************\nIf you confirm deletion, this card and all its index entries will be deleted."); option = ReadOption("Are you sure (y/n)? ", "Y", "y", "yes", "Yes", "N", "n", "No", "no"); switch (option) { case "y": case "Y": case "yes": case "Yes": { Console.Write("Searching related index entries..."); var indexEntries = indexTable.ExecuteQuery(new TableQuery <IndexByMonsterEntity>()).Where((e) => { return(e.RowKey.Equals(card.RowKey)); }).ToList(); Console.WriteLine($"done\n{indexEntries.Count} entr{(indexEntries.Count == 1 ? "y" : "ies")} found."); Console.Write("Deleting card entry..."); cardUtils.DeleteEntityAsync(card).GetAwaiter().GetResult(); Console.WriteLine("done"); Console.Write("Deleting index entries..."); foreach (IndexByMonsterEntity indexEntry in indexEntries) { indexUtils.DeleteEntityAsync(indexEntry).GetAwaiter().GetResult(); } Console.WriteLine("done"); } break; default: { Console.Write("Skipping this entry. "); } break; } AddContinuation(); } }
private static void ExecuteRebuildIndexes(CloudTable cardsTable, CloudTable indexTable) { TableUtils <IndexByMonsterEntity> indexUtils = new TableUtils <IndexByMonsterEntity>(indexTable); int count = 0; List <IndexByMonsterEntity> rebuiltEntries = new List <IndexByMonsterEntity>(); Console.WriteLine("Rebuild indexes"); Console.Write("Index by Monster: retrieving current index..."); var indexEntities = indexTable.ExecuteQuery(new TableQuery <IndexByMonsterEntity>()).ToList(); Console.WriteLine("done"); Console.WriteLine("Index by Monster: rebuilding properties"); var cardEntities = cardsTable.ExecuteQuery(new TableQuery <MonsterCardEntity>()).ToList(); foreach (MonsterCardEntity entity in cardEntities) { if (entity.PartitionKey != CardType.BasicResource.ToString() && entity.PartitionKey != CardType.StrangeResource.ToString()) { foreach (IndexByMonsterEntity indexEntry in indexEntities) { if (entity.RowKey.Equals(indexEntry.RowKey) && !indexEntry.CardType.Equals(entity.PartitionKey)) { indexEntry.CardType = entity.PartitionKey; rebuiltEntries.Add(indexEntry); Console.WriteLine($"Entry '{indexEntry}' updated"); count++; } } } } if (count > 0) { Console.Write("Index by monster: uploading rebuilt index..."); indexUtils.BatchInsertOrMergeEntityAsync(indexEntities, true).GetAwaiter().GetResult(); Console.WriteLine($"done\n{indexEntities.Count} entr{(indexEntities.Count == 1 ? "y" : "ies")} found\n{count} entr{(count == 1 ? "y" : "ies")} rebuilt"); } else { Console.WriteLine("Index by Monster: no entries to update found."); } }
private static void ExecuteAdd(ProgramParameters parameters, CloudTable cardsTable, CloudTable indexTable) { MonsterCardEntity monsterCard = new MonsterCardEntity(); IndexByMonsterEntity indexCard = new IndexByMonsterEntity(); TableUtils <MonsterCardEntity> cardUtils = new TableUtils <MonsterCardEntity>(cardsTable); TableUtils <IndexByMonsterEntity> indexUtils = new TableUtils <IndexByMonsterEntity>(indexTable); monsterCard.PartitionKey = parameters.CardType.ToString(); indexCard.CardType = parameters.CardType.ToString(); monsterCard.RowKey = ReadNotEmptyLine("Card name: "); MonsterCardEntity existingCard = cardUtils.RetrieveEntityUsingPointQueryAsync(monsterCard.PartitionKey, monsterCard.RowKey).GetAwaiter().GetResult(); if (existingCard != null) { Console.WriteLine($"Entry '{monsterCard.PartitionKey} {monsterCard.RowKey}' already exists in database. If you continue, existing entry will be REPLACED."); string option = ReadOption("Continue (yes/no)? ", "Y", "y", "yes", "Yes", "N", "n", "No", "no"); switch (option) { case "N": case "n": case "no": case "No": { Console.WriteLine("Aborted by user."); return; } } } indexCard.RowKey = monsterCard.RowKey; monsterCard.Expansion = ReadNotEmptyLine("Expansion: "); monsterCard.Versions = ReadNotEmptyLine("Versions: "); if (parameters.CardType != CardType.StrangeResource && parameters.CardType != CardType.BasicResource && parameters.CardType != CardType.Universal && parameters.CardType != CardType.BasicHuntEvent && parameters.CardType != CardType.SpecialHuntEvent) { indexCard.PartitionKey = ReadNotEmptyLine("Monster: "); } switch (parameters.CardType) { case CardType.AI: case CardType.Universal: { monsterCard.AILevel = ReadNotEmptyLine("AI Level: "); Console.Write("AI card types (if any): "); monsterCard.AITypes = Console.ReadLine(); monsterCard.CardText = ReadNotEmptyLine("Card Text: "); } break; case CardType.MonsterResource: case CardType.BasicResource: case CardType.StrangeResource: { monsterCard.ResourceKeywords = ReadNotEmptyLine("Keywords: "); monsterCard.CardText = ReadNotEmptyLine("Card Text: "); } break; case CardType.HitLocation: { Console.Write("HL types (if any): "); monsterCard.HLTypes = Console.ReadLine(); Console.Write("Card text (if any): "); monsterCard.CardText = Console.ReadLine(); Console.Write("Reaction - Failure (if any): "); monsterCard.HLReactionFailure = Console.ReadLine(); Console.Write("Reaction - Wound (if any): "); monsterCard.HLReactionWound = Console.ReadLine(); Console.Write("Reaction - Reflex (if any): "); monsterCard.HLReactionReflex = Console.ReadLine(); Console.Write("Critical Wound text (if any): "); monsterCard.HLCriticalText = Console.ReadLine(); } break; case CardType.HuntEvent: case CardType.SpecialHuntEvent: case CardType.BasicHuntEvent: { monsterCard.EventSubtitle = ReadNotEmptyLine("Event subtitle: "); monsterCard.CardText = ReadNotEmptyLine("Card text: "); Console.Write("Event bottom text (if any): "); monsterCard.EventBottomText = Console.ReadLine(); } break; default: { Trace.TraceError($"Unable to parse CardType '{parameters.CardType}'"); return; } } monsterCard.Multiplicity = ReadInt("# of cards (default 1): ", 1); Trace.TraceInformation($"Adding to database: [{monsterCard}]"); Console.WriteLine($"*************\n{monsterCard}\n*************"); cardUtils.InsertOrMergeEntityAsync(monsterCard, true).GetAwaiter().GetResult(); if (parameters.CardType != CardType.BasicResource && parameters.CardType != CardType.StrangeResource && parameters.CardType != CardType.Universal && parameters.CardType != CardType.BasicHuntEvent && parameters.CardType != CardType.SpecialHuntEvent) { indexUtils.InsertOrMergeEntityAsync(indexCard, true).GetAwaiter().GetResult(); } Console.WriteLine("Data added."); }