Example #1
0
        private static void ExecuteUpload(CloudStorageAccount account, string sourceDataFile)
        {
            DumpSerialization dump = null;

            try
            {
                Console.Write("Loading source data file...");
                dump = DumpSerialization.FromFile(sourceDataFile);
                Console.WriteLine("done");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"failed\nError accessing source data file '{sourceDataFile}':\n{ex}");
                return;
            }

            //todo: same considerations as the ExecuteDump() todo annotation

            Console.Write($"Inserting entries for table '{cardsTableName}'...");
            CloudTable t = Task.Run(async() => await Common.CreateTableAsync(account, dump.Cards.TableName)).GetAwaiter().GetResult();

            foreach (MonsterCardEntity e in dump.Cards.Items)
            {
                TableOperation op = TableOperation.InsertOrReplace(e);
                t.ExecuteAsync(op).GetAwaiter().GetResult();
            }
            Console.WriteLine($"done - {dump.Cards.Items.Length} entries uploaded");

            Console.Write($"Inserting entries for table '{indexTableName}'...");
            t = Task.Run(async() => await Common.CreateTableAsync(account, dump.Index.TableName)).GetAwaiter().GetResult();
            foreach (IndexByMonsterEntity e in dump.Index.Items)
            {
                TableOperation op = TableOperation.InsertOrReplace(e);
                t.ExecuteAsync(op).GetAwaiter().GetResult();
            }
            Console.WriteLine($"done - {dump.Index.Items.Length} entries uploaded");

            Console.Write($"Inserting entries for table '{monsterTableName}'...");
            t = Task.Run(async() => await Common.CreateTableAsync(account, dump.Monsters.TableName)).GetAwaiter().GetResult();
            foreach (MonsterEntry e in dump.Monsters.Items)
            {
                TableOperation op = TableOperation.InsertOrReplace(e);
                t.ExecuteAsync(op).GetAwaiter().GetResult();
            }
            Console.WriteLine($"done - {dump.Monsters.Items.Length} entries uploaded");
        }
Example #2
0
        private static void ExecuteDump(CloudTable cards, CloudTable index, CloudTable monsters, string targetDataFile)
        {
            DumpSerialization dump = new DumpSerialization();

            //todo: we will swap this with a good powershell cmdlet, eventually.
            //at the moment, we are okay with a static count of items - we just need to populate the initial list

            Console.WriteLine($"Dump of table '{cardsTableName}'");
            dump.Cards = new CardsTableDescriptor
            {
                TableName = cardsTableName
            };
            Console.Write("Retrieving rows...");
            var cardsEntities = cards.ExecuteQuery(new TableQuery <MonsterCardEntity>()).ToList();

            dump.Cards.Items = cardsEntities.ToArray();
            Console.WriteLine($"done - {dump.Cards.Items.Length} entries retrieved");

            Console.WriteLine($"Dump of table '{indexTableName}'");
            dump.Index = new IndexTableDescriptor
            {
                TableName = indexTableName
            };
            Console.Write("Retrieving rows...");
            var indexEntities = index.ExecuteQuery(new TableQuery <IndexByMonsterEntity>()).ToList();

            dump.Index.Items = indexEntities.ToArray();
            Console.WriteLine($"done - {dump.Index.Items.Length} entries retrieved");

            Console.WriteLine($"Dump of table '{monsterTableName}'");
            dump.Monsters = new MonstersTableDescriptor
            {
                TableName = monsterTableName
            };
            Console.Write("Retrieving rows...");
            var monsterEntities = monsters.ExecuteQuery(new TableQuery <MonsterEntry>()).ToList();

            dump.Monsters.Items = monsterEntities.ToArray();
            Console.WriteLine($"done - {dump.Monsters.Items.Length} entries retrieved");

            Console.Write("Saving dump to file...");
            dump.Save(targetDataFile);
            Console.WriteLine("done\n");
        }