Exemple #1
0
        private AsyncPageable <QueryResultPage> QueryInternalAsync(
            QueryRequest queryRequest,
            string storeType, CancellationToken cancellationToken)
        {
            async Task <Page <QueryResultPage> > FirstPageFunc(int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetEvents)}");
                scope.Start();
                try
                {
                    Response <QueryResultPage> response = await _queryRestClient
                                                          .ExecuteAsync(queryRequest, storeType, null, null, cancellationToken)
                                                          .ConfigureAwait(false);

                    var frame = new QueryResultPage[]
                    {
                        response.Value
                    };

                    return(Page.FromValues(frame, response.Value.ContinuationToken, response.GetRawResponse()));
                }
                catch (Exception ex)
                {
                    scope.Failed(ex);
                    throw;
                }
            }

            async Task <Page <QueryResultPage> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetEvents)}");
                scope.Start();
                try
                {
                    Response <QueryResultPage> response = await _queryRestClient
                                                          .ExecuteAsync(queryRequest, storeType, nextLink, null, cancellationToken)
                                                          .ConfigureAwait(false);

                    var frame = new QueryResultPage[]
                    {
                        response.Value
                    };

                    return(Page.FromValues(frame, response.Value.ContinuationToken, response.GetRawResponse()));
                }
                catch (Exception ex)
                {
                    scope.Failed(ex);
                    throw;
                }
            }

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }
        /// <summary>
        /// Get all of the <see cref="TimeSeriesPoint"/> in pages asynchronously.
        /// </summary>
        /// <returns>The pageable list <see cref="AsyncPageable{TimeSeriesPoint}"/> of time series points.</returns>
        public AsyncPageable <TimeSeriesPoint> GetResultsAsync()
        {
            async Task <Page <TimeSeriesPoint> > FirstPageFunc(int?pageSizeHint)
            {
                try
                {
                    Response <QueryResultPage> response = await _queryClient
                                                          .ExecuteAsync(_queryRequest, _storeType, null, null, _cancellationToken)
                                                          .ConfigureAwait(false);

                    TimeSeriesPoint[] points = QueryHelper.CreateQueryResponse(response.Value);

                    Progress = response.Value.Progress;

                    return(Page.FromValues(points, response.Value.ContinuationToken, response.GetRawResponse()));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            async Task <Page <TimeSeriesPoint> > NextPageFunc(string nextLink, int?pageSizeHint)
            {
                try
                {
                    Response <QueryResultPage> response = await _queryClient
                                                          .ExecuteAsync(_queryRequest, _storeType, nextLink, null, _cancellationToken)
                                                          .ConfigureAwait(false);

                    TimeSeriesPoint[] points = QueryHelper.CreateQueryResponse(response.Value);

                    Progress = response.Value.Progress;

                    return(Page.FromValues(points, response.Value.ContinuationToken, response.GetRawResponse()));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc));
        }