/// <summary> /// Used internally by friends ensure robust argument and /// exception-less handling /// </summary> internal static Task <T> ProcessResourceOperationAsync <T>( CosmosClient client, Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher, Func <CosmosResponseMessage, T> responseCreator, CancellationToken cancellationToken) { return(ProcessResourceOperationAsync( requestHandler: client.RequestHandler, resourceUri: resourceUri, resourceType: resourceType, operationType: operationType, requestOptions: requestOptions, cosmosContainerCore: null, partitionKey: partitionKey, streamPayload: streamPayload, requestEnricher: requestEnricher, responseCreator: responseCreator, cancellationToken: cancellationToken)); }
private Task <CosmosResponseMessage> ItemStreamFeedRequestExecutor( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { Uri resourceUri = this.container.LinkUri; return(ExecUtils.ProcessResourceOperationAsync <CosmosResponseMessage>( client: this.container.Database.Client, resourceUri: resourceUri, resourceType: ResourceType.Document, operationType: OperationType.ReadFeed, requestOptions: options, requestEnricher: request => { CosmosQueryRequestOptions.FillContinuationToken(request, continuationToken); CosmosQueryRequestOptions.FillMaxItemCount(request, maxItemCount); }, responseCreator: response => response, partitionKey: null, streamPayload: null, cancellationToken: cancellationToken)); }
/// <summary> /// Used internally by friends ensrue robust argument and /// exception-less handling, with container information /// </summary> internal static Task <T> ProcessResourceOperationAsync <T>( CosmosClient client, Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, CosmosContainerCore cosmosContainerCore, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher, Func <CosmosResponseMessage, T> responseCreator, CancellationToken cancellationToken) { if (client == null) { throw new ArgumentNullException(nameof(client)); } return(ExecUtils.ProcessResourceOperationAsync( requestHandler: client.RequestHandler, resourceUri: resourceUri, resourceType: resourceType, operationType: operationType, requestOptions: requestOptions, cosmosContainerCore: cosmosContainerCore, partitionKey: partitionKey, streamPayload: streamPayload, requestEnricher: requestEnricher, responseCreator: responseCreator, cancellationToken: cancellationToken)); }
internal async Task <CosmosQueryResponse <T> > NextResultSetAsync <T>( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { CosmosQueryRequestOptions cosmosQueryRequestOptions = options as CosmosQueryRequestOptions ?? new CosmosQueryRequestOptions(); FeedOptions feedOptions = cosmosQueryRequestOptions.ToFeedOptions(); feedOptions.RequestContinuation = continuationToken; feedOptions.MaxItemCount = maxItemCount; IDocumentQuery <T> documentClientResult = this.client.DocumentClient.CreateDocumentQuery <T>( collectionLink: this.container.LinkUri.OriginalString, feedOptions: feedOptions, querySpec: state as SqlQuerySpec).AsDocumentQuery(); try { FeedResponse <T> feedResponse = await documentClientResult.ExecuteNextAsync <T>(cancellationToken); return(CosmosQueryResponse <T> .CreateResponse <T>(feedResponse, feedResponse.ResponseContinuation, documentClientResult.HasMoreResults)); } catch (DocumentClientException exception) { throw new CosmosException( message: exception.Message, statusCode: exception.StatusCode.HasValue ? exception.StatusCode.Value : HttpStatusCode.InternalServerError, subStatusCode: (int)exception.GetSubStatus(), activityId: exception.ActivityId, requestCharge: exception.RequestCharge); } }
private static CosmosRequestMessage GenerateCosmosRequestMessage( Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher) { HttpMethod method = ExecUtils.GetHttpMethod(operationType); CosmosRequestMessage request = new CosmosRequestMessage(method, resourceUri); request.OperationType = operationType; request.ResourceType = resourceType; request.RequestOptions = requestOptions; request.Content = streamPayload; if (partitionKey != null) { PartitionKey pk = new PartitionKey(partitionKey); request.Headers.PartitionKey = pk.InternalKey.ToJsonString(); } if (operationType == OperationType.Upsert) { request.Headers.IsUpsert = bool.TrueString; } requestEnricher?.Invoke(request); return(request); }
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)); }
private Task <CosmosQueryResponse <CosmosUserDefinedFunctionSettings> > ContainerFeedRequestExecutor( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { Debug.Assert(state == null); return(this.clientContext.ProcessResourceOperationAsync <CosmosQueryResponse <CosmosUserDefinedFunctionSettings> >( resourceUri: this.container.LinkUri, resourceType: ResourceType.UserDefinedFunction, operationType: OperationType.ReadFeed, requestOptions: options, cosmosContainerCore: null, partitionKey: null, streamPayload: null, requestEnricher: request => { CosmosQueryRequestOptions.FillContinuationToken(request, continuationToken); CosmosQueryRequestOptions.FillMaxItemCount(request, maxItemCount); }, responseCreator: response => this.clientContext.ResponseFactory.CreateResultSetQueryResponse <CosmosUserDefinedFunctionSettings>(response), cancellationToken: cancellationToken)); }
private Task <CosmosQueryResponse <CosmosDatabaseSettings> > DatabaseFeedRequestExecutor( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { Debug.Assert(state == null); Uri resourceUri = new Uri(Paths.Databases_Root, UriKind.Relative); return(this.clientContext.ProcessResourceOperationAsync <CosmosQueryResponse <CosmosDatabaseSettings> >( resourceUri: resourceUri, resourceType: ResourceType.Database, operationType: OperationType.ReadFeed, requestOptions: options, cosmosContainerCore: null, partitionKey: null, streamPayload: null, requestEnricher: request => { CosmosQueryRequestOptions.FillContinuationToken(request, continuationToken); CosmosQueryRequestOptions.FillMaxItemCount(request, maxItemCount); }, responseCreator: response => this.clientContext.ResponseFactory.CreateResultSetQueryResponse <CosmosDatabaseSettings>(response), cancellationToken: cancellationToken)); }
/// <summary> /// Creates a stored procedure as an asynchronous operation in the Azure Cosmos DB service. /// </summary> /// <param name="id">The cosmos stored procedure id</param> /// <param name="body">The JavaScript function that is the body of the stored procedure</param> /// <param name="requestOptions">(Optional) The options for the stored procedure request <see cref="CosmosRequestOptions"/></param> /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param> /// <returns>The <see cref="CosmosStoredProcedureSettings"/> that was created contained within a <see cref="Task"/> object representing the service response for the asynchronous operation.</returns> /// <exception cref="ArgumentNullException">If either <paramref name="id"/> or <paramref name="body"/> 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 Document 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 stored procedure or the Body was malformed.</description> /// </item> /// <item> /// <term>403</term><description>Forbidden - You have reached your quota of stored procedures for the collection supplied. Contact support to have this quota increased.</description> /// </item> /// <item> /// <term>409</term><description>Conflict - This means a <see cref="CosmosStoredProcedureSettings"/> 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="CosmosStoredProcedureSettings"/> you tried to create was too large.</description> /// </item> /// </list> /// </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.""); /// }"; /// /// CosmosStoredProcedure cosmosStoredProcedure = await this.container.StoredProcedures.CreateStoredProcedureAsync( /// 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 virtual Task <CosmosStoredProcedureResponse> CreateStoredProcedureAsync( string id, string body, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } if (string.IsNullOrEmpty(body)) { throw new ArgumentNullException(nameof(body)); } CosmosStoredProcedureSettings storedProcedureSettings = new CosmosStoredProcedureSettings(); storedProcedureSettings.Id = id; storedProcedureSettings.Body = body; Task <CosmosResponseMessage> response = ExecUtils.ProcessResourceOperationStreamAsync( this.container.Database.Client, this.container.LinkUri, ResourceType.StoredProcedure, OperationType.Create, requestOptions, partitionKey: null, streamPayload: storedProcedureSettings.GetResourceStream(), requestEnricher: null, cancellationToken: cancellationToken); return(this.client.ResponseFactory.CreateStoredProcedureResponse(this[id], response)); }
public override async Task <CosmosDatabaseResponse> CreateDatabaseIfNotExistsAsync( string id, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { // Doing a Read before Create will give us better latency for existing databases CosmosDatabase database = this[id]; CosmosDatabaseResponse cosmosDatabaseResponse = await database.ReadAsync(cancellationToken : cancellationToken); if (cosmosDatabaseResponse.StatusCode != HttpStatusCode.NotFound) { return(cosmosDatabaseResponse); } cosmosDatabaseResponse = await this.CreateDatabaseAsync(id, throughput, requestOptions, cancellationToken : cancellationToken); if (cosmosDatabaseResponse.StatusCode != HttpStatusCode.Conflict) { return(cosmosDatabaseResponse); } // This second Read is to handle the race condition when 2 or more threads have Read the database and only one succeeds with Create // so for the remaining ones we should do a Read instead of throwing Conflict exception return(await database.ReadAsync(cancellationToken : cancellationToken)); }
internal static Task <T> ProcessResourceOperationAsync <T>( CosmosClient client, Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher, Func <CosmosResponseMessage, T> responseCreator, CancellationToken cancellationToken) { CosmosRequestMessage request = ExecUtils.GenerateCosmosRequestMessage( client, resourceUri, resourceType, operationType, requestOptions, partitionKey, streamPayload, requestEnricher); return(client.RequestHandler.SendAsync(request, cancellationToken) .ContinueWith(task => responseCreator(task.Result), cancellationToken)); }
private Task <CosmosQueryResponse <CosmosDatabaseSettings> > DatabaseFeedRequestExecutor( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { Debug.Assert(state == null); Uri resourceUri = new Uri(Paths.Databases_Root, UriKind.Relative); return(ExecUtils.ProcessResourceOperationAsync <CosmosQueryResponse <CosmosDatabaseSettings> >( this.client, resourceUri, ResourceType.Database, OperationType.ReadFeed, options, request => { CosmosQueryRequestOptions.FillContinuationToken(request, continuationToken); CosmosQueryRequestOptions.FillMaxItemCount(request, maxItemCount); }, response => this.client.ResponseFactory.CreateResultSetQueryResponse <CosmosDatabaseSettings>(response), cancellationToken)); }
internal async Task <CosmosQueryResponse <T> > NextResultSetAsync <T>( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { IDocumentQueryExecutionContext documentQueryExecution = (IDocumentQueryExecutionContext)state; try { FeedResponse <CosmosElement> feedResponse = await documentQueryExecution.ExecuteNextAsync(cancellationToken); return(CosmosQueryResponse <T> .CreateResponse <T>( feedResponse : feedResponse, jsonSerializer : this.clientContext.JsonSerializer, hasMoreResults : !documentQueryExecution.IsDone, resourceType : ResourceType.Document)); } catch (DocumentClientException exception) { throw new CosmosException( message: exception.Message, statusCode: exception.StatusCode.HasValue ? exception.StatusCode.Value : HttpStatusCode.InternalServerError, subStatusCode: (int)exception.GetSubStatus(), activityId: exception.ActivityId, requestCharge: exception.RequestCharge); } }
private Task <CosmosQueryResponse <T> > ItemFeedRequestExecutor <T>( int?maxItemCount, string continuationToken, CosmosRequestOptions options, object state, CancellationToken cancellationToken) { Uri resourceUri = this.container.LinkUri; return(this.clientContext.ProcessResourceOperationAsync <CosmosQueryResponse <T> >( resourceUri: resourceUri, resourceType: ResourceType.Document, operationType: OperationType.ReadFeed, requestOptions: options, requestEnricher: request => { CosmosQueryRequestOptions.FillContinuationToken(request, continuationToken); CosmosQueryRequestOptions.FillMaxItemCount(request, maxItemCount); }, responseCreator: response => this.clientContext.ResponseFactory.CreateResultSetQueryResponse <T>(response), cosmosContainerCore: this.container, partitionKey: null, streamPayload: null, cancellationToken: cancellationToken)); }
public override Task <CosmosStoredProcedureResponse> CreateStoredProcedureAsync( string id, string body, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } if (string.IsNullOrEmpty(body)) { throw new ArgumentNullException(nameof(body)); } CosmosStoredProcedureSettings storedProcedureSettings = new CosmosStoredProcedureSettings { Id = id, Body = body }; Task <CosmosResponseMessage> response = this.clientContext.ProcessResourceOperationStreamAsync( resourceUri: this.container.LinkUri, resourceType: ResourceType.StoredProcedure, operationType: OperationType.Create, requestOptions: requestOptions, cosmosContainerCore: this.container, partitionKey: null, streamPayload: CosmosResource.ToStream(storedProcedureSettings), requestEnricher: null, cancellationToken: cancellationToken); return(this.clientContext.ResponseFactory.CreateStoredProcedureResponse(this[id], response)); }
internal override Task <T> ProcessResourceOperationAsync <T>( Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, CosmosContainerCore cosmosContainerCore, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher, Func <CosmosResponseMessage, T> responseCreator, CancellationToken cancellationToken) { return(ExecUtils.ProcessResourceOperationAsync <T>( requestHandler: this.RequestHandler, resourceUri: resourceUri, resourceType: resourceType, operationType: operationType, requestOptions: requestOptions, cosmosContainerCore: cosmosContainerCore, partitionKey: partitionKey, streamPayload: streamPayload, requestEnricher: requestEnricher, responseCreator: responseCreator, cancellationToken: cancellationToken)); }
public override async Task <CosmosContainerResponse> CreateContainerIfNotExistsAsync( CosmosContainerSettings containerSettings, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { if (containerSettings == null) { throw new ArgumentNullException(nameof(containerSettings)); } this.ValidateContainerSettings(containerSettings); CosmosContainer cosmosContainer = this[containerSettings.Id]; CosmosContainerResponse cosmosContainerResponse = await cosmosContainer.ReadAsync(cancellationToken : cancellationToken); if (cosmosContainerResponse.StatusCode != HttpStatusCode.NotFound) { return(cosmosContainerResponse); } cosmosContainerResponse = await this.CreateContainerAsync(containerSettings, throughput, requestOptions, cancellationToken : cancellationToken); if (cosmosContainerResponse.StatusCode != HttpStatusCode.Conflict) { return(cosmosContainerResponse); } // This second Read is to handle the race condition when 2 or more threads have Read the database and only one succeeds with Create // so for the remaining ones we should do a Read instead of throwing Conflict exception return(await cosmosContainer.ReadAsync(cancellationToken : cancellationToken)); }
/// <summary> /// Delete a <see cref="CosmosDatabaseSettings"/> from the Azure Cosmos DB service as an asynchronous operation. /// </summary> /// <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> internal virtual Task <CosmosResponseMessage> DeleteStreamAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( OperationType.Delete, requestOptions, cancellationToken)); }
/// <summary> /// Reads a <see cref="CosmosDatabaseSettings"/> from the Azure Cosmos service as an asynchronous operation. /// </summary> /// <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="CosmosDatabaseResponse"/> which wraps a <see cref="CosmosDatabaseSettings"/> containing the read 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> /// <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.</description> /// </item> /// </list> /// </exception> /// <example> /// <code language="c#"> /// <![CDATA[ /// //Reads a Database resource where /// // - database_id is the ID property of the Database resource you wish to read. /// CosmosDatabase database = this.cosmosClient.Databases[database_id]; /// CosmosDatabaseResponse response = await database.ReadAsync(); /// ]]> /// </code> /// </example> /// <remarks> /// <para> /// Doing a read of a resource is the most efficient way to get a resource from the Database. If you know the resource's ID, do a read instead of a query by ID. /// </para> /// </remarks> public virtual Task <CosmosDatabaseResponse> ReadAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(ProcessAsync( OperationType.Read, requestOptions, cancellationToken)); }
public override Task <CosmosResponseMessage> ReadStreamAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( OperationType.Read, requestOptions, cancellationToken)); }
/// <summary> /// This is a wrapper around ExecUtil method. This allows the calls to be mocked so logic done /// in a resource can be unit tested. /// </summary> internal abstract Task <CosmosResponseMessage> ProcessResourceOperationStreamAsync( Uri resourceUri, ResourceType resourceType, OperationType operationType, CosmosRequestOptions requestOptions, CosmosContainerCore cosmosContainerCore, Object partitionKey, Stream streamPayload, Action <CosmosRequestMessage> requestEnricher, CancellationToken cancellationToken);
public override Task <CosmosDatabaseResponse> DeleteAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { Task <CosmosResponseMessage> response = this.DeleteStreamAsync( requestOptions: requestOptions, cancellationToken: cancellationToken); return(this.clientContext.ResponseFactory.CreateDatabaseResponse(this, response)); }
/// <summary> /// Reads a <see cref="CosmosDatabaseSettings"/> from the Azure Cosmos service as an asynchronous operation. /// </summary> /// <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="CosmosDatabaseResponse"/> which wraps a <see cref="CosmosDatabaseSettings"/> containing the read 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> /// <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.</description> /// </item> /// </list> /// </exception> /// <example> /// <code language="c#"> /// <![CDATA[ /// //Reads a Database resource where /// // - database_id is the ID property of the Database resource you wish to read. /// CosmosDatabase database = this.cosmosClient.Databases[database_id]; /// CosmosDatabaseResponse response = await database.ReadAsync(); /// ]]> /// </code> /// </example> /// <remarks> /// <para> /// Doing a read of a resource is the most efficient way to get a resource from the Database. If you know the resource's ID, do a read instead of a query by ID. /// </para> /// </remarks> public virtual Task <CosmosDatabaseResponse> ReadAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { Task <CosmosResponseMessage> response = this.ReadStreamAsync( requestOptions: requestOptions, cancellationToken: cancellationToken); return(this.Client.ResponseFactory.CreateDatabaseResponse(this, response)); }
/// <summary> /// Delete a <see cref="CosmosUserDefinedFunctionSettings"/> from the Azure Cosmos DB service as an asynchronous operation. /// </summary> /// <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"/> which will contain information about the request issued.</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 gets a reference to an existing user defined function and deletes it. /// <code language="c#"> /// <![CDATA[ /// CosmosUserDefinedFunctionResponse response = await this.cosmosContainer.UserDefinedFunctions["taxUdfId"].DeleteAsync(); /// ]]> /// </code> /// </example> /// <example> /// This examples containers an existing reference to a user defined function and deletes it. /// <code language="c#"> /// <![CDATA[ /// CosmosUserDefinedFunctionResponse response = await this.cosmosTaxUdf.DeleteAsync(); /// ]]> /// </code> /// </example> public virtual Task <CosmosUserDefinedFunctionResponse> DeleteAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( partitionKey: null, streamPayload: null, operationType: OperationType.Delete, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
/// <summary> /// Reads a <see cref="CosmosTriggerSettings"/> from the Azure Cosmos service as an asynchronous operation. /// </summary> /// <param name="requestOptions">(Optional) The options for the trigger 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="CosmosTriggerResponse"/> which wraps a <see cref="CosmosTriggerSettings"/> containing the read 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> /// This reads an existing trigger /// <code language="c#"> /// <![CDATA[ /// CosmosTriggerResponse response = await cosmosContainer.Triggers["ExistingId"].ReadAsync(); /// CosmosTriggerSettings settings = response; /// ]]> /// </code> /// </example> public virtual Task <CosmosTriggerResponse> ReadAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( partitionKey: null, streamPayload: null, operationType: OperationType.Read, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
public override Task <CosmosStoredProcedureResponse> DeleteAsync( CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( partitionKey: null, streamPayload: null, operationType: OperationType.Delete, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
public override Task <CosmosContainerResponse> CreateContainerIfNotExistsAsync( string id, string partitionKeyPath, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { CosmosContainerSettings settings = new CosmosContainerSettings(id, partitionKeyPath); return(this.CreateContainerIfNotExistsAsync(settings, throughput, requestOptions, cancellationToken)); }
/// <summary> /// Replaces a <see cref="CosmosTriggerSettings"/> in the Azure Cosmos service as an asynchronous operation. /// </summary> /// <param name="triggerSettings">The <see cref="CosmosTriggerSettings"/> object.</param> /// <param name="requestOptions">(Optional) The options for the trigger 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="CosmosTriggerResponse"/> which wraps a <see cref="CosmosTriggerSettings"/> containing the updated resource record. /// </returns> /// <exception cref="ArgumentNullException">If <paramref name="triggerSettings"/> is not set.</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 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 trigger. /// <code language="c#"> /// <![CDATA[ /// //Updated settings /// CosmosTriggerSettings settings = new CosmosTriggerSettings /// { /// Id = "testTriggerId", /// Body = @"function AddTax() { /// var item = getContext().getRequest().getBody(); /// /// // Validate/calculate the tax. /// item.tax = item.cost* .15; /// /// // Update the request -- this is what is going to be inserted. /// getContext().getRequest().setBody(item); /// }", /// TriggerOperation = TriggerOperation.All, /// TriggerType = TriggerType.Post /// }; /// /// CosmosTriggerResponse response = await this.cosmosTrigger.ReplaceAsync(settings); /// ]]> /// </code> /// </example> public virtual Task <CosmosTriggerResponse> ReplaceAsync( CosmosTriggerSettings triggerSettings, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessAsync( partitionKey: null, streamPayload: CosmosResource.ToStream(triggerSettings), operationType: OperationType.Replace, requestOptions: requestOptions, cancellationToken: cancellationToken)); }
/// <summary> /// Fill the CosmosRequestMessage headers with the set properties /// </summary> /// <param name="request">The <see cref="CosmosRequestMessage"/></param> public override void FillRequestOptions(CosmosRequestMessage request) { if (this.EnableScriptLogging) { request.Headers.Add(HttpConstants.HttpHeaders.EnableLogging, bool.TrueString); } CosmosRequestOptions.SetSessionToken(request, this.SessionToken); CosmosRequestOptions.SetConsistencyLevel(request, this.ConsistencyLevel); base.FillRequestOptions(request); }
public override Task <CosmosResponseMessage> CreateContainerStreamAsync( Stream streamPayload, int?throughput = null, CosmosRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(this.ProcessCollectionCreateAsync( streamPayload: streamPayload, throughput: throughput, requestOptions: requestOptions, cancellationToken: cancellationToken)); }