Ejemplo n.º 1
0
        internal ChangeFeedPartitionKeyResultSetIteratorCore(
            CosmosClientContext clientContext,
            ContainerCore container,
            string partitionKeyRangeId,
            string continuationToken,
            int?maxItemCount,
            ChangeFeedRequestOptions options)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

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

            this.clientContext       = clientContext;
            this.container           = container;
            this.changeFeedOptions   = options;
            this.MaxItemCount        = maxItemCount;
            this.continuationToken   = continuationToken;
            this.partitionKeyRangeId = partitionKeyRangeId;
        }
        internal void Init(
            CosmosClientOptions clientOptions,
            DocumentClient documentClient)
        {
            this.ClientOptions  = clientOptions;
            this.DocumentClient = documentClient;

            //Request pipeline
            ClientPipelineBuilder clientPipelineBuilder = new ClientPipelineBuilder(
                this,
                this.DocumentClient.ResetSessionTokenRetryPolicy,
                this.ClientOptions.CustomHandlers);

            // DocumentClient is not initialized with any consistency overrides so default is backend consistency
            this.AccountConsistencyLevel = (ConsistencyLevel)this.DocumentClient.ConsistencyLevel;

            this.RequestHandler = clientPipelineBuilder.Build();

            this.ResponseFactory = new CosmosResponseFactory(
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                userJsonSerializer: this.ClientOptions.CosmosSerializerWithWrapperOrDefault);

            this.ClientContext = new ClientContextCore(
                client: this,
                clientOptions: this.ClientOptions,
                userJsonSerializer: this.ClientOptions.CosmosSerializerWithWrapperOrDefault,
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                cosmosResponseFactory: this.ResponseFactory,
                requestHandler: this.RequestHandler,
                documentClient: this.DocumentClient,
                documentQueryClient: new DocumentQueryClient(this.DocumentClient));

            this.offerSet = new Lazy <CosmosOffers>(() => new CosmosOffers(this.DocumentClient), LazyThreadSafetyMode.PublicationOnly);
        }
        internal void Init(
            CosmosClientOptions clientOptions,
            DocumentClient documentClient)
        {
            this.ClientOptions  = clientOptions;
            this.DocumentClient = documentClient;

            //Request pipeline
            ClientPipelineBuilder clientPipelineBuilder = new ClientPipelineBuilder(
                this,
                this.ClientOptions.CustomHandlers);

            this.RequestHandler = clientPipelineBuilder.Build();

            CosmosSerializer userSerializer = this.ClientOptions.GetCosmosSerializerWithWrapperOrDefault();

            this.ResponseFactory = new CosmosResponseFactory(
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                userJsonSerializer: userSerializer);

            CosmosSerializer sqlQuerySpecSerializer = CosmosSqlQuerySpecJsonConverter.CreateSqlQuerySpecSerializer(
                cosmosSerializer: userSerializer,
                propertiesSerializer: this.ClientOptions.PropertiesSerializer);

            this.ClientContext = new ClientContextCore(
                client: this,
                clientOptions: this.ClientOptions,
                userJsonSerializer: userSerializer,
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                sqlQuerySpecSerializer: sqlQuerySpecSerializer,
                cosmosResponseFactory: this.ResponseFactory,
                requestHandler: this.RequestHandler,
                documentClient: this.DocumentClient);
        }
        internal void Init(
            CosmosClientOptions clientOptions,
            DocumentClient documentClient)
        {
            this.ClientOptions  = clientOptions;
            this.DocumentClient = documentClient;

            //Request pipeline
            ClientPipelineBuilder clientPipelineBuilder = new ClientPipelineBuilder(
                this,
                this.ClientOptions.CustomHandlers);

            this.RequestHandler = clientPipelineBuilder.Build();

            this.ResponseFactory = new CosmosResponseFactory(
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                userJsonSerializer: this.ClientOptions.CosmosSerializerWithWrapperOrDefault);

            this.ClientContext = new ClientContextCore(
                client: this,
                clientOptions: this.ClientOptions,
                userJsonSerializer: this.ClientOptions.CosmosSerializerWithWrapperOrDefault,
                defaultJsonSerializer: this.ClientOptions.PropertiesSerializer,
                cosmosResponseFactory: this.ResponseFactory,
                requestHandler: this.RequestHandler,
                documentClient: this.DocumentClient,
                documentQueryClient: new DocumentQueryClient(this.DocumentClient));

            this.offerSet = new Lazy <CosmosOffers>(() => new CosmosOffers(this.DocumentClient), LazyThreadSafetyMode.PublicationOnly);
        }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
        public BatchAsyncContainerExecutor(
            ContainerCore cosmosContainer,
            CosmosClientContext cosmosClientContext,
            int maxServerRequestOperationCount,
            int maxServerRequestBodyLength,
            int dispatchTimerInSeconds = BatchAsyncContainerExecutor.DefaultDispatchTimerInSeconds)
        {
            if (cosmosContainer == null)
            {
                throw new ArgumentNullException(nameof(cosmosContainer));
            }

            if (maxServerRequestOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxServerRequestOperationCount));
            }

            if (maxServerRequestBodyLength < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxServerRequestBodyLength));
            }

            if (dispatchTimerInSeconds < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(dispatchTimerInSeconds));
            }

            this.cosmosContainer                = cosmosContainer;
            this.cosmosClientContext            = cosmosClientContext;
            this.maxServerRequestBodyLength     = maxServerRequestBodyLength;
            this.maxServerRequestOperationCount = maxServerRequestOperationCount;
            this.dispatchTimerInSeconds         = dispatchTimerInSeconds;
            this.timerPool    = new TimerPool(BatchAsyncContainerExecutor.MinimumDispatchTimerInSeconds);
            this.retryOptions = cosmosClientContext.ClientOptions.GetConnectionPolicy().RetryOptions;
        }
        public ChangeFeedIteratorCore(
            ContainerInternal container,
            ChangeFeedRequestOptions changeFeedRequestOptions)
        {
            this.container         = container ?? throw new ArgumentNullException(nameof(container));
            this.clientContext     = container.ClientContext;
            this.changeFeedOptions = changeFeedRequestOptions ?? new ChangeFeedRequestOptions();
            this.lazyContainerRid  = new AsyncLazy <TryCatch <string> >(valueFactory: (innerCancellationToken) =>
            {
                return(this.TryInitializeContainerRIdAsync(innerCancellationToken));
            });
            this.hasMoreResults = true;

            if (this.changeFeedOptions?.From is ChangeFeedRequestOptions.StartFromContinuation startFromContinuation)
            {
                if (!FeedRangeContinuation.TryParse(startFromContinuation.Continuation, out FeedRangeContinuation feedRangeContinuation))
                {
                    throw new ArgumentException(string.Format(ClientResources.FeedToken_UnknownFormat, startFromContinuation.Continuation));
                }

                this.FeedRangeContinuation       = feedRangeContinuation;
                this.changeFeedOptions.FeedRange = feedRangeContinuation.GetFeedRange();
                string continuationToken = feedRangeContinuation.GetContinuation();
                if (continuationToken != null)
                {
                    this.changeFeedOptions.From = ChangeFeedRequestOptions.StartFrom.CreateFromContinuation(continuationToken);
                }
                else
                {
                    this.changeFeedOptions.From = ChangeFeedRequestOptions.StartFrom.CreateFromBeginning();
                }
            }
        }
        public BatchAsyncBatcher(
            int maxBatchOperationCount,
            int maxBatchByteSize,
            CosmosSerializerCore serializerCore,
            BatchAsyncBatcherExecuteDelegate executor,
            BatchAsyncBatcherRetryDelegate retrier,
            CosmosClientContext clientContext)
        {
            if (maxBatchOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchOperationCount));
            }

            if (maxBatchByteSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
            }

            this.batchOperations        = new List <ItemBatchOperation>(maxBatchOperationCount);
            this.executor               = executor ?? throw new ArgumentNullException(nameof(executor));
            this.retrier                = retrier ?? throw new ArgumentNullException(nameof(retrier));
            this.maxBatchByteSize       = maxBatchByteSize;
            this.maxBatchOperationCount = maxBatchOperationCount;
            this.serializerCore         = serializerCore ?? throw new ArgumentNullException(nameof(serializerCore));
            this.clientContext          = clientContext;
        }
