async Task <ProvisioningQueryResult> ExecuteQueryAsync(Uri queryUri, int?pageSize, string continuationToken, CancellationToken cancellationToken)
        {
            ThrowIfClosed();

            //TODO: support sqlQueryStrings

            var customHeaders = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(continuationToken))
            {
                customHeaders.Add(ContinuationTokenHeader, continuationToken);
            }

            if (pageSize != null)
            {
                customHeaders.Add(PageSizeHeader, pageSize.ToString());
            }

            HttpResponseMessage response = await this.httpClientHelper.PostAsync <QuerySpecification>(
                queryUri,
                new QuerySpecification
            {
                Sql = string.Empty
            },
                null,
                customHeaders,
                new MediaTypeHeaderValue("application/json") { CharSet = "utf-8" },
                null,
                cancellationToken);

            return(await ProvisioningQueryResult.FromHttpResponseAsync(response));
        }
Esempio n. 2
0
        async Task <ProvisioningQueryResult> GetNextAsync(QueryOptions options)
        {
            this.newQuery = false;
            ProvisioningQueryResult result = await this.queryTaskFunc(!string.IsNullOrWhiteSpace(options?.ContinuationToken)?options.ContinuationToken : this.continuationToken);

            this.continuationToken = result.ContinuationToken;
            return(result);
        }
Esempio n. 3
0
        static IEnumerable <T> CastResultContent <T>(ProvisioningQueryResult result, ProvisioningQueryResultType expected)
        {
            if (result.Type != expected)
            {
                throw new InvalidCastException($"result type is {result.Type}");
            }

            // TODO: optimize this 2nd parse from JObject to target object type T
            return(result.Items.Select(o => ((JObject)o).ToObject <T>()));
        }
Esempio n. 4
0
        public async Task <QueryResponse <string> > GetNextAsJsonAsync(QueryOptions options)
        {
            IEnumerable <string> response;

            if (!this.HasMoreResults)
            {
                response = new List <string>();
            }
            else
            {
                ProvisioningQueryResult r = await this.GetNextAsync(options);

                response = r.Items.Select(o => o.ToString());
            }

            return(new QueryResponse <string>(response, this.continuationToken));
        }
Esempio n. 5
0
        async Task <IEnumerable <T> > GetAndCastNextResultAsync <T>(ProvisioningQueryResultType type, QueryOptions options)
        {
            ProvisioningQueryResult r = await this.GetNextAsync(options);

            return(CastResultContent <T>(r, type));
        }