Esempio n. 1
0
        public FeedProcessorFactoryCore(
            CosmosContainerCore container,
            ChangeFeedProcessorOptions changeFeedProcessorOptions,
            DocumentServiceLeaseCheckpointer leaseCheckpointer,
            CosmosJsonSerializer cosmosJsonSerializer)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (changeFeedProcessorOptions == null)
            {
                throw new ArgumentNullException(nameof(changeFeedProcessorOptions));
            }
            if (leaseCheckpointer == null)
            {
                throw new ArgumentNullException(nameof(leaseCheckpointer));
            }
            if (cosmosJsonSerializer == null)
            {
                throw new ArgumentNullException(nameof(cosmosJsonSerializer));
            }

            this.container = container;
            this.changeFeedProcessorOptions = changeFeedProcessorOptions;
            this.leaseCheckpointer          = leaseCheckpointer;
            this.cosmosJsonSerializer       = cosmosJsonSerializer;
        }
Esempio n. 2
0
 public FeedProcessorCore(
     ChangeFeedObserver <T> observer,
     FeedIterator resultSetIterator,
     ProcessorSettings settings,
     PartitionCheckpointer checkpointer,
     CosmosJsonSerializer cosmosJsonSerializer)
 {
     this.observer             = observer;
     this.settings             = settings;
     this.checkpointer         = checkpointer;
     this.resultSetIterator    = resultSetIterator;
     this.cosmosJsonSerializer = cosmosJsonSerializer;
 }
 public CosmosLinqQueryProvider(
     CosmosContainerCore container,
     CosmosJsonSerializer cosmosJsonSerializer,
     CosmosQueryClient queryClient,
     QueryRequestOptions cosmosQueryRequestOptions,
     bool allowSynchronousQueryExecution)
 {
     this.container                      = container;
     this.cosmosJsonSerializer           = cosmosJsonSerializer;
     this.queryClient                    = queryClient;
     this.cosmosQueryRequestOptions      = cosmosQueryRequestOptions;
     this.allowSynchronousQueryExecution = allowSynchronousQueryExecution;
 }
        public async Task TestInitialize()
        {
            await base.TestInit();

            string            PartitionKey = "/status";
            ContainerResponse response     = await this.database.CreateContainerAsync(
                new CosmosContainerProperties(id : Guid.NewGuid().ToString(), partitionKeyPath : PartitionKey),
                cancellationToken : this.cancellationToken);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Container);
            Assert.IsNotNull(response.Resource);
            this.Container      = response;
            this.jsonSerializer = new CosmosJsonSerializerCore();
        }
Esempio n. 5
0
        /// <summary>
        /// Converts a list of CosmosElements into a list of objects.
        /// </summary>
        /// <param name="cosmosElements">The cosmos elements</param>
        /// <param name="jsonSerializer">The JSON </param>
        /// <param name="cosmosSerializationOptions">The custom serialization options. This allows custom serialization types like BSON, JSON, or other formats</param>
        /// <returns>Returns a memory stream of cosmos elements. By default the memory stream will contain JSON.</returns>
        internal static IEnumerable <T> Deserialize <T>(
            IEnumerable <CosmosElement> cosmosElements,
            CosmosJsonSerializer jsonSerializer,
            CosmosSerializationOptions cosmosSerializationOptions = null)
        {
            if (!cosmosElements.Any())
            {
                return(Enumerable.Empty <T>());
            }

            Stream          stream       = CosmosElementSerializer.ToStream(cosmosElements, cosmosSerializationOptions);
            IEnumerable <T> typedResults = jsonSerializer.FromStream <List <T> >(stream);

            return(typedResults);
        }
