Exemplo n.º 1
0
 internal CosmosStoredProceduresCore(
     CosmosClientContext clientContext,
     CosmosContainerCore container)
 {
     this.container     = container;
     this.clientContext = clientContext;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a <see cref="CosmosUserDefinedFunctions"/>
 /// </summary>
 /// <param name="clientContext">The client context.</param>
 /// <param name="container">The <see cref="CosmosContainer"/> the user defined function set is related to.</param>
 protected internal CosmosUserDefinedFunctions(
     CosmosClientContext clientContext,
     CosmosContainerCore container)
 {
     this.container     = container;
     this.clientContext = clientContext;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a <see cref="CosmosTriggers"/>
 /// </summary>
 /// <param name="clientContext">The client context</param>
 /// <param name="container">The <see cref="CosmosContainer"/> the triggers set is related to.</param>
 protected internal CosmosTriggers(
     CosmosClientContext clientContext,
     CosmosContainerCore container)
 {
     this.container     = container;
     this.clientContext = clientContext;
 }
 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));
 }
Exemplo n.º 5
0
        /// <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,
            RequestOptions 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));
        }
Exemplo n.º 6
0
        internal async Task <CosmosResponseMessage> ProcessItemStreamAsync(
            PartitionKey partitionKey,
            string itemId,
            Stream streamPayload,
            OperationType operationType,
            RequestOptions requestOptions,
            bool extractPartitionKeyIfNeeded,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (extractPartitionKeyIfNeeded && partitionKey == null)
            {
                partitionKey = await this.GetPartitionKeyValueFromStreamAsync(streamPayload, cancellationToken);
            }

            CosmosContainerCore.ValidatePartitionKey(partitionKey, requestOptions);
            Uri resourceUri = this.GetResourceUri(requestOptions, operationType, itemId);

            return(await this.ClientContext.ProcessResourceOperationStreamAsync(
                       resourceUri,
                       ResourceType.Document,
                       operationType,
                       requestOptions,
                       this,
                       partitionKey,
                       streamPayload,
                       null,
                       cancellationToken));
        }
Exemplo n.º 7
0
        internal ChangeFeedPartitionKeyResultSetIteratorCore(
            CosmosClientContext clientContext,
            CosmosContainerCore cosmosContainer,
            string partitionKeyRangeId,
            string continuationToken,
            int?maxItemCount,
            ChangeFeedRequestOptions options)
        {
            if (cosmosContainer == null)
            {
                throw new ArgumentNullException(nameof(cosmosContainer));
            }

            if (partitionKeyRangeId == null)
            {
                throw new ArgumentNullException(nameof(partitionKeyRangeId));
            }

            this.clientContext       = clientContext;
            this.cosmosContainer     = cosmosContainer;
            this.changeFeedOptions   = options;
            this.MaxItemCount        = maxItemCount;
            this.continuationToken   = continuationToken;
            this.partitionKeyRangeId = partitionKeyRangeId;
        }
 internal CosmosQueryClientCore(
     CosmosClientContext clientContext,
     CosmosContainerCore cosmosContainerCore)
 {
     this.clientContext       = clientContext ?? throw new ArgumentException(nameof(clientContext));
     this.cosmosContainerCore = cosmosContainerCore ?? throw new ArgumentException(nameof(cosmosContainerCore));
     this.DocumentQueryClient = clientContext.DocumentQueryClient ?? throw new ArgumentException(nameof(clientContext));
 }
 internal CosmosItemsCore(
     CosmosClientContext clientContext,
     CosmosContainerCore container,
     CosmosQueryClient queryClient = null)
 {
     this.clientContext             = clientContext;
     this.container                 = container;
     this.cachedUriSegmentWithoutId = this.GetResourceSegmentUriWithoutId();
     this.queryClient               = queryClient ?? new CosmosQueryClientCore(this.clientContext, container);
 }
 /// <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,
     RequestOptions requestOptions,
     CosmosContainerCore cosmosContainerCore,
     PartitionKey partitionKey,
     Stream streamPayload,
     Action <CosmosRequestMessage> requestEnricher,
     CancellationToken cancellationToken);