Ejemplo n.º 9
0
 public static string CreateLinkUri(CosmosClientContext clientContext, DatabaseInternal database, string keyId)
 {
     return(clientContext.CreateLink(
                parentLink: database.LinkUri,
                uriPathSegment: Paths.ClientEncryptionKeysPathSegment,
                id: keyId));
 }
Ejemplo n.º 10
0
 internal CosmosStoredProceduresCore(
     CosmosClientContext clientContext,
     CosmosContainerCore container)
 {
     this.container     = container;
     this.clientContext = clientContext;
 }
 internal FeedIteratorInlineCore(
     FeedIteratorInternal feedIteratorInternal,
     CosmosClientContext clientContext)
 {
     this.feedIteratorInternal = feedIteratorInternal ?? throw new ArgumentNullException(nameof(feedIteratorInternal));
     this.clientContext        = clientContext;
 }
Ejemplo n.º 12
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;
 }
        public BatchAsyncContainerExecutor(
            ContainerInternal cosmosContainer,
            CosmosClientContext cosmosClientContext,
            int maxServerRequestOperationCount,
            int maxServerRequestBodyLength)
        {
            if (cosmosContainer == null)
            {
                throw new ArgumentNullException(nameof(cosmosContainer));
            }

            if (maxServerRequestOperationCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxServerRequestOperationCount));
            }

            if (maxServerRequestBodyLength < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxServerRequestBodyLength));
            }

            this.cosmosContainer                = cosmosContainer;
            this.cosmosClientContext            = cosmosClientContext;
            this.maxServerRequestBodyLength     = maxServerRequestBodyLength;
            this.maxServerRequestOperationCount = maxServerRequestOperationCount;
            this.timerWheel   = TimerWheel.CreateTimerWheel(BatchAsyncContainerExecutor.TimerWheelResolution, BatchAsyncContainerExecutor.TimerWheelBucketCount);
            this.retryOptions = cosmosClientContext.ClientOptions.GetConnectionPolicy().RetryOptions;
        }
