Beispiel #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Welcome to the Heroes Table Storage sample!");

            Console.WriteLine("Let's connect to our table");

            string connectionString = AppSettings.LoadAppSettings().ConnectionString;

            CloudTableClient tableClient = TableHelpers.ConnectToClient(connectionString);

            CloudTable cloudTable = tableClient.GetTableReference("HeroesDB");

            List <HeroEntity> heroes = GenerateHeros();

            try
            {
                foreach (var hero in heroes)
                {
                    await OperationsHelper.InsertOrMergeHero(cloudTable, hero);
                }

                Console.WriteLine("Let's see if we can find Superman! Performing a read.");

                var superman = await OperationsHelper.GetHero(cloudTable, "Superman", "Clark Kent");

                Console.WriteLine("Wait, his hometown isn't right! Let's update it.");

                superman.Hometown = "Kryptonopolis";

                await OperationsHelper.InsertOrMergeHero(cloudTable, superman);

                Console.WriteLine("Let's 'snap' Tony Stark out of the Universe (too soon?).");

                HeroEntity tonyStark = await OperationsHelper.GetHero(cloudTable, "Iron Man", "Tony Stark");

                await OperationsHelper.DeleteHero(cloudTable, tonyStark);

                Console.WriteLine("Love you 3000");

                Console.WriteLine("Sample over. Press any key to exit....");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Something went wrong. Exception thrown: {ex.Message}");
                Console.ReadLine();
                throw;
            }
        }