internal static Task <T> ProcessCollectionCreateAsync <T>(
            CosmosContainerSettings containerSettings,
            CosmosDatabase database,
            int?throughput,
            Func <CosmosResponseMessage, T> responseCreator,
            CosmosRequestOptions requestOptions = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (containerSettings == null)
            {
                throw new ArgumentNullException(nameof(containerSettings));
            }

            containerSettings.ValidateRequiredProperties();
            database.Client.DocumentClient.ValidateResource(containerSettings);
            return(ExecUtils.ProcessResourceOperationAsync <T>(
                       database.Client,
                       database.LinkUri,
                       ResourceType.Collection,
                       OperationType.Create,
                       requestOptions,
                       partitionKey: null,
                       streamPayload: containerSettings.GetResourceStream(),
                       requestEnricher: (httpRequestMessage) => httpRequestMessage.AddThroughputHeader(throughput),
                       responseCreator: responseCreator,
                       cancellationToken: cancellationToken));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Replace a <see cref="CosmosContainerSettings"/> from the Azure Cosmos service as an asynchronous operation.
        /// </summary>
        /// <param name="containerSettings">The <see cref="CosmosContainerSettings"/> object.</param>
        /// <param name="requestOptions">(Optional) The options for the container request <see cref="CosmosRequestOptions"/></param>
        /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
        /// <returns>
        /// A <see cref="Task"/> containing a <see cref="CosmosContainerResponse"/> which wraps a <see cref="CosmosContainerSettings"/> containing the replace resource record.
        /// </returns>
        /// <exception cref="CosmosException">This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:
        /// <list type="table">
        ///     <listheader>
        ///         <term>StatusCode</term><description>Reason for exception</description>
        ///     </listheader>
        ///     <item>
        ///         <term>404</term><description>NotFound - This means the resource you tried to read did not exist.</description>
        ///     </item>
        ///     <item>
        ///         <term>429</term><description>TooManyRequests - This means you have exceeded the number of request units per second. Consult the DocumentClientException.RetryAfter value to see how long you should wait before retrying this operation.</description>
        ///     </item>
        /// </list>
        /// </exception>
        /// <example>
        /// Update the cosmosContainer to disable automatic indexing
        /// <code language="c#">
        /// <![CDATA[
        /// ContainerSettings setting = containerReadResponse;
        /// setting.IndexingPolicy.Automatic = false;
        /// CosmosContainerResponse response = cosmosContainer.ReplaceAsync(setting);
        /// ContainerSettings settings = response;
        /// ]]>
        /// </code>
        /// </example>
        public virtual Task <CosmosContainerResponse> ReplaceAsync(
            CosmosContainerSettings containerSettings,
            CosmosContainerRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            this.Database.Client.DocumentClient.ValidateResource(containerSettings);

            Task <CosmosResponseMessage> response = this.ReplaceStreamAsync(
                streamPayload: containerSettings.GetResourceStream(),
                requestOptions: requestOptions,
                cancellationToken: cancellationToken);

            return(this.Client.ResponseFactory.CreateContainerResponse(this, response));
        }
 private Task <CosmosContainerResponse> ProcessAsync(
     CosmosContainerSettings containerSettings,
     OperationType operationType,
     CosmosContainerRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default(CancellationToken))
 {
     return(ExecUtils.ProcessResourceOperationAsync <CosmosContainerResponse>(
                this.Client,
                this.LinkUri,
                ResourceType.Collection,
                operationType,
                requestOptions,
                containerSettings?.GetResourceStream(),
                response =>
                this.Client.ResponseFactory.CreateContainerResponse(response, this),
                cancellationToken));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a container as an asynchronous operation in the Azure Cosmos service.
        /// </summary>
        /// <param name="containerSettings">The <see cref="CosmosContainerSettings"/> object.</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) The options for the container request <see cref="CosmosRequestOptions"/></param>
        /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
        /// <returns>A <see cref="Task"/> containing a <see cref="CosmosContainerResponse"/> which wraps a <see cref="CosmosContainerSettings"/> containing the read resource record.</returns>
        /// <exception cref="ArgumentNullException">If either <paramref name="containerSettings"/> is not set.</exception>
        /// <exception cref="System.AggregateException">Represents a consolidation of failures that occurred during async processing. Look within InnerExceptions to find the actual exception(s).</exception>
        /// <exception cref="CosmosException">This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a container are:
        /// <list type="table">
        ///     <listheader>
        ///         <term>StatusCode</term><description>Reason for exception</description>
        ///     </listheader>
        ///     <item>
        ///         <term>400</term><description>BadRequest - This means something was wrong with the request supplied. It is likely that an id was not supplied for the new container.</description>
        ///     </item>
        ///     <item>
        ///         <term>403</term><description>Forbidden - This means you attempted to exceed your quota for containers. Contact support to have this quota increased.</description>
        ///     </item>
        ///     <item>
        ///         <term>409</term><description>Conflict - This means a <see cref="CosmosContainerSettings"/> with an id matching the id you supplied already existed.</description>
        ///     </item>
        /// </list>
        /// </exception>
        /// <example>
        ///
        /// <code language="c#">
        /// <![CDATA[
        /// CosmosContainerSettings settings = new CosmosContainerSettings()
        /// {
        ///     Id = Guid.NewGuid().ToString(),
        ///     IndexingPolicy = new IndexingPolicy()
        ///    {
        ///         Automatic = false,
        ///         IndexingMode = IndexingMode.Lazy,
        ///    };
        /// };
        ///
        /// CosmosContainerResponse response = this.cosmosDatabase.Containers.CreateContainerAsync(settings);
        /// ]]>
        /// </code>
        /// </example>
        public virtual Task <CosmosContainerResponse> CreateContainerAsync(
            CosmosContainerSettings containerSettings,
            int?throughput = null,
            CosmosRequestOptions requestOptions = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (containerSettings == null)
            {
                throw new ArgumentNullException(nameof(containerSettings));
            }

            this.ValidateContainerSettings(containerSettings);

            Task <CosmosResponseMessage> response = this.CreateContainerStreamAsync(
                streamPayload: containerSettings.GetResourceStream(),
                throughput: throughput,
                requestOptions: requestOptions,
                cancellationToken: cancellationToken);

            return(this.client.ResponseFactory.CreateContainerResponse(this[containerSettings.Id], response));
        }