public override Task <ThroughputResponse> ReplaceThroughputAsync( int throughput, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceThroughputAsync(throughput, requestOptions, cancellationToken))); }
/// <inheritdoc/> public override Task <DataEncryptionKeyResponse> ReadAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.dataEncryptionKey.ReadAsync(requestOptions, cancellationToken))); }
public override Task <ItemResponse <T> > ReadCurrentAsync <T>( ConflictProperties cosmosConflict, PartitionKey partitionKey, CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.ReadCurrentAsync <T>(cosmosConflict, partitionKey, cancellationToken))); }
public override Task <ResponseMessage> DeleteAsync( ConflictProperties conflict, PartitionKey partitionKey, CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.DeleteAsync(conflict, partitionKey, cancellationToken))); }
/// <summary> /// <para>Check if a database exists, and if it doesn't, create it. /// Only the database id is used to verify if there is an existing database. Other database properties /// such as throughput are not validated and can be different then the passed properties.</para> /// /// <para>A database manages users, permissions and a set of containers. /// Each Azure Cosmos DB Database Account is able to support multiple independent named databases, /// with the database being the logical container for data.</para> /// /// <para>Each Database consists of one or more containers, each of which in turn contain one or more /// documents. Since databases are an administrative resource, the Service Master Key will be /// required in order to access and successfully complete any action using the User APIs.</para> /// </summary> /// <param name="id">The database id.</param> /// <param name="throughput">(Optional) The throughput provisioned for a database in measurement of Request Units per second in the Azure Cosmos DB service.</param> /// <param name="requestOptions">(Optional) A set of additional options that can be set.</param> /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>A <see cref="Task"/> containing a <see cref="DatabaseResponse"/> which wraps a <see cref="DatabaseProperties"/> containing the resource record. /// <list type="table"> /// <listheader> /// <term>StatusCode</term><description>Common success StatusCodes for the CreateDatabaseIfNotExistsAsync operation</description> /// </listheader> /// <item> /// <term>201</term><description>Created - New database is created.</description> /// </item> /// <item> /// <term>200</term><description>Accepted - This means the database already exists.</description> /// </item> /// </list> /// </returns> /// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso> public virtual Task <DatabaseResponse> CreateDatabaseIfNotExistsAsync( string id, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } return(TaskHelper.RunInlineIfNeededAsync(async() => { // Doing a Read before Create will give us better latency for existing databases DatabaseProperties databaseProperties = this.PrepareDatabaseProperties(id); Database database = this.GetDatabase(id); ResponseMessage response = await database.ReadStreamAsync(requestOptions: requestOptions, cancellationToken: cancellationToken); if (response.StatusCode != HttpStatusCode.NotFound) { return await this.ClientContext.ResponseFactory.CreateDatabaseResponseAsync(database, Task.FromResult(response)); } response = await this.CreateDatabaseStreamAsync(databaseProperties, throughput, requestOptions, cancellationToken); if (response.StatusCode != HttpStatusCode.Conflict) { return await this.ClientContext.ResponseFactory.CreateDatabaseResponseAsync(this.GetDatabase(databaseProperties.Id), Task.FromResult(response)); } // This second Read is to handle the race condition when 2 or more threads have Read the database and only one succeeds with Create // so for the remaining ones we should do a Read instead of throwing Conflict exception return await database.ReadAsync(cancellationToken: cancellationToken); })); }
public override Task <UserResponse> UpsertUserAsync( string id, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.UpsertUserAsync(id, requestOptions, cancellationToken))); }
public override Task <ItemResponse <T> > CreateItemAsync <T>(T item, PartitionKey?partitionKey = null, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.CreateItemAsync <T>(item, partitionKey, requestOptions, cancellationToken))); }
public override Task <ResponseMessage> ReplaceContainerStreamAsync( ContainerProperties containerProperties, ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceContainerStreamAsync(containerProperties, requestOptions, cancellationToken))); }
public override Task <UserResponse> ReplaceAsync( UserProperties userProperties, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceAsync(userProperties, requestOptions, cancellationToken))); }
public override Task <PermissionResponse> ReadAsync( int?tokenExpiryInSeconds = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.ReadAsync(tokenExpiryInSeconds, requestOptions, cancellationToken))); }
public override Task <ContainerResponse> CreateContainerAsync(string id, string partitionKeyPath, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.CreateContainerAsync(id, partitionKeyPath, throughput, requestOptions, cancellationToken))); }
public override Task <ResponseMessage> DeleteItemStreamAsync( string id, PartitionKey partitionKey, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.DeleteItemStreamAsync(id, partitionKey, requestOptions, cancellationToken))); }
public override Task <ResponseMessage> UpsertItemStreamAsync( Stream streamPayload, PartitionKey partitionKey, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.UpsertItemStreamAsync(streamPayload, partitionKey, requestOptions, cancellationToken))); }
public override Task <PermissionResponse> CreatePermissionAsync( PermissionProperties permissionProperties, int?tokenExpiryInSeconds = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.CreatePermissionAsync(permissionProperties, tokenExpiryInSeconds, requestOptions, cancellationToken))); }
public override Task <ItemResponse <T> > DeleteItemAsync <T>( string id, PartitionKey partitionKey, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteItemAsync <T>(id, partitionKey, requestOptions, cancellationToken))); }
public override Task <ResponseMessage> CreateContainerStreamAsync( ContainerProperties containerProperties, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.CreateContainerStreamAsync(containerProperties, throughput, requestOptions, cancellationToken))); }
public override Task <ContainerResponse> CreateContainerIfNotExistsAsync( ContainerProperties containerProperties, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.CreateContainerIfNotExistsAsync(containerProperties, throughput, requestOptions, cancellationToken))); }
Task <ContainerResponse> CreateContainerIfNotExistsAsync( ContainerProperties containerProperties, ThroughputProperties throughputProperties, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.CreateContainerIfNotExistsAsync(containerProperties, throughputProperties, requestOptions, cancellationToken))); }
Task <DataEncryptionKeyResponse> CreateDataEncryptionKeyAsync( string id, CosmosEncryptionAlgorithm encryptionAlgorithm, EncryptionKeyWrapMetadata encryptionKeyWrapMetadata, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.CreateDataEncryptionKeyAsync(id, encryptionAlgorithm, encryptionKeyWrapMetadata, requestOptions, cancellationToken))); }
public override Task <ItemResponse <T> > ReplaceItemAsync <T>( T item, string id, PartitionKey?partitionKey = null, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => base.ReplaceItemAsync <T>(item, id, partitionKey, requestOptions, cancellationToken))); }
/// <inheritdoc/> public override Task <DataEncryptionKeyResponse> RewrapAsync( EncryptionKeyWrapMetadata newWrapMetadata, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (newWrapMetadata == null) { throw new ArgumentNullException(nameof(newWrapMetadata)); } return(TaskHelper.RunInlineIfNeededAsync(() => this.dataEncryptionKey.RewrapAsync(newWrapMetadata, requestOptions, cancellationToken))); }
/// <summary> /// Sends a request for creating a database. /// /// A database manages users, permissions and a set of containers. /// Each Azure Cosmos DB Database Account is able to support multiple independent named databases, /// with the database being the logical container for data. /// /// Each Database consists of one or more containers, each of which in turn contain one or more /// documents. Since databases are an administrative resource, the Service Master Key will be /// required in order to access and successfully complete any action using the User APIs. /// </summary> /// <param name="id">The database id.</param> /// <param name="throughput">(Optional) The throughput provisioned for a database in measurement of Request Units per second in the Azure Cosmos DB service.</param> /// <param name="requestOptions">(Optional) A set of options that can be set.</param> /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>A <see cref="Task"/> containing a <see cref="DatabaseResponse"/> which wraps a <see cref="DatabaseProperties"/> containing the resource record.</returns> /// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso> public virtual Task <DatabaseResponse> CreateDatabaseAsync( string id, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } DatabaseProperties databaseProperties = this.PrepareDatabaseProperties(id); return(TaskHelper.RunInlineIfNeededAsync(() => this.CreateDatabaseAsync( databaseProperties: databaseProperties, throughput: throughput, requestOptions: requestOptions, cancellationToken: cancellationToken))); }
/// <summary> /// Send a request for creating a database. /// /// A database manages users, permissions and a set of containers. /// Each Azure Cosmos DB Database Account is able to support multiple independent named databases, /// with the database being the logical container for data. /// /// Each Database consists of one or more containers, each of which in turn contain one or more /// documents. Since databases are an administrative resource, the Service Master Key will be /// required in order to access and successfully complete any action using the User APIs. /// </summary> /// <param name="databaseProperties">The database properties</param> /// <param name="throughput">(Optional) The throughput provisioned for a database in measurement of Request Units per second in the Azure Cosmos DB service.</param> /// <param name="requestOptions">(Optional) A set of options that can be set.</param> /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>A <see cref="Task"/> containing a <see cref="DatabaseResponse"/> which wraps a <see cref="DatabaseProperties"/> containing the resource record.</returns> /// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso> public virtual Task <ResponseMessage> CreateDatabaseStreamAsync( DatabaseProperties databaseProperties, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (databaseProperties == null) { throw new ArgumentNullException(nameof(databaseProperties)); } this.ClientContext.ValidateResource(databaseProperties.Id); Stream streamPayload = this.ClientContext.SerializerCore.ToStream <DatabaseProperties>(databaseProperties); return(TaskHelper.RunInlineIfNeededAsync(() => this.CreateDatabaseStreamInternalAsync( streamPayload, throughput, requestOptions, cancellationToken))); }
public override Task <ThroughputResponse> ReadThroughputAsync( RequestOptions requestOptions, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.ReadThroughputAsync(requestOptions, cancellationToken))); }
public override Task <int?> ReadThroughputAsync(CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadThroughputAsync(cancellationToken))); }
public override Task <ContainerResponse> DeleteContainerAsync( ContainerRequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteContainerAsync(requestOptions, cancellationToken))); }
public override Task <IEnumerable <string> > GetPartitionKeyRangesAsync( FeedToken feedToken, CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.GetPartitionKeyRangesAsync(feedToken, cancellationToken))); }
public override Task <IReadOnlyList <FeedToken> > GetFeedTokensAsync(CancellationToken cancellationToken = default(CancellationToken)) { return(TaskHelper.RunInlineIfNeededAsync(() => this.container.GetFeedTokensAsync(cancellationToken))); }
public override Task <ResponseMessage> ReadNextAsync(ITrace trace, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.feedIteratorInternal.ReadNextAsync(trace, cancellationToken))); }
public override Task <ResponseMessage> DeleteStreamAsync( RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(TaskHelper.RunInlineIfNeededAsync(() => this.database.DeleteStreamAsync(requestOptions, cancellationToken))); }