public override Task <ResponseMessage> ReplaceContainerStreamAsync( ContainerProperties containerProperties, ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(this.Container.ReplaceContainerStreamAsync( containerProperties, requestOptions, cancellationToken)); }
public static async Task Main(string[] args) { Console.WriteLine($"Hello Cosmos DB World! {System.AppDomain.CurrentDomain.FriendlyName}"); var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); string endpoint = configuration["EndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid endpoint in the appSettings.json"); } string authKey = configuration["AuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid AuthorizationKey in the appSettings.json"); } CosmosClientOptions options = new CosmosClientOptions() { AllowBulkExecution = true }; client = new CosmosClient(endpoint, authKey, options); DatabaseResponse databaseResponse = await client.CreateDatabaseIfNotExistsAsync(databaseName); Database database = databaseResponse; ContainerProperties containerProperties = new ContainerProperties(containerName, containerPartitionKey); ContainerRequestOptions containerRequestOptions = new ContainerRequestOptions { PopulateQuotaInfo = true }; ContainerResponse containerResponse = await database.CreateContainerIfNotExistsAsync( containerProperties : containerProperties, throughputProperties : ThroughputProperties.CreateAutoscaleThroughput(autoscaleMaxThroughput: 4000), containerRequestOptions ); long indexTransformationProgress = long.Parse(containerResponse.Headers["x-ms-documentdb-collection-index-transformation-progress"]); Console.WriteLine($" Index status {indexTransformationProgress}"); Container container = containerResponse.Container; // await InsertSalesOrders(container, 1000000); await QueryContainer(container); Console.WriteLine("Done!"); }
public async Task TestPreProcessingHandler() { RequestHandler preProcessHandler = new PreProcessingTestHandler(); using CosmosClient client = MockCosmosUtil.CreateMockCosmosClient((builder) => builder.AddCustomHandlers(preProcessHandler)); Assert.IsTrue(typeof(RequestInvokerHandler).Equals(client.RequestHandler.GetType())); Assert.IsTrue(typeof(PreProcessingTestHandler).Equals(client.RequestHandler.InnerHandler.GetType())); Container container = client.GetDatabase("testdb") .GetContainer("testcontainer"); HttpStatusCode[] testHttpStatusCodes = new HttpStatusCode[] { HttpStatusCode.OK }; // User operations foreach (HttpStatusCode code in testHttpStatusCodes) { ItemRequestOptions options = new ItemRequestOptions { Properties = new Dictionary <string, object>() { { PreProcessingTestHandler.StatusCodeName, code }, } }; ItemResponse <object> response = await container.ReadItemAsync <object>("id1", new Cosmos.PartitionKey("pk1"), options); Console.WriteLine($"Got status code {response.StatusCode}"); Assert.AreEqual(code, response.StatusCode); } // Meta-data operations foreach (HttpStatusCode code in testHttpStatusCodes) { ContainerRequestOptions options = new ContainerRequestOptions { Properties = new Dictionary <string, object>() { { PreProcessingTestHandler.StatusCodeName, code } } }; ContainerResponse response = await container.DeleteContainerAsync(options); Console.WriteLine($"Got status code {response.StatusCode}"); Assert.AreEqual(code, response.StatusCode); } }
public async Task ReIndexingTest() { ContainerProperties cp = new ContainerProperties() { Id = "ReIndexContainer", PartitionKeyPath = "/pk", IndexingPolicy = new Cosmos.IndexingPolicy() { Automatic = false, } }; ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(cp); Container container = response; ContainerProperties existingContainerProperties = response.Resource; // Turn on indexing existingContainerProperties.IndexingPolicy.Automatic = true; existingContainerProperties.IndexingPolicy.IndexingMode = Cosmos.IndexingMode.Consistent; await container.ReplaceContainerAsync(existingContainerProperties); // Check progress ContainerRequestOptions requestOptions = new ContainerRequestOptions(); requestOptions.PopulateQuotaInfo = true; while (true) { ContainerResponse readResponse = await container.ReadContainerAsync(requestOptions); string indexTransformationStatus = readResponse.Headers["x-ms-documentdb-collection-index-transformation-progress"]; Assert.IsNotNull(indexTransformationStatus); if (int.Parse(indexTransformationStatus) == 100) { break; } await Task.Delay(TimeSpan.FromMilliseconds(20)); } }
private static async Task <float> GetReEncryptionProgressPercentageAsync( Container sourceContainer, Container targetContainer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ContainerRequestOptions containerRequestOptions = new ContainerRequestOptions { PopulateQuotaInfo = true }; ContainerResponse result = await sourceContainer.ReadContainerAsync(containerRequestOptions); string usage = result.Headers["x-ms-resource-usage"]; int index = usage.IndexOf("documentsCount"); string[] quotas = usage.Remove(0, index).Split(';'); long sourceContainerTotalDocCount = long.Parse(quotas[0].Split('=')[1]); result = await targetContainer.ReadContainerAsync(containerRequestOptions); usage = result.Headers["x-ms-resource-usage"]; index = usage.IndexOf("documentsCount"); quotas = usage.Remove(0, index).Split(';'); long destinationContainerTotalDocCount = long.Parse(quotas[0].Split('=')[1]); if (destinationContainerTotalDocCount > sourceContainerTotalDocCount) { destinationContainerTotalDocCount = sourceContainerTotalDocCount - (destinationContainerTotalDocCount - sourceContainerTotalDocCount); } float progress = 100 * (float)((double)destinationContainerTotalDocCount / (double)sourceContainerTotalDocCount); Program.ShowReEncryptionProgressBar((int)destinationContainerTotalDocCount, (int)sourceContainerTotalDocCount, (int)progress); return(progress); }
public override Task <ContainerResponse> ReadContainerAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(_container.ReadContainerAsync(requestOptions, cancellationToken)); }
public override Task <ResponseMessage> DeleteContainerStreamAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(_container.DeleteContainerStreamAsync(requestOptions, cancellationToken)); }
public override Task <ResponseMessage> DeleteContainerStreamAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
public override Task <ContainerResponse> ReplaceContainerAsync(ContainerProperties containerProperties, ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
public override Task <ResponseMessage> DeleteContainerStreamAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { var returnValue = new ResponseMessage(); return(Task.FromResult(returnValue)); }
public override Task <ContainerResponse> DeleteContainerAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { var returnValue = new CosmosContainerResponseMock(); return(Task.FromResult((ContainerResponse)returnValue)); }
public override Task <ContainerResponse> DeleteContainerAsync(ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public override Task <ResponseMessage> ReplaceContainerStreamAsync(ContainerProperties containerProperties, ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();