Ejemplo n.º 14
0
 internal static Uri CreateLinkUri(CosmosClientContext clientContext, DatabaseCore database, string keyId)
 {
     return(clientContext.CreateLink(
                parentLink: database.LinkUri.OriginalString,
                uriPathSegment: Paths.ClientEncryptionKeysPathSegment,
                id: keyId));
 }
Ejemplo n.º 15
0
        public BatchAsyncContainerExecutor GetExecutorForContainer(
            ContainerInternal container,
            CosmosClientContext cosmosClientContext)
        {
            if (!cosmosClientContext.ClientOptions.AllowBulkExecution)
            {
                throw new InvalidOperationException("AllowBulkExecution is not currently enabled.");
            }

            string containerLink = container.LinkUri.ToString();

            if (this.executorsPerContainer.TryGetValue(containerLink, out BatchAsyncContainerExecutor executor))
            {
                return(executor);
            }

            BatchAsyncContainerExecutor newExecutor = new BatchAsyncContainerExecutor(
                container,
                cosmosClientContext,
                Constants.MaxOperationsInDirectModeBatchRequest,
                Constants.MaxDirectModeBatchRequestBodySizeInBytes);

            if (!this.executorsPerContainer.TryAdd(containerLink, newExecutor))
            {
                newExecutor.Dispose();
            }

            return(this.executorsPerContainer[containerLink]);
        }
