public async Task InitAsync()

in DEV - Building your Applications for the Cloud/DEV50/src/TailwindTraderServerless/_DataAccess/InventoryInitializer.cs [25:71]


        public async Task InitAsync()
        {
            Console.WriteLine("Initializing inventory database...");
            var random = new Random();
            var dataAccess = new StorageAccess();
            await dataAccess.InitTableAsync();
            await dataAccess.InitBlobAsync();
            var table = dataAccess.table;
            var container = dataAccess.container;
            Console.WriteLine("Deleting old table...");
            await table.DeleteIfExistsAsync();
            var tableCreated = false;
            while (!tableCreated)
            {
                try
                {
                    tableCreated = await table.CreateIfNotExistsAsync();
                }
                catch (StorageException se)
                {
                    Console.WriteLine(se.Message);
                    Console.WriteLine("Trying again in 10 seconds...");
                    Thread.Sleep(10000);
                }
                catch
                {
                    throw;
                }
            }
            for (var idx = 0; idx < skus.Length; idx += 1)
            {
                var item = new TableInventoryItem
                {
                    Sku = skus[idx],
                    Price = (decimal)(random.NextDouble() * 100),
                    ImageUrl = await LoadImageAsync(container, skus[idx]),
                    HumanDescription = descriptions[idx],
                    PriceSet = true,
                    DescriptionSet = true,
                    ImageSet = true,
                    IsActive = true
                };
                var operation = TableOperation.Insert(item);
                await table.ExecuteAsync(operation);
                Console.WriteLine($"Inserted sku {item.Sku}: {item.Description}");
            }            
        }