public async Task <IActionResult> GenerateCatalogReadTableData() { try { var correlationToken = Guid.NewGuid().ToString(); // First, clear out any data in ReadModel var currentReadTableItems = _productRepository.GetList(ProductPartitionKey).Result; if (currentReadTableItems.Count() > 0) { // Delete all product readmodel entities as a batch await ProcessReadTable(currentReadTableItems, correlationToken, DeletetProduct); } var products = _musicRepository.GetAll(correlationToken); if (products.Count < 1) { throw new Exception("Error in Seed Catalog Read Table -- Cannot get reference to the Products Table"); } // Transform to InventoryItemEntity objects var productEntityObjects = products.Select(x => new ProductEntity { PartitionKey = ProductPartitionKey, RowKey = x.Id.ToString(), Title = x.Title, ArtistName = x.Artist.Name, Cutout = x.Cutout, GenreName = x.Genre.Name, ParentalCaution = x.ParentalCaution, Price = x.Price.ToString(), ReleaseDate = x.ReleaseDate, Upc = x.Upc }).ToList(); // Add product readmodel entities as a batch await ProcessReadTable(productEntityObjects, correlationToken, InsertProduct); } catch (Exception ex) { throw new Exception($"Could not build Catalog Read Table in DataInitializer. Message : {ex.Message}"); } return(NoContent()); }
public IActionResult CheckConnections() { var configurationState = string.Empty; var correlationToken = Guid.NewGuid().ToString(); // Can I read UserSecrets and present configuration data configurationState = string.IsNullOrEmpty(configuration["ServiceBusPublisherConnectionString"]) ? "ServiceBus Connection string missing/n" : string.Empty; var serviceBusConnectionString = configuration["ServiceBusPublisherConnectionString"]; var topicName = configuration["ServiceBusTopicName"]; var subscriptionName = configuration["ServiceBusSubscriptionName"]; var storageAccount = configuration["StorageAccount"]; var storageKey = configuration["StorageKey"]; var storageTable = configuration["StorageTableName_Basket"]; var cosmosConnectionString = configuration["CosmosEndpoint"]; var cosmosKey = configuration["CosmosPrimaryKey"]; var databaseConnectonString = configuration["CatalogConnectionString"]; var connectionString = configuration["ServiceBusPublisherConnectionString"]; //var topicName = configuration["ServiceBusTopicName"]; //var subscriptionName = configuration["ServiceBusSubscriptionName"]; Guard.ForNullOrEmpty(connectionString, "ConnectionString from Catalog is Null"); Guard.ForNullOrEmpty(topicName, "TopicName from Catalog is Null"); Guard.ForNullOrEmpty(subscriptionName, "SubscriptionName from Catalog is Null"); //Can I connect to the SqlDB and query products? var products = musicRepository.GetAll(correlationToken); if (products.Count < 1) { throw new Exception("Error in Seed Catalog Read Table -- Cannot get reference to the Products Table"); } var productEntityObjects = products.Select(x => new ProductEntity { PartitionKey = ProductPartitionKey, RowKey = x.Id.ToString(), Title = x.Title, ArtistName = x.Artist.Name, Cutout = x.Cutout, GenreName = x.Genre.Name, ParentalCaution = x.ParentalCaution, Price = x.Price.ToString(), ReleaseDate = x.ReleaseDate, Upc = x.Upc }); try { var currentReadTableItems = productRepository.GetList(ProductPartitionKey).Result; var count = currentReadTableItems.Count(); // Empty product read table for (var i = 0; i < count; i++) { productRepository.Delete(currentReadTableItems[i].PartitionKey, currentReadTableItems[i].RowKey); } // Populate product read table foreach (var item in productEntityObjects) { productRepository.Insert(item, correlationToken); } } catch (Exception ex) { throw new Exception($"Could not build Catalog Read Table in DataInitializer. Message : {ex.Message}"); } // Can I connect to Azure Storage and query on baskets? // Can I connect to Azure Service Bus and ensure that each Topic and subscription is present? // Can I connect to CosmosDB and query for orders? configurationState = "This feature is not enabled\n\n"; return(Ok(configurationState)); }