internal Task <UserDefinedFunctionResponse> CreateUserDefinedFunctionResponseAsync(Task <CosmosResponseMessage> cosmosResponseMessageTask)
 {
     return(this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
     {
         CosmosUserDefinedFunctionSettings settings = this.ToObjectInternal <CosmosUserDefinedFunctionSettings>(cosmosResponseMessage, this.settingsSerializer);
         return new UserDefinedFunctionResponse(
             cosmosResponseMessage.StatusCode,
             cosmosResponseMessage.Headers,
             settings);
     }));
 }
 /// <summary>
 /// Replaces a <see cref="CosmosUserDefinedFunctionSettings"/> in the Azure Cosmos DB service as an asynchronous operation.
 /// </summary>
 /// <param name="userDefinedFunctionSettings">The <see cref="CosmosUserDefinedFunctionSettings"/> object.</param>
 /// <param name="requestOptions">(Optional) The options for the user defined function 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="CosmosUserDefinedFunctionResponse"/> which wraps a <see cref="CosmosUserDefinedFunctionSettings"/> containing the updated 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 delete did not exist.</description>
 ///     </item>
 /// </list>
 /// </exception>
 /// <example>
 /// This examples replaces an existing user defined function.
 /// <code language="c#">
 /// <![CDATA[
 /// //Updated settings
 /// CosmosUserDefinedFunctionSettings settings = new CosmosUserDefinedFunctionSettings
 /// {
 ///     Id = "testUserDefinedFunId",
 ///     Body = "function(amt) { return amt * 0.15; }",
 /// };
 ///
 /// CosmosUserDefinedFunctionResponse response = await this.cosmosUserDefinedFunction.ReplaceAsync(settings);
 /// CosmosUserDefinedFunctionSettings settings = response;
 /// ]]>
 /// </code>
 /// </example>
 public virtual Task <CosmosUserDefinedFunctionResponse> ReplaceAsync(
     CosmosUserDefinedFunctionSettings userDefinedFunctionSettings,
     CosmosRequestOptions requestOptions = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(this.ProcessAsync(
                partitionKey: null,
                streamPayload: userDefinedFunctionSettings.GetResourceStream(),
                operationType: OperationType.Replace,
                requestOptions: requestOptions,
                cancellationToken: cancellationToken));
 }
 internal Task <CosmosUserDefinedFunctionResponse> CreateUserDefinedFunctionResponse(
     CosmosUserDefinedFunction userDefinedFunction,
     Task <CosmosResponseMessage> cosmosResponseMessageTask)
 {
     return(this.MessageHelper(cosmosResponseMessageTask, (cosmosResponseMessage) =>
     {
         CosmosUserDefinedFunctionSettings settings = this.ToObjectInternal <CosmosUserDefinedFunctionSettings>(cosmosResponseMessage);
         return new CosmosUserDefinedFunctionResponse(
             cosmosResponseMessage.StatusCode,
             cosmosResponseMessage.Headers,
             settings,
             userDefinedFunction);
     }));
 }
示例#4
0
 /// <summary>
 /// Creates a user defined function as an asynchronous operation in the Azure Cosmos DB service.
 /// </summary>
 /// <param name="userDefinedFunctionSettings">The <see cref="CosmosUserDefinedFunctionSettings"/> object.</param>
 /// <param name="requestOptions">(Optional) The options for the user defined function request <see cref="CosmosRequestOptions"/></param>
 /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
 /// <returns>A task object representing the service response for the asynchronous operation.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="userDefinedFunctionSettings"/> 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 user defined function 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 user defined function or that the Body was malformed.</description>
 ///     </item>
 ///     <item>
 ///         <term>403</term><description>Forbidden - You have reached your quota of user defined functions for the collection supplied. Contact support to have this quota increased.</description>
 ///     </item>
 ///     <item>
 ///         <term>409</term><description>Conflict - This means a <see cref="CosmosUserDefinedFunctionSettings"/> with an id matching the id you supplied already existed.</description>
 ///     </item>
 ///     <item>
 ///         <term>413</term><description>RequestEntityTooLarge - This means the body of the <see cref="CosmosUserDefinedFunctionSettings"/> you tried to create was too large.</description>
 ///     </item>
 /// </list>
 /// </exception>
 /// <example>
 ///  This creates a user defined function then uses the function in an item query.
 /// <code language="c#">
 /// <![CDATA[
 ///
 /// await this.container.UserDefinedFunctions.CreateUserDefinedFunctionAsync(
 ///     new CosmosUserDefinedFunctionSettings
 ///     {
 ///         Id = "calculateTax",
 ///         Body = @"function(amt) { return amt * 0.05; }"
 ///     });
 ///
 /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition(
 ///     "SELECT VALUE udf.calculateTax(t.cost) FROM toDoActivity t where t.cost > @expensive and t.status = @status")
 ///     .UseParameter("@expensive", 9000)
 ///     .UseParameter("@status", "Done");
 ///
 /// CosmosResultSetIterator<double> setIterator = this.container.Items.CreateItemQuery<double>(
 ///     sqlQueryDefinition: sqlQuery,
 ///     partitionKey: "Done");
 ///
 /// while (setIterator.HasMoreResults)
 /// {
 ///     foreach (var tax in await setIterator.FetchNextSetAsync())
 ///     {
 ///         Console.WriteLine(tax);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public virtual Task <CosmosUserDefinedFunctionResponse> CreateUserDefinedFunctionAsync(
     CosmosUserDefinedFunctionSettings userDefinedFunctionSettings,
     CosmosRequestOptions requestOptions = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ExecUtils.ProcessResourceOperationAsync <CosmosUserDefinedFunctionResponse>(
                this.container.Database.Client,
                this.container.LinkUri,
                ResourceType.UserDefinedFunction,
                OperationType.Create,
                requestOptions,
                partitionKey: null,
                streamPayload: userDefinedFunctionSettings.GetResourceStream(),
                requestEnricher: null,
                responseCreator: response => this.client.ResponseFactory.CreateUserDefinedFunctionResponse(response, new CosmosUserDefinedFunction(this.container, userDefinedFunctionSettings.Id)),
                cancellationToken: cancellationToken));
 }
