public async Task <List <MetricAggregatedValueDto> > Handle(GetMetricsAggregatedValueQuery request, CancellationToken cancellationToken) { var dbMetrics = await ValidateMetrics(request); if (dbMetrics.Count == 0) { return(new List <MetricAggregatedValueDto>()); } var timePeriod = TimePeriodUtils.Parse(request.StartTimestamp, request.EndTimestamp, request.LiveSpan); var result = new List <MetricAggregatedValueDto>(); for (int i = 0; i < request.Metrics.Count; i++) { var requestMetric = request.Metrics[i]; var dbMetric = dbMetrics.FirstOrDefault(x => x.Name.Equals(requestMetric.MetricName) && x.Namespace.Equals(requestMetric.Namespace)); if (dbMetric == null) { continue; } // Retrieve the metrics var metricValues = await metricsRetriever.QueryAsync(dbMetric, new TimePeriod() { StartTimestamp = timePeriod.StartTimestamp, EndTimestamp = timePeriod.EndTimestamp }); var metricValue = GetMetricTimeSeriesValue(requestMetric, metricValues); result.Add(metricValue); } return(result); }
private async Task <List <Metric> > ValidateMetrics(GetMetricsAggregatedValueQuery request) { var currentUserId = currentUserService.GetCurrentUserId(); try { //var dbMetrics = await (from application in context.Applications // join metric in context.Metrics // on application.Id equals metric.ApplicationId // where application.UserId == currentUserId && application.Id == request.ApplicationId // //&& request.Metrics.Any(x => x.MetricName == metric.Name && x.Namespace == metric.Namespace) // select metric // ) // .AsNoTracking() // .ToListAsync(); //var dbMetrics = await (from metric in context.Metrics // where metric.ApplicationId == request.ApplicationId // && request.Metrics.Any(x => x.MetricName == metric.Name && x.Namespace == metric.Namespace) // select metric // ) // .AsNoTracking() // .ToListAsync(); var dbMetrics = await context.Metrics.Where(metric => metric.ApplicationId == request.ApplicationId && request.Metrics.Select(x => x.MetricName + x.Namespace).ToList().Contains(metric.Name + metric.Namespace)) .AsNoTracking() .ToListAsync(); return(dbMetrics); } catch (Exception ex) { throw; } }