Esempio n. 6
0
 public CosmosLinqQuery(
     CosmosContainerCore container,
     CosmosJsonSerializer cosmosJsonSerializer,
     CosmosQueryClient queryClient,
     QueryRequestOptions cosmosQueryRequestOptions,
     bool allowSynchronousQueryExecution)
     : this(
         container,
         cosmosJsonSerializer,
         queryClient,
         cosmosQueryRequestOptions,
         null,
         allowSynchronousQueryExecution)
 {
 }
        internal static CosmosQueryResponse <TInput> CreateCosmosQueryFeedResponse <TInput>(
            CosmosResponseMessage cosmosResponseMessage,
            CosmosJsonSerializer jsonSerializer)
        {
            using (cosmosResponseMessage)
            {
                // Throw the exception if the query failed.
                cosmosResponseMessage.EnsureSuccessStatusCode();

                string continuationToken = ChangeFeedResultSetStreamIterator.GetContinuationToken(cosmosResponseMessage);
                bool   hasMoreResults    = ChangeFeedResultSetStreamIterator.GetHasMoreResults(continuationToken, cosmosResponseMessage.Headers.ContentLengthAsLong);

                return(CosmosQueryResponse <TInput> .CreateResponse <TInput>(
                           stream : cosmosResponseMessage.Content,
                           jsonSerializer : jsonSerializer,
                           continuationToken : continuationToken,
                           hasMoreResults : hasMoreResults));
            }
        }
        public void AssertJsonSerializer()
        {
            string connectionString    = "AccountEndpoint=https://localtestcosmos.documents.azure.com:443/;AccountKey=425Mcv8CXQqzRNCgFNjIhT424GK99CKJvASowTnq15Vt8LeahXTcN5wt3342vQ==;";
            var    cosmosClientBuilder = new CosmosClientBuilder(connectionString);
            var    cosmosClient        = cosmosClientBuilder.Build(new MockDocumentClient());

            Assert.IsInstanceOfType(cosmosClient.ClientOptions.CosmosSerializerWithWrapperOrDefault, typeof(CosmosJsonSerializerWrapper));
            Assert.AreEqual(cosmosClient.ClientOptions.CosmosSerializerWithWrapperOrDefault, cosmosClient.ClientOptions.SettingsSerializer);

            CosmosJsonSerializer defaultSerializer  = cosmosClient.ClientOptions.SettingsSerializer;
            CosmosJsonSerializer mockJsonSerializer = new Mock <CosmosJsonSerializer>().Object;

            cosmosClientBuilder.WithCustomJsonSerializer(mockJsonSerializer);
            var cosmosClientCustom = cosmosClientBuilder.Build(new MockDocumentClient());

            Assert.AreEqual(defaultSerializer, cosmosClientCustom.ClientOptions.SettingsSerializer);
            Assert.AreEqual(mockJsonSerializer, cosmosClientCustom.ClientOptions.CosmosSerializer);
            Assert.IsInstanceOfType(cosmosClientCustom.ClientOptions.CosmosSerializerWithWrapperOrDefault, typeof(CosmosJsonSerializerWrapper));
            Assert.AreEqual(mockJsonSerializer, ((CosmosJsonSerializerWrapper)cosmosClientCustom.ClientOptions.CosmosSerializerWithWrapperOrDefault).InternalJsonSerializer);
        }
Esempio n. 9
0
        /// <summary>
        /// Converts a list of CosmosElements into a list of objects.
        /// </summary>
        /// <param name="containerRid">Container Rid</param>
        /// <param name="cosmosElements">The cosmos elements</param>
        /// <param name="resourceType">The resource type</param>
        /// <param name="jsonSerializer">The JSON </param>
        /// <param name="cosmosSerializationOptions">The custom serialization options. This allows custom serialization types like BSON, JSON, or other formats</param>
        /// <returns>Returns a list of deserialized objects</returns>
        internal static IEnumerable <T> Deserialize <T>(
            string containerRid,
            IEnumerable <CosmosElement> cosmosElements,
            ResourceType resourceType,
            CosmosJsonSerializer jsonSerializer,
            CosmosSerializationOptions cosmosSerializationOptions = null)
        {
            if (!cosmosElements.Any())
            {
                return(Enumerable.Empty <T>());
            }

            Stream stream = CosmosElementSerializer.ToStream(
                containerRid,
                cosmosElements,
                resourceType,
                cosmosSerializationOptions);

            IEnumerable <T> typedResults = jsonSerializer.FromStream <CosmosFeedResponseUtil <T> >(stream).Data;

            return(typedResults);
        }
Esempio n. 10
0
 public CosmosLinqQuery(
     CosmosContainerCore container,
     CosmosJsonSerializer cosmosJsonSerializer,
     CosmosQueryClient queryClient,
     QueryRequestOptions cosmosQueryRequestOptions,
     Expression expression,
     bool allowSynchronousQueryExecution)
 {
     this.container                      = container ?? throw new ArgumentNullException(nameof(container));
     this.cosmosJsonSerializer           = cosmosJsonSerializer;
     this.queryClient                    = queryClient;
     this.cosmosQueryRequestOptions      = cosmosQueryRequestOptions;
     this.expression                     = expression ?? Expression.Constant(this);
     this.allowSynchronousQueryExecution = allowSynchronousQueryExecution;
     this.queryProvider                  = new CosmosLinqQueryProvider(
         container,
         cosmosJsonSerializer,
         queryClient,
         cosmosQueryRequestOptions,
         this.allowSynchronousQueryExecution);
     this.correlatedActivityId = Guid.NewGuid();
 }
 /// <summary>
 /// Set a custom JSON serializer.
 /// </summary>
 /// <param name="cosmosJsonSerializer">The custom class that implements <see cref="CosmosJsonSerializer"/> </param>
 /// <returns>The <see cref="CosmosClientBuilder"/> object</returns>
 /// <seealso cref="CosmosJsonSerializer"/>
 /// <seealso cref="CosmosClientOptions.CosmosSerializer"/>
 public virtual CosmosClientBuilder WithCustomJsonSerializer(
     CosmosJsonSerializer cosmosJsonSerializer)
 {
     this.clientOptions.CosmosSerializer = cosmosJsonSerializer;
     return(this);
 }