Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        internal static TimeSeriesPoint[] CreateQueryResponse(QueryResultPage value)
        {
            var result = new List <TimeSeriesPoint>();

            var propertyNameToPageValues = new Dictionary <string, PropertyValues>();

            foreach (PropertyValues property in value.Properties)
            {
                propertyNameToPageValues[property.Name] = property;
            }

            for (int index = 0; index < value.Timestamps.Count; index++)
            {
                DateTimeOffset timestamp = value.Timestamps[index];
                result.Add(new TimeSeriesPoint(timestamp, propertyNameToPageValues, index));
            }

            return(result.ToArray());
        }