public override Task <CosmosItemResponse <TOutput> > ExecuteAsync <TInput, TOutput>( object partitionKey, TInput input, CosmosStoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { CosmosItemsCore.ValidatePartitionKey(partitionKey, requestOptions); Stream parametersStream; if (input != null && !input.GetType().IsArray) { parametersStream = this.Client.CosmosJsonSerializer.ToStream <TInput[]>(new TInput[1] { input }); } else { parametersStream = this.Client.CosmosJsonSerializer.ToStream <TInput>(input); } Task <CosmosResponseMessage> response = ExecUtils.ProcessResourceOperationStreamAsync( this.Client, this.LinkUri, ResourceType.StoredProcedure, OperationType.ExecuteJavaScript, requestOptions, partitionKey, parametersStream, null, cancellationToken); return(this.Client.ResponseFactory.CreateItemResponse <TOutput>(response)); }
public override Task <CosmosItemResponse <TOutput> > ExecuteAsync <TInput, TOutput>( object partitionKey, TInput input, CosmosStoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { CosmosItemsCore.ValidatePartitionKey(partitionKey, requestOptions); Stream parametersStream; if (input != null && !input.GetType().IsArray) { parametersStream = this.clientContext.JsonSerializer.ToStream <TInput[]>(new TInput[1] { input }); } else { parametersStream = this.clientContext.JsonSerializer.ToStream <TInput>(input); } Task <CosmosResponseMessage> response = this.clientContext.ProcessResourceOperationStreamAsync( resourceUri: this.LinkUri, resourceType: ResourceType.StoredProcedure, operationType: OperationType.ExecuteJavaScript, requestOptions: requestOptions, cosmosContainerCore: this.container, partitionKey: partitionKey, streamPayload: parametersStream, requestEnricher: null, cancellationToken: cancellationToken); return(this.clientContext.ResponseFactory.CreateItemResponse <TOutput>(response)); }
/// <summary> /// Executes a stored procedure against a container as an asynchronous operation in the Azure Cosmos service. /// </summary> /// <typeparam name="TInput">The input type that is JSON serializable.</typeparam> /// <typeparam name="TOutput">The return type that is JSON serializable.</typeparam> /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param> /// <param name="input">The JSON serializable input parameters.</param> /// <param name="requestOptions">(Optional) The options for the stored procedure request <see cref="CosmosStoredProcedureRequestOptions"/></param> /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>The task object representing the service response for the asynchronous operation which would contain any response set in the stored procedure.</returns> /// <example> /// This creates and executes a stored procedure that appends a string to the first item returned from the query. /// <code language="c#"> /// <![CDATA[ /// string sprocBody = @"function simple(prefix) /// { /// var collection = getContext().getCollection(); /// /// // Query documents and take 1st item. /// var isAccepted = collection.queryDocuments( /// collection.getSelfLink(), /// 'SELECT * FROM root r', /// function(err, feed, options) { /// if (err)throw err; /// /// // Check the feed and if it's empty, set the body to 'no docs found', /// // Otherwise just take 1st element from the feed. /// if (!feed || !feed.length) getContext().getResponse().setBody(""no docs found""); /// else getContext().getResponse().setBody(prefix + JSON.stringify(feed[0])); /// }); /// /// if (!isAccepted) throw new Error(""The query wasn't accepted by the server. Try again/use continuation token between API and script.""); /// }"; /// /// CosmosStoredProcedure cosmosStoredProcedure = await this.container.StoredProcedures.CreateStoredProceducreAsync( /// id: "appendString", /// body: sprocBody); /// /// // Execute the stored procedure /// CosmosItemResponse<string> sprocResponse = await storedProcedure.ExecuteAsync<string, string>(testPartitionId, "Item as a string: "); /// Console.WriteLine("sprocResponse.Resource"); /// /// ]]> /// </code> /// </example> public abstract Task <CosmosItemResponse <TOutput> > ExecuteAsync <TInput, TOutput>( object partitionKey, TInput input, CosmosStoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken));