public override Task <CosmosDatabaseResponse> CreateDatabaseAsync( string id, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { CosmosDatabaseSettings databaseSettings = this.PrepareCosmosDatabaseSettings(id); return(this.CreateDatabaseAsync( databaseSettings: databaseSettings, throughput: throughput, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
internal Task <DatabaseResponse> CreateDatabaseAsync( CosmosDatabaseSettings databaseSettings, int?requestUnitsPerSecond = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { Task <CosmosResponseMessage> response = this.CreateDatabaseStreamInternalAsync( streamPayload: this.ClientContext.SettingsSerializer.ToStream <CosmosDatabaseSettings>(databaseSettings), requestUnitsPerSecond: requestUnitsPerSecond, requestOptions: requestOptions, cancellationToken: cancellationToken); return(this.ClientContext.ResponseFactory.CreateDatabaseResponseAsync(this.GetDatabase(databaseSettings.Id), response)); }
internal Task <CosmosDatabaseResponse> CreateDatabaseResponse( CosmosDatabase database, Task <CosmosResponseMessage> cosmosResponseMessageTask) { return(this.MessageHelper(cosmosResponseMessageTask, (cosmosResponseMessage) => { CosmosDatabaseSettings settings = this.ToObjectInternal <CosmosDatabaseSettings>(cosmosResponseMessage); return new CosmosDatabaseResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, settings, database); })); }
internal Task <CosmosDatabaseResponse> CreateDatabaseAsync( CosmosDatabaseSettings databaseSettings, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { Task <CosmosResponseMessage> response = this.CreateDatabaseStreamAsync( streamPayload: CosmosResource.ToStream(databaseSettings), throughput: throughput, requestOptions: requestOptions, cancellationToken: cancellationToken); return(this.clientContext.ResponseFactory.CreateDatabaseResponse(this[databaseSettings.Id], response)); }
internal Task <DatabaseResponse> CreateDatabaseResponseAsync( CosmosDatabase database, Task <CosmosResponseMessage> cosmosResponseMessageTask) { return(this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) => { CosmosDatabaseSettings settings = this.ToObjectInternal <CosmosDatabaseSettings>(cosmosResponseMessage, this.settingsSerializer); return new DatabaseResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, settings, database); })); }
internal static CosmosDatabaseSettings PrepareCosmosDatabaseSettings(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } CosmosDatabaseSettings databaseSettings = new CosmosDatabaseSettings() { Id = id }; return(databaseSettings); }
/// <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="id">The database id.</param> /// <param name="throughput">(Optional) The throughput provisioned for a collection in measurement of Requests-per-Unit 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="CosmosDatabaseResponse"/> which wraps a <see cref="CosmosDatabaseSettings"/> containing the resource record.</returns> public virtual Task <CosmosDatabaseResponse> CreateDatabaseAsync( string id, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { CosmosDatabaseSettings databaseSettings = CosmosDatabases.PrepareCosmosDatabaseSettings(id); return(CreateDatabaseAsync( databaseSettings, throughput, requestOptions, cancellationToken)); }
internal CosmosDatabaseSettings PrepareCosmosDatabaseSettings(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } CosmosDatabaseSettings databaseSettings = new CosmosDatabaseSettings() { Id = id }; this.ClientContext.ValidateResource(databaseSettings.Id); return(databaseSettings); }
/// <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="databaseSettings">The database settings</param> /// <param name="requestUnitsPerSecond">(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="CosmosDatabaseSettings"/> containing the resource record.</returns> /// <remarks> /// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units"/> for details on provision throughput. /// </remarks> public virtual Task <CosmosResponseMessage> CreateDatabaseStreamAsync( CosmosDatabaseSettings databaseSettings, int?requestUnitsPerSecond = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (databaseSettings == null) { throw new ArgumentNullException(nameof(databaseSettings)); } this.ClientContext.ValidateResource(databaseSettings.Id); Stream streamPayload = this.ClientContext.SettingsSerializer.ToStream <CosmosDatabaseSettings>(databaseSettings); return(this.CreateDatabaseStreamInternalAsync(streamPayload, requestUnitsPerSecond, requestOptions, cancellationToken)); }
internal virtual Task <CosmosDatabaseResponse> CreateDatabaseAsync( CosmosDatabaseSettings databaseSettings, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(CosmosDatabases.CreateDatabaseCoreAsync( databaseSettings, this.client, response => this.client.ResponseFactory.CreateDatabaseResponse( response, new CosmosDatabase(this.client, databaseSettings.Id)), requestOptions, throughput, 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="id">The database id.</param> /// <param name="requestUnitsPerSecond">(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="CosmosDatabaseSettings"/> containing the resource record.</returns> /// <remarks> /// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units"/> for details on provision throughput. /// </remarks> public virtual Task <DatabaseResponse> CreateDatabaseAsync( string id, int?requestUnitsPerSecond = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } CosmosDatabaseSettings databaseSettings = this.PrepareCosmosDatabaseSettings(id); return(this.CreateDatabaseAsync( databaseSettings: databaseSettings, requestUnitsPerSecond: requestUnitsPerSecond, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
public override Task <DatabaseResponse> CreateDatabaseAsync( string id, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } CosmosDatabaseSettings databaseSettings = this.PrepareCosmosDatabaseSettings(id); return(this.CreateDatabaseAsync( databaseSettings: databaseSettings, throughput: throughput, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
internal static Task <T> CreateDatabaseCoreAsync <T>( CosmosDatabaseSettings databaseSettings, CosmosClient client, Func <CosmosResponseMessage, T> responseCreator, CosmosRequestOptions requestOptions = null, int?throughput = null, CancellationToken cancellationToken = default(CancellationToken)) { client.DocumentClient.ValidateResource(databaseSettings); Uri resourceUri = new Uri(Paths.Databases_Root, UriKind.Relative); return(ExecUtils.ProcessResourceOperationAsync <T>( client, resourceUri, ResourceType.Database, OperationType.Create, requestOptions, partitionKey: null, streamPayload: databaseSettings.GetResourceStream(), requestEnricher: (httpRequestMessage) => httpRequestMessage.AddThroughputHeader(throughput), responseCreator: responseCreator, 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="databaseSettings">The database settings</param> /// <param name="throughput">(Optional) The throughput provisioned for a collection in measurement of Requests-per-Unit 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="CosmosDatabaseSettings"/> containing the resource record.</returns> public abstract Task <CosmosResponseMessage> CreateDatabaseAsStreamAsync( CosmosDatabaseSettings databaseSettings, int?throughput = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken));