Esempio n. 1
0
        internal async Task <ResponseWithHeaders <QueryResult <T>, QueryQueryTwinsHeaders> > QueryTwinsAsync <T>(
            QuerySpecification querySpecification,
            QueryOptions queryTwinsOptions      = null,
            ObjectSerializer objectSerializer   = null,
            CancellationToken cancellationToken = default)
        {
            if (querySpecification == null)
            {
                throw new ArgumentNullException(nameof(querySpecification));
            }

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

            using HttpMessage message = CreateQueryTwinsRequest(querySpecification, queryTwinsOptions);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new QueryQueryTwinsHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                using JsonDocument document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                QueryResult <T> value = QueryResult <T> .DeserializeQueryResult(document.RootElement, objectSerializer);

                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }
Esempio n. 2
0
        public async Task <ResponseWithHeaders <QueryResult, QueryQueryTwinsHeaders> > QueryTwinsAsync(QuerySpecification querySpecification, CancellationToken cancellationToken = default)
        {
            if (querySpecification == null)
            {
                throw new ArgumentNullException(nameof(querySpecification));
            }

            using var message = CreateQueryTwinsRequest(querySpecification);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new QueryQueryTwinsHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                QueryResult value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                if (document.RootElement.ValueKind == JsonValueKind.Null)
                {
                    value = null;
                }
                else
                {
                    value = QueryResult.DeserializeQueryResult(document.RootElement);
                }
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }