Esempio n. 1
0
        async Task <IEnumerable <T> > IEventApiRepository.Execute <T>(string query, CancellationToken cancellationToken)
        {
            var results = await _webRequestRepository.ExecuteRequestAsync(query, "events", cancellationToken);

            // According to samples here: https://github.com/Azure-Samples/Azure-Time-Series-Insights/blob/master/C-%20Hello%20World%20App%20Sample/Program.cs
            // Events should combine all results recevied
            var jArray = new JArray(results.SelectMany(x => (JArray)x["events"]));

            var eventResults = jArray.ToObject <List <EventResult> >(new JsonSerializer
            {
                DateParseHandling = DateParseHandling.None
            });

            return(new EventQueryResultToTypeMapper().Map <T>(eventResults));
        }
Esempio n. 2
0
        async Task <IEnumerable <T> > IAggregateApiRepository.Execute <T>(string query, IEnumerable <T> aggregates, CancellationToken cancellationToken)
        {
            var executionResults = new List <T>();

            var results = await _webSocketRepository.ExecuteRequestAsync(query, "aggregates", cancellationToken);

            // According to samples here: https://github.com/Azure-Samples/Azure-Time-Series-Insights/blob/master/C-%20Hello%20World%20App%20Sample/Program.cs
            // Aggregates should only use the final result set
            var jArray = (JArray)results.First();

            foreach (var aggregate in aggregates.Select((x, y) => new { x, y }))
            {
                var typedAggregate   = (IInternalAggregate)aggregate.x;
                var aggregateJObject = (JObject)jArray[aggregate.y];

                var populatedAggregate = typedAggregate.GetPopulatedAggregate(aggregateJObject, x => x);
                executionResults.Add((T)populatedAggregate);
            }

            return(executionResults);
        }