/// <summary> /// Create a partitioned container. /// </summary> /// <returns>The created container.</returns> private static async Task <ContainerResponse> CreatePartitionedContainerAsync(BenchmarkConfig options, CosmosClient cosmosClient) { Microsoft.Azure.Cosmos.Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync(options.Database); Container container = database.GetContainer(options.Container); try { return(await container.ReadContainerAsync()); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { // Show user cost of running this test double estimatedCostPerMonth = 0.06 * options.Throughput; double estimatedCostPerHour = estimatedCostPerMonth / (24 * 30); Console.WriteLine($"The container will cost an estimated ${Math.Round(estimatedCostPerHour, 2)} per hour (${Math.Round(estimatedCostPerMonth, 2)} per month)"); Console.WriteLine("Press enter to continue ..."); Console.ReadLine(); string partitionKeyPath = options.PartitionKeyPath; return(await database.CreateContainerAsync(options.Container, partitionKeyPath, options.Throughput)); } }
private async Task <Container> CreateContainerAsync(Database db) { var containerId = RandomName(); var containerResponse = await db.CreateContainerAsync(containerId, "/PartitionKey"); return(containerResponse.Container); }
private static async Task <Container> CreateDemoEnvironment(CosmosClient client) { ContainerResponse hotelContainer = null; try { // Set up a database Microsoft.Azure.Cosmos.Database database = await client.CreateDatabaseIfNotExistsAsync(databaseId); // Container and Throughput Properties ContainerProperties containerProperties = new ContainerProperties(readHeavyId, "/CityName"); ThroughputProperties throughputProperties = ThroughputProperties.CreateAutoscaleThroughput(20000); // Create a read heavy environment hotelContainer = await database.CreateContainerAsync( containerProperties, throughputProperties); } catch (CosmosException ce) { Console.WriteLine($"Exception thrown by Cosmos DB: {ce.StatusCode}, {ce.Message}"); } catch (Exception ex) { Console.WriteLine($"General Exception thrown: {ex.Message}"); throw; } return(hotelContainer); }