public override Task <CosmosResponseMessage> SendAsync( CosmosRequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } CosmosRequestOptions promotedRequestOptions = request.RequestOptions; if (promotedRequestOptions != null) { // Fill request options promotedRequestOptions.FillRequestOptions(request); // Validate the request consistency compatibility with account consistency // Type based access context for requested consistency preferred for performance ConsistencyLevel?consistencyLevel = null; if (promotedRequestOptions is CosmosItemRequestOptions) { consistencyLevel = (promotedRequestOptions as CosmosItemRequestOptions).ConsistencyLevel; } else if (promotedRequestOptions is CosmosQueryRequestOptions) { consistencyLevel = (promotedRequestOptions as CosmosQueryRequestOptions).ConsistencyLevel; } else if (promotedRequestOptions is CosmosStoredProcedureRequestOptions) { consistencyLevel = (promotedRequestOptions as CosmosStoredProcedureRequestOptions).ConsistencyLevel; } if (consistencyLevel.HasValue) { if (!ValidationHelpers.ValidateConsistencyLevel(this.client.AccountConsistencyLevel, consistencyLevel.Value)) { throw new ArgumentException(string.Format( CultureInfo.CurrentUICulture, RMResources.InvalidConsistencyLevel, consistencyLevel.Value.ToString(), this.client.AccountConsistencyLevel)); } } } return(this.client.DocumentClient.EnsureValidClientAsync() .ContinueWith(task => request.AssertPartitioningDetailsAsync(client, cancellationToken)) .ContinueWith(task => { if (task.IsFaulted) { throw task.Exception; } this.FillMultiMasterContext(request); return base.SendAsync(request, cancellationToken); }) .Unwrap()); }
public async Task EnsureContainer(int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { Database = await _client.Databases.CreateDatabaseIfNotExistsAsync(_options.Database, throughput, requestOptions, cancellationToken); CosmosContainerSettings containerDefinition = new CosmosContainerSettings(id: ContainerName, partitionKeyPath: PartitionPath); containerDefinition.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 }); Container = await Database.Containers.CreateContainerIfNotExistsAsync(containerSettings : containerDefinition, throughput, requestOptions, cancellationToken); }
private Task <CosmosResponseMessage> NextResultSetDelegate( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { // Validate that same contract is sent back on delegate Assert.IsTrue(object.ReferenceEquals(this.ContinuationToken, continuationToken)); Assert.IsTrue(object.ReferenceEquals(this.Options, options)); // CancellationToken is a struct and refs will not match Assert.AreEqual(this.CancellationToken.IsCancellationRequested, cancellationToken.IsCancellationRequested); return(Task.FromResult(GetHttpResponse())); }