Exemplo n.º 11
0
 /// <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 <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);
 internal CosmosStoredProcedureCore(
     CosmosClientContext clientContext,
     CosmosContainerCore container,
     string storedProcedureId)
 {
     this.clientContext = clientContext;
     this.Id            = storedProcedureId;
     this.LinkUri       = clientContext.CreateLink(
         parentLink: container.LinkUri.OriginalString,
         uriPathSegment: Paths.StoredProceduresPathSegment,
         id: storedProcedureId);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create a <see cref="CosmosUserDefinedFunction"/>
 /// </summary>
 /// <param name="clientContext">The client context</param>
 /// <param name="container">The <see cref="CosmosContainer"/></param>
 /// <param name="userDefinedFunctionId">The cosmos user defined function id.</param>
 /// <remarks>
 /// Note that the user defined function must be explicitly created, if it does not already exist, before
 /// you can read from it or write to it.
 /// </remarks>
 protected internal CosmosUserDefinedFunction(
     CosmosClientContext clientContext,
     CosmosContainerCore container,
     string userDefinedFunctionId)
 {
     this.Id            = userDefinedFunctionId;
     this.clientContext = clientContext;
     this.container     = container;
     this.LinkUri       = this.clientContext.CreateLink(
         parentLink: container.LinkUri.OriginalString,
         uriPathSegment: Paths.UserDefinedFunctionsPathSegment,
         id: userDefinedFunctionId);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Create a <see cref="CosmosTrigger"/>
 /// </summary>
 /// <param name="clientContext">The client context</param>
 /// <param name="container">The <see cref="CosmosContainer"/></param>
 /// <param name="triggerId">The cosmos trigger id.</param>
 /// <remarks>
 /// Note that the trigger must be explicitly created, if it does not already exist, before
 /// you can read from it or write to it.
 /// </remarks>
 protected internal CosmosTrigger(
     CosmosClientContext clientContext,
     CosmosContainerCore container,
     string triggerId)
 {
     this.Id            = triggerId;
     this.clientContext = clientContext;
     this.container     = container;
     this.LinkUri       = this.clientContext.CreateLink(
         parentLink: container.LinkUri.OriginalString,
         uriPathSegment: Paths.TriggersPathSegment,
         id: triggerId);
 }
Exemplo n.º 15
0
        private static async Task <CosmosRequestMessage> GenerateCosmosRequestMessage(
            Uri resourceUri,
            ResourceType resourceType,
            OperationType operationType,
            CosmosRequestOptions requestOptions,
            CosmosContainerCore cosmosContainerCore,
            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)
            {
                if (cosmosContainerCore == null && partitionKey.Equals(PartitionKey.None))
                {
                    throw new ArgumentException($"{nameof(cosmosContainerCore)} can not be null with partition key as PartitionKey.None");
                }
                else if (partitionKey.Equals(PartitionKey.None))
                {
                    PartitionKeyInternal partitionKeyInternal = await cosmosContainerCore.GetNonePartitionKeyValue();

                    request.Headers.PartitionKey = partitionKeyInternal.ToJsonString();
                }
                else
                {
                    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);
        }
Exemplo n.º 16
0
        public CosmosConflictsCore(
            CosmosClientContext clientContext,
            CosmosContainerCore container)
        {
            if (clientContext == null)
            {
                throw new ArgumentNullException(nameof(clientContext));
            }

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            this.container     = container;
            this.clientContext = clientContext;
        }
Exemplo n.º 17
0
 internal ChangeFeedProcessorBuilder(
     string workflowName,
     CosmosContainerCore cosmosContainer,
     ChangeFeedProcessor changeFeedProcessor,
     Action <DocumentServiceLeaseStoreManager,
             CosmosContainerCore,
             string,
             string,
             ChangeFeedLeaseOptions,
             ChangeFeedProcessorOptions,
             CosmosContainerCore> applyBuilderConfiguration)
 {
     this.changeFeedLeaseOptions             = new ChangeFeedLeaseOptions();
     this.changeFeedLeaseOptions.LeasePrefix = workflowName;
     this.monitoredContainer        = cosmosContainer;
     this.changeFeedProcessor       = changeFeedProcessor;
     this.applyBuilderConfiguration = applyBuilderConfiguration;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Sets the Cosmos Container to hold the leases state
        /// </summary>
        /// <param name="leaseContainer">Instance of a Cosmos Container to hold the leases.</param>
        /// <returns></returns>
        public virtual ChangeFeedProcessorBuilder WithCosmosLeaseContainer(CosmosContainer leaseContainer)
        {
            if (leaseContainer == null)
            {
                throw new ArgumentNullException(nameof(leaseContainer));
            }
            if (this.leaseContainer != null)
            {
                throw new InvalidOperationException("The builder already defined a lease container.");
            }
            if (this.LeaseStoreManager != null)
            {
                throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");
            }

            this.leaseContainer = (CosmosContainerCore)leaseContainer;
            return(this);
        }
        internal CosmosChangeFeedResultSetIteratorCore(
            CosmosContainerCore cosmosContainer,
            string continuationToken,
            int?maxItemCount,
            CosmosChangeFeedRequestOptions options)
        {
            if (cosmosContainer == null)
            {
                throw new ArgumentNullException(nameof(cosmosContainer));
            }

            this.cosmosContainer      = cosmosContainer;
            this.changeFeedOptions    = options;
            this.maxItemCount         = maxItemCount;
            this.originalMaxItemCount = maxItemCount;
            this.continuationToken    = continuationToken;
            this.HasMoreResults       = true;
        }
Exemplo n.º 20
0
        internal static async Task <T> ProcessResourceOperationAsync <T>(
            CosmosRequestHandler requestHandler,
            Uri resourceUri,
            ResourceType resourceType,
            OperationType operationType,
            CosmosRequestOptions requestOptions,
            CosmosContainerCore cosmosContainerCore,
            Object partitionKey,
            Stream streamPayload,
            Action <CosmosRequestMessage> requestEnricher,
            Func <CosmosResponseMessage, T> responseCreator,
            CancellationToken cancellationToken)
        {
            if (requestHandler == null)
            {
                throw new ArgumentException(nameof(requestHandler));
            }

            if (resourceUri == null)
            {
                throw new ArgumentNullException(nameof(resourceUri));
            }

            if (responseCreator == null)
            {
                throw new ArgumentNullException(nameof(responseCreator));
            }

            CosmosRequestMessage request = await ExecUtils.GenerateCosmosRequestMessage(
                resourceUri,
                resourceType,
                operationType,
                requestOptions,
                cosmosContainerCore,
                partitionKey,
                streamPayload,
                requestEnricher);

            CosmosResponseMessage response = await requestHandler.SendAsync(request, cancellationToken);

            return(responseCreator(response));
        }
        internal Task <CosmosResponseMessage> ProcessItemAsStreamAsync(
            object partitionKey,
            string itemId,
            Stream streamPayload,
            OperationType operationType,
            RequestOptions requestOptions,
            CancellationToken cancellationToken)
        {
            CosmosContainerCore.ValidatePartitionKey(partitionKey, requestOptions);
            Uri resourceUri = this.GetResourceUri(requestOptions, operationType, itemId);

            return(this.ClientContext.ProcessResourceOperationAsStreamAsync(
                       resourceUri,
                       ResourceType.Document,
                       operationType,
                       requestOptions,
                       this,
                       partitionKey,
                       streamPayload,
                       null,
                       cancellationToken));
        }
Exemplo n.º 22
0
 internal override Task <CosmosResponseMessage> ProcessResourceOperationStreamAsync(
     Uri resourceUri,
     ResourceType resourceType,
     OperationType operationType,
     RequestOptions requestOptions,
     CosmosContainerCore cosmosContainerCore,
     PartitionKey partitionKey,
     Stream streamPayload,
     Action <CosmosRequestMessage> requestEnricher,
     CancellationToken cancellationToken)
 {
     return(this.RequestHandler.SendAsync(
                resourceUri: resourceUri,
                resourceType: resourceType,
                operationType: operationType,
                requestOptions: requestOptions,
                cosmosContainerCore: cosmosContainerCore,
                partitionKey: partitionKey,
                streamPayload: streamPayload,
                requestEnricher: requestEnricher,
                cancellationToken: cancellationToken));
 }
Exemplo n.º 23
0
        internal static async Task <CosmosResponseMessage> ProcessResourceOperationStreamAsync(
            CosmosRequestHandler requestHandler,
            Uri resourceUri,
            ResourceType resourceType,
            OperationType operationType,
            CosmosRequestOptions requestOptions,
            CosmosContainerCore cosmosContainerCore,
            Object partitionKey,
            Stream streamPayload,
            Action <CosmosRequestMessage> requestEnricher,
            CancellationToken cancellationToken)
        {
            CosmosRequestMessage request = await ExecUtils.GenerateCosmosRequestMessage(
                resourceUri,
                resourceType,
                operationType,
                requestOptions,
                cosmosContainerCore,
                partitionKey,
                streamPayload,
                requestEnricher);

            return(await requestHandler.SendAsync(request, cancellationToken));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Create a <see cref="CosmosTriggers"/>
 /// </summary>
 /// <param name="container">The <see cref="CosmosContainer"/> the triggers set is related to.</param>
 protected internal CosmosTriggers(CosmosContainerCore container)
 {
     this.container = container;
     this.client    = container.Client;
 }