Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private Task DispatchChangesAsync(CosmosResponseMessage response, CancellationToken cancellationToken)
        {
            ChangeFeedObserverContext context = new ChangeFeedObserverContextCore <T>(this.settings.LeaseToken, response, this.checkpointer);
            Collection <T>            asFeedResponse;

            try
            {
                asFeedResponse = cosmosJsonSerializer.FromStream <CosmosFeedResponseUtil <T> >(response.Content).Data;
            }
            catch (Exception serializationException)
            {
                // Error using custom serializer to parse stream
                throw new ObserverException(serializationException);
            }

            List <T> asReadOnlyList = new List <T>(asFeedResponse.Count);

            asReadOnlyList.AddRange(asFeedResponse);

            return(this.observer.ProcessChangesAsync(context, asReadOnlyList, cancellationToken));
        }
Ejemplo n.º 3
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);
        }