Ejemplo n.º 16
0
 internal ConflictsInlineCore(
     CosmosClientContext clientContext,
     ContainerInternal container)
     : base(
         clientContext,
         container)
 {
 }
 public ReadManyQueryHelper(PartitionKeyDefinition partitionKeyDefinition,
                            ContainerCore container)
 {
     this.partitionKeyDefinition = partitionKeyDefinition;
     this.partitionKeySelectors  = this.CreatePkSelectors(partitionKeyDefinition);
     this.container     = container;
     this.clientContext = container.ClientContext;
 }
 internal CosmosContainersCore(
     CosmosClientContext clientContext,
     CosmosDatabaseCore database)
 {
     this.database       = database;
     this.clientContext  = clientContext;
     this.containerCache = new ConcurrentDictionary <string, CosmosContainer>();
 }
Ejemplo n.º 19
0
 internal CosmosQueryClientCore(
     CosmosClientContext clientContext,
     ContainerCore 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));
 }
Ejemplo n.º 20
0
 internal DatabaseInlineCore(
     CosmosClientContext clientContext,
     string databaseId)
     : base(
         clientContext,
         databaseId)
 {
 }
Ejemplo n.º 21
0
 public CosmosQueryClientCore(
     CosmosClientContext clientContext,
     ContainerInternal cosmosContainerCore)
 {
     this.clientContext       = clientContext ?? throw new ArgumentException(nameof(clientContext));
     this.cosmosContainerCore = cosmosContainerCore;
     this.documentClient      = this.clientContext.DocumentClient;
     this.semaphore           = new SemaphoreSlim(1, 1);
 }
Ejemplo n.º 22
0
 public ChangeFeedPartitionKeyResultSetIteratorCore(
     CosmosClientContext clientContext,
     ContainerInternal container,
     ChangeFeedRequestOptions options)
 {
     this.clientContext     = clientContext ?? throw new ArgumentNullException(nameof(clientContext));
     this.container         = container ?? throw new ArgumentNullException(nameof(container));
     this.changeFeedOptions = options;
 }
 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);
 }
 internal ClientEncryptionKeyInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string keyId)
     : base(
         clientContext,
         database,
         keyId)
 {
 }
 internal PermissionInlineCore(
     CosmosClientContext clientContext,
     UserCore user,
     string userId)
     : base(
         clientContext,
         user,
         userId)
 {
 }
Ejemplo n.º 26
0
 internal UserInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string userId)
     : base(
         clientContext,
         database,
         userId)
 {
 }
 internal DatabaseCore(
     CosmosClientContext clientContext,
     string databaseId)
 {
     this.Id            = databaseId;
     this.ClientContext = clientContext;
     this.LinkUri       = clientContext.CreateLink(
         parentLink: null,
         uriPathSegment: Paths.DatabasesPathSegment,
         id: databaseId);
 }
Ejemplo n.º 28
0
        internal DataEncryptionKeyCore(
            CosmosClientContext clientContext,
            DatabaseCore database,
            string keyId)
        {
            this.Id            = keyId;
            this.ClientContext = clientContext;
            this.LinkUri       = DataEncryptionKeyCore.CreateLinkUri(clientContext, database, keyId);

            this.Database = database;
        }
 internal ContainerInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string containerId,
     CosmosQueryClient cosmosQueryClient = null)
     : base(clientContext,
            database,
            containerId,
            cosmosQueryClient)
 {
 }
        internal FeedIteratorInlineCore(
            FeedIterator feedIterator,
            CosmosClientContext clientContext)
        {
            if (!(feedIterator is FeedIteratorInternal feedIteratorInternal))
            {
                throw new ArgumentNullException(nameof(feedIterator));
            }

            this.feedIteratorInternal = feedIteratorInternal;
            this.clientContext        = clientContext;
        }