Ejemplo n.º 1
0
        public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
            string storedProcedureId,
            Stream streamPayload,
            Cosmos.PartitionKey partitionKey,
            StoredProcedureRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(storedProcedureId))
            {
                throw new ArgumentNullException(nameof(storedProcedureId));
            }

            ContainerInternal.ValidatePartitionKey(partitionKey, requestOptions);

            Uri linkUri = this.clientContext.CreateLink(
                parentLink: this.container.LinkUri.OriginalString,
                uriPathSegment: Paths.StoredProceduresPathSegment,
                id: storedProcedureId);

            return(this.ProcessStreamOperationAsync(
                       resourceUri: linkUri,
                       resourceType: ResourceType.StoredProcedure,
                       operationType: OperationType.ExecuteJavaScript,
                       partitionKey: partitionKey,
                       streamPayload: streamPayload,
                       requestOptions: requestOptions,
                       cancellationToken: cancellationToken));
        }
Ejemplo n.º 2
0
        public Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
            CosmosDiagnosticsContext diagnosticsContext,
            string storedProcedureId,
            Cosmos.PartitionKey partitionKey,
            dynamic[] parameters,
            StoredProcedureRequestOptions requestOptions,
            ITrace trace,
            CancellationToken cancellationToken)
        {
            Stream streamPayload = null;

            if (parameters != null)
            {
                streamPayload = this.ClientContext.SerializerCore.ToStream <dynamic[]>(parameters);
            }

            return(this.ExecuteStoredProcedureStreamAsync(
                       diagnosticsContext: diagnosticsContext,
                       storedProcedureId: storedProcedureId,
                       partitionKey: partitionKey,
                       streamPayload: streamPayload,
                       requestOptions: requestOptions,
                       trace: trace,
                       cancellationToken: cancellationToken));
        }
Ejemplo n.º 3
0
        public Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
            CosmosDiagnosticsContext diagnosticsContext,
            string storedProcedureId,
            Stream streamPayload,
            Cosmos.PartitionKey partitionKey,
            StoredProcedureRequestOptions requestOptions,
            ITrace trace,
            CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(storedProcedureId))
            {
                throw new ArgumentNullException(nameof(storedProcedureId));
            }

            ContainerInternal.ValidatePartitionKey(partitionKey, requestOptions);

            string linkUri = this.ClientContext.CreateLink(
                parentLink: this.container.LinkUri,
                uriPathSegment: Paths.StoredProceduresPathSegment,
                id: storedProcedureId);

            return(this.ProcessStreamOperationAsync(
                       diagnosticsContext: diagnosticsContext,
                       resourceUri: linkUri,
                       resourceType: ResourceType.StoredProcedure,
                       operationType: OperationType.ExecuteJavaScript,
                       partitionKey: partitionKey,
                       streamPayload: streamPayload,
                       requestOptions: requestOptions,
                       trace: trace,
                       cancellationToken: cancellationToken));
        }
        public override Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TInput, TOutput>(
            Cosmos.PartitionKey partitionKey,
            string storedProcedureId,
            TInput input,
            StoredProcedureRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            Stream parametersStream;

            if (input != null && !input.GetType().IsArray)
            {
                parametersStream = this.clientContext.CosmosSerializer.ToStream <TInput[]>(new TInput[1] {
                    input
                });
            }
            else
            {
                parametersStream = this.clientContext.CosmosSerializer.ToStream <TInput>(input);
            }

            Task <CosmosResponseMessage> response = this.ExecuteStoredProcedureStreamAsync(
                partitionKey: partitionKey,
                storedProcedureId: storedProcedureId,
                streamPayload: parametersStream,
                requestOptions: requestOptions,
                cancellationToken: cancellationToken);

            return(this.clientContext.ResponseFactory.CreateStoredProcedureExecuteResponseAsync <TOutput>(response));
        }
Ejemplo n.º 5
0
 public override Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TOutput>(
     string storedProcedureId,
     Cosmos.PartitionKey partitionKey,
     dynamic[] parameters,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ExecuteStoredProcedureAsync <TOutput>(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)));
 }
