コード例 #1
0
        async Task <QueryResult> ExecuteQueryAsync(string sqlQueryString, int?pageSize, string continuationToken, CancellationToken cancellationToken)
        {
            this.EnsureInstanceNotClosed();

            if (string.IsNullOrWhiteSpace(sqlQueryString))
            {
                throw new ArgumentException(IotHubApiResources.GetString(ApiResources.ParameterCannotBeNullOrEmpty, nameof(sqlQueryString)));
            }

            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>(
                QueryDevicesRequestUri(),
                new QuerySpecification()
            {
                Sql = sqlQueryString
            },
                null,
                customHeaders,
                new MediaTypeHeaderValue("application/json") { CharSet = "utf-8" },
                null,
                cancellationToken);

            return(await QueryResult.FromHttpResponseAsync(response));
        }
コード例 #2
0
        private async Task <QueryResult> GetJobsAsync(JobType?jobType, JobStatus?jobStatus, int?pageSize, string continuationToken, CancellationToken cancellationToken)
        {
            Logging.Enter(this, $"jobType=[{jobType}], jobStatus=[{jobStatus}], pageSize=[{pageSize}]", nameof(GetJobsAsync));

            try
            {
                EnsureInstanceNotClosed();

                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 _httpClientHelper.GetAsync <HttpResponseMessage>(
                    BuildQueryJobUri(jobType, jobStatus),
                    null,
                    customHeaders,
                    cancellationToken).ConfigureAwait(false);

                return(await QueryResult.FromHttpResponseAsync(response).ConfigureAwait(false));
            }
            finally
            {
                Logging.Exit(this, $"jobType=[{jobType}], jobStatus=[{jobStatus}], pageSize=[{pageSize}]", nameof(GetJobsAsync));
            }
        }
コード例 #3
0
        async Task <QueryResult> GetJobsAsync(JobType?jobType, JobStatus?jobStatus, int?pageSize, string continuationToken, CancellationToken cancellationToken)
        {
            this.EnsureInstanceNotClosed();

            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.GetAsync <HttpResponseMessage>(
                BuildQueryJobUri(jobType, jobStatus),
                null,
                customHeaders,
                cancellationToken);

            return(await QueryResult.FromHttpResponseAsync(response));
        }