示例#5
0
        /// <summary>
        /// Creates a user defined function as an asynchronous operation in the Azure Cosmos DB service.
        /// </summary>
        /// <param name="userDefinedFunctionSettings">The <see cref="CosmosUserDefinedFunctionSettings"/> object.</param>
        /// <param name="requestOptions">(Optional) The options for the user defined function request <see cref="CosmosRequestOptions"/></param>
        /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
        /// <returns>A task object representing the service response for the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="userDefinedFunctionSettings"/> 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 user defined function 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 user defined function or that the Body was malformed.</description>
        ///     </item>
        ///     <item>
        ///         <term>403</term><description>Forbidden - You have reached your quota of user defined functions for the collection supplied. Contact support to have this quota increased.</description>
        ///     </item>
        ///     <item>
        ///         <term>409</term><description>Conflict - This means a <see cref="CosmosUserDefinedFunctionSettings"/> with an id matching the id you supplied already existed.</description>
        ///     </item>
        ///     <item>
        ///         <term>413</term><description>RequestEntityTooLarge - This means the body of the <see cref="CosmosUserDefinedFunctionSettings"/> you tried to create was too large.</description>
        ///     </item>
        /// </list>
        /// </exception>
        /// <example>
        ///  This creates a user defined function then uses the function in an item query.
        /// <code language="c#">
        /// <![CDATA[
        ///
        /// await this.container.UserDefinedFunctions.CreateUserDefinedFunctionAsync(
        ///     new CosmosUserDefinedFunctionSettings
        ///     {
        ///         Id = "calculateTax",
        ///         Body = @"function(amt) { return amt * 0.05; }"
        ///     });
        ///
        /// CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition(
        ///     "SELECT VALUE udf.calculateTax(t.cost) FROM toDoActivity t where t.cost > @expensive and t.status = @status")
        ///     .UseParameter("@expensive", 9000)
        ///     .UseParameter("@status", "Done");
        ///
        /// CosmosResultSetIterator<double> setIterator = this.container.Items.CreateItemQuery<double>(
        ///     sqlQueryDefinition: sqlQuery,
        ///     partitionKey: "Done");
        ///
        /// while (setIterator.HasMoreResults)
        /// {
        ///     foreach (var tax in await setIterator.FetchNextSetAsync())
        ///     {
        ///         Console.WriteLine(tax);
        ///     }
        /// }
        /// ]]>
        /// </code>
        /// </example>
        public virtual Task <CosmosUserDefinedFunctionResponse> CreateUserDefinedFunctionAsync(
            CosmosUserDefinedFunctionSettings userDefinedFunctionSettings,
            CosmosRequestOptions requestOptions = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Task <CosmosResponseMessage> response = this.clientContext.ProcessResourceOperationStreamAsync(
                resourceUri: this.container.LinkUri,
                resourceType: ResourceType.UserDefinedFunction,
                operationType: OperationType.Create,
                requestOptions: requestOptions,
                cosmosContainerCore: this.container,
                partitionKey: null,
                streamPayload: CosmosResource.ToStream(userDefinedFunctionSettings),
                requestEnricher: null,
                cancellationToken: cancellationToken);

            return(this.clientContext.ResponseFactory.CreateUserDefinedFunctionResponse(this[userDefinedFunctionSettings.Id], response));
        }