Ejemplo n.º 6
0
 public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
     string storedProcedureId,
     Stream streamPayload,
     Cosmos.PartitionKey partitionKey,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(TaskHelper.RunInlineIfNeededAsync(() => this.scripts.ExecuteStoredProcedureStreamAsync(storedProcedureId, streamPayload, partitionKey, requestOptions, cancellationToken)));
 }
 public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
     string storedProcedureId,
     Cosmos.PartitionKey partitionKey,
     dynamic[] parameters,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(TaskHelper.RunInlineIfNeededAsync(() => base.ExecuteStoredProcedureStreamAsync(storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)));
 }
Ejemplo n.º 8
0
 public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
     string storedProcedureId,
     Stream streamPayload,
     Cosmos.PartitionKey partitionKey,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(this.ClientContext.OperationHelperAsync(
                nameof(ExecuteStoredProcedureStreamAsync),
                requestOptions,
                (diagnostics) => base.ExecuteStoredProcedureStreamAsync(diagnostics, storedProcedureId, streamPayload, partitionKey, requestOptions, cancellationToken)));
 }
Ejemplo n.º 9
0
 public override Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TOutput>(
     string storedProcedureId,
     Cosmos.PartitionKey partitionKey,
     dynamic[] parameters,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(this.ClientContext.OperationHelperAsync(
                nameof(ExecuteStoredProcedureAsync),
                requestOptions,
                (diagnostics) => base.ExecuteStoredProcedureAsync <TOutput>(diagnostics, storedProcedureId, partitionKey, parameters, requestOptions, cancellationToken)));
 }
 public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
     string storedProcedureId,
     Cosmos.PartitionKey partitionKey,
     dynamic[] parameters,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default)
 {
     return(this.ClientContext.OperationHelperAsync(
                nameof(ExecuteStoredProcedureStreamAsync),
                requestOptions,
                (trace) => base.ExecuteStoredProcedureStreamAsync(storedProcedureId, partitionKey, parameters, requestOptions, trace, cancellationToken)));
 }
Ejemplo n.º 11
0
        public override async Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TOutput>(
            string storedProcedureId,
            Cosmos.PartitionKey partitionKey,
            dynamic[] parameters,
            StoredProcedureRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            ResponseMessage response = await this.ExecuteStoredProcedureStreamAsync(
                storedProcedureId : storedProcedureId,
                partitionKey : partitionKey,
                parameters : parameters,
                requestOptions : requestOptions,
                cancellationToken : cancellationToken);

            return(this.clientContext.ResponseFactory.CreateStoredProcedureExecuteResponse <TOutput>(response));
        }
Ejemplo n.º 12
0
        public async Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TOutput>(
            CosmosDiagnosticsContext diagnosticsContext,
            string storedProcedureId,
            Cosmos.PartitionKey partitionKey,
            dynamic[] parameters,
            StoredProcedureRequestOptions requestOptions,
            CancellationToken cancellationToken)
        {
            ResponseMessage response = await this.ExecuteStoredProcedureStreamAsync(
                diagnosticsContext : diagnosticsContext,
                storedProcedureId : storedProcedureId,
                partitionKey : partitionKey,
                parameters : parameters,
                requestOptions : requestOptions,
                cancellationToken : cancellationToken);

            return(this.ClientContext.ResponseFactory.CreateStoredProcedureExecuteResponse <TOutput>(response));
        }
        public override Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TInput, TOutput>(
            Cosmos.PartitionKey partitionKey,
            string id,
            TInput input,
            StoredProcedureRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            CosmosContainerCore.ValidatePartitionKey(partitionKey, requestOptions);

            Stream parametersStream;

            if (input != null && !input.GetType().IsArray)
            {
                parametersStream = this.clientContext.CosmosSerializer.ToStream <TInput[]>(new TInput[1] {
                    input
                });
            }
            else
            {
                parametersStream = this.clientContext.CosmosSerializer.ToStream <TInput>(input);
            }

            Uri linkUri = this.clientContext.CreateLink(
                parentLink: this.container.LinkUri.OriginalString,
                uriPathSegment: Paths.StoredProceduresPathSegment,
                id: id);

            Task <CosmosResponseMessage> response = this.ProcessStreamOperationAsync(
                resourceUri: linkUri,
                resourceType: ResourceType.StoredProcedure,
                operationType: OperationType.ExecuteJavaScript,
                partitionKey: partitionKey,
                streamPayload: parametersStream,
                requestOptions: requestOptions,
                cancellationToken: cancellationToken);

            return(this.clientContext.ResponseFactory.CreateStoredProcedureExecuteResponseAsync <TOutput>(response));
        }
