public async Task <ServiceBusViewModel> GetBusMetrics(int interval, DateTime?startTime, DateTime?endTime, string metricName = null)
        {
            if (startTime is null || endTime is null || interval <= 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (!(metricName is null) && !Default.ServiceBusMetricsList.Contains(metricName))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (startTime.Value == endTime.Value)
            {
                endTime = endTime.Value.AddHours(24);
            }

            var models = await _serviceBusMetricsRepository.GetMetricsAsync(interval, startTime.Value, endTime.Value, metricName);

            var viewModel = new ServiceBusViewModel
            {
                ServiceBusModels = models.ToList()
            };

            return(viewModel);
        }
        public async Task <ServiceBusViewModel> GetBusMetricsForHours(int hour, int interval)
        {
            if (hour <= 0 || interval <= 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var currentTime = DateTime.UtcNow;
            var models      = await _serviceBusMetricsRepository.GetMetricsAsync(interval, currentTime.AddHours(-hour), currentTime);

            var viewModel = new ServiceBusViewModel
            {
                ServiceBusModels = models.ToList()
            };

            return(viewModel);
        }
Пример #3
0
        private ServiceBusViewModel convertJsonToViewModel(string json)
        {
            var root = JsonConvert.DeserializeObject <IncomingMetrics>(json);

            ServiceBusViewModel viewModel = new ServiceBusViewModel
            {
                MetricName = root.Value[0].Name.Value,
                Points     = new List <ServiceBusMetricPoint>()
            };

            foreach (var t in root.Value[0].Timeseries[0].Data)
            {
                viewModel.Points.Add(new ServiceBusMetricPoint()
                {
                    Time  = t.TimeStamp.AddHours(3).ToUniversalTime(),
                    Count = Convert.ToInt32(t.Total)
                });
            }

            return(viewModel);
        }