示例#1
0
        /// <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>
        /// <exception>https://aka.ms/cosmosdb-dot-net-exceptions</exception>
        /// <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));
            }

            return(this.ClientContext.OperationHelperAsync(
                       nameof(CreateDatabaseAsync),
                       requestOptions,
                       (diagnostics) =>
            {
                DatabaseProperties databaseProperties = this.PrepareDatabaseProperties(id);
                ThroughputProperties throughputProperties = ThroughputProperties.CreateManualThroughput(throughput);

                return this.CreateDatabaseInternalAsync(
                    databaseProperties: databaseProperties,
                    throughputProperties: throughputProperties,
                    requestOptions: requestOptions,
                    diagnosticsContext: diagnostics,
                    cancellationToken: cancellationToken);
            }));
        }
示例#2
0
        /// <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>
        /// <exception>https://aka.ms/cosmosdb-dot-net-exceptions</exception>
        /// <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));
            }

            return(this.ClientContext.OperationHelperAsync(
                       nameof(CreateDatabaseStreamAsync),
                       requestOptions,
                       (diagnostics) =>
            {
                this.ClientContext.ValidateResource(databaseProperties.Id);
                return this.CreateDatabaseStreamInternalAsync(
                    diagnostics,
                    databaseProperties,
                    ThroughputProperties.CreateManualThroughput(throughput),
                    requestOptions,
                    cancellationToken);
            }));
        }
示例#3
0
 internal Task <ThroughputResponse> ReplaceThroughputIfExistsAsync(
     string targetRID,
     int throughput,
     RequestOptions requestOptions,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(this.ReplaceThroughputPropertiesIfExistsAsync(
                targetRID,
                ThroughputProperties.CreateManualThroughput(throughput),
                requestOptions,
                cancellationToken));
 }
示例#4
0
 public Task <ThroughputResponse> ReplaceThroughputAsync(
     int throughput,
     ITrace trace,
     RequestOptions requestOptions       = null,
     CancellationToken cancellationToken = default)
 {
     return(this.ReplaceThroughputAsync(
                throughputProperties: ThroughputProperties.CreateManualThroughput(throughput),
                requestOptions: requestOptions,
                trace: trace,
                cancellationToken: cancellationToken));
 }
 public Task <ThroughputResponse> ReplaceThroughputAsync(
     CosmosDiagnosticsContext diagnosticsContext,
     int throughput,
     RequestOptions requestOptions       = null,
     CancellationToken cancellationToken = default)
 {
     return(this.ReplaceThroughputAsync(
                diagnosticsContext: diagnosticsContext,
                throughputProperties: ThroughputProperties.CreateManualThroughput(throughput),
                requestOptions: requestOptions,
                cancellationToken: cancellationToken));
 }
示例#6
0
        /// <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>
        /// <exception>https://aka.ms/cosmosdb-dot-net-exceptions</exception>
        /// <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))
        {
            ThroughputProperties throughputProperties = ThroughputProperties.CreateManualThroughput(throughput);

            return(this.CreateDatabaseIfNotExistsAsync(
                       id,
                       throughputProperties,
                       requestOptions,
                       cancellationToken));
        }
示例#7
0
        private Task <ResponseMessage> CreateDatabaseStreamInternalAsync(
            Stream streamPayload,
            int?throughput,
            RequestOptions requestOptions,
            CancellationToken cancellationToken)
        {
            ThroughputProperties throughputProperties = null;

            if (throughput.HasValue)
            {
                throughputProperties = ThroughputProperties.CreateManualThroughput(throughput.Value);
            }

            return(this.CreateDatabaseStreamInternalAsync(
                       streamPayload,
                       throughputProperties,
                       requestOptions,
                       cancellationToken));
        }
示例#8
0
        public Task <ContainerResponse> CreateContainerIfNotExistsAsync(
            ContainerProperties containerProperties,
            int?throughput,
            RequestOptions requestOptions,
            ITrace trace,
            CancellationToken cancellationToken)
        {
            if (containerProperties == null)
            {
                throw new ArgumentNullException(nameof(containerProperties));
            }

            return(this.CreateContainerIfNotExistsAsync(
                       containerProperties,
                       ThroughputProperties.CreateManualThroughput(throughput),
                       requestOptions,
                       trace,
                       cancellationToken));
        }