public override Task <CosmosResponseMessage> SendAsync( CosmosRequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } RequestOptions 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 Cosmos.ConsistencyLevel?consistencyLevel = null; if (promotedRequestOptions is ItemRequestOptions) { consistencyLevel = (promotedRequestOptions as ItemRequestOptions).ConsistencyLevel; } else if (promotedRequestOptions is QueryRequestOptions) { consistencyLevel = (promotedRequestOptions as QueryRequestOptions).ConsistencyLevel; } else if (promotedRequestOptions is StoredProcedureRequestOptions) { consistencyLevel = (promotedRequestOptions as StoredProcedureRequestOptions).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(this.client, cancellationToken)) .ContinueWith(task => { if (task.IsFaulted) { throw task.Exception; } this.FillMultiMasterContext(request); return base.SendAsync(request, cancellationToken); }) .Unwrap()); }