Ejemplo n.º 14
0
        public override Task <ResponseMessage> ExecuteStoredProcedureStreamAsync(
            string storedProcedureId,
            Cosmos.PartitionKey partitionKey,
            dynamic[] parameters,
            StoredProcedureRequestOptions requestOptions = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            Stream streamPayload = null;

            if (parameters != null)
            {
                streamPayload = this.clientContext.SerializerCore.ToStream <dynamic[]>(parameters);
            }

            return(this.ExecuteStoredProcedureStreamAsync(
                       storedProcedureId: storedProcedureId,
                       partitionKey: partitionKey,
                       streamPayload: streamPayload,
                       requestOptions: requestOptions,
                       cancellationToken: cancellationToken));
        }
 /// <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="id">The identifier of the Stored Procedure to execute.</param>
 /// <param name="input">The JSON serializable input parameters.</param>
 /// <param name="requestOptions">(Optional) The options for the stored procedure request <see cref="StoredProcedureRequestOptions"/></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>
 /// <exception cref="ArgumentNullException">If <paramref name="id"/> or <paramref name="partitionKey"/>  are not set.</exception>
 /// <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."");
 ///    }";
 ///
 /// CosmosScripts scripts = this.container.GetScripts();
 /// CosmosStoredProcedure cosmosStoredProcedure = await scripts.CreateStoredProcedureAsync(
 ///         id: "appendString",
 ///         body: sprocBody);
 ///
 /// // Execute the stored procedure
 /// CosmosItemResponse<string> sprocResponse = await scripts.ExecuteAsync<string, string>(testPartitionId, "Item as a string: ");
 /// Console.WriteLine("sprocResponse.Resource");
 /// /// ]]>
 /// </code>
 /// </example>
 public abstract Task <StoredProcedureExecuteResponse <TOutput> > ExecuteStoredProcedureAsync <TInput, TOutput>(
     PartitionKey partitionKey,
     string id,
     TInput input,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default(CancellationToken));
Ejemplo n.º 16
0
 /// <summary>
 /// Executes a stored procedure against a container as an asynchronous operation in the Azure Cosmos service and obtains a Stream as response.
 /// </summary>
 /// <param name="partitionKey">The partition key for the item. <see cref="Microsoft.Azure.Documents.PartitionKey"/></param>
 /// <param name="storedProcedureId">The identifier of the Stored Procedure to execute.</param>
 /// <param name="streamPayload">The stream representing the input for the stored procedure.</param>
 /// <param name="requestOptions">(Optional) The options for the stored procedure request <see cref="StoredProcedureRequestOptions"/></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>
 /// <exception cref="ArgumentNullException">If <paramref name="storedProcedureId"/> or <paramref name="partitionKey"/>  are not set.</exception>
 /// <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."");
 ///    }";
 ///
 /// CosmosScripts scripts = this.container.GetScripts();
 /// CosmosStoredProcedure cosmosStoredProcedure = await scripts.CreateStoredProcedureAsync(
 ///         id: "appendString",
 ///         body: sprocBody);
 ///
 /// // Execute the stored procedure
 /// CosmosResponseMessage sprocResponse = await scripts.ExecuteStoredProcedureStreamAsync(testPartitionId, streamPayload: stream);
 /// using (StreamReader sr = new StreamReader(sprocResponse.Content))
 /// {
 ///     string stringResponse = await sr.ReadToEndAsync();
 ///     Console.WriteLine(stringResponse);
 ///  }
 ///
 /// /// ]]>
 /// </code>
 /// </example>
 public abstract Task <CosmosResponseMessage> ExecuteStoredProcedureStreamAsync(
     PartitionKey partitionKey,
     string storedProcedureId,
     Stream streamPayload,
     StoredProcedureRequestOptions requestOptions = null,
     CancellationToken cancellationToken          = default(CancellationToken));