public ActionResult ForMetricByInterval(Guid id, EventCategory category, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            return(ForMetric(id, category, fromDate, toDate));
        }
        public ActionResult ForEventTypeAnyComponentsByInterval(Guid eventTypeId, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            return(ForEventTypeAnyComponents(eventTypeId, fromDate, toDate));
        }
        public ActionResult GraphByInterval(Guid id, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            var metricHistoryRepository = CurrentAccountDbContext.GetMetricHistoryRepository();
            var rows = metricHistoryRepository
                       .GetByPeriod(metric.ComponentId, fromDate, toDate, new[] { metric.MetricTypeId })
                       .OrderBy(t => t.BeginDate)
                       .ToArray();

            var model = GetCounterGraphDataModel(metric.MetricType, rows);

            return(PartialView("GraphPartial", model));
        }
Esempio n. 4
0
        public static DateTime IntervalToStartDate(DateTime toDate, TimelineInterval interval)
        {
            if (interval == TimelineInterval.Hour)
            {
                return(toDate.AddHours(-1));
            }

            if (interval == TimelineInterval.Day)
            {
                return(toDate.AddDays(-1));
            }

            if (interval == TimelineInterval.Week)
            {
                return(toDate.AddDays(-7));
            }

            if (interval == TimelineInterval.Month)
            {
                return(toDate.AddMonths(-1));
            }

            return(toDate.AddDays(-1));
        }
Esempio n. 5
0
        public PartialViewResult ShowTimelinesEventsPartial(Guid id, TimelineInterval interval, bool all = false)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventTypes          = eventTypeRepository.QueryAll().Select(t => new { t.Id, t.DisplayName }).ToDictionary(t => t.Id, t => t);
            var eventRepository     = CurrentAccountDbContext.GetEventRepository();

            var query = eventRepository.QueryAllByAccount()
                        .Where(t => t.OwnerId == id && t.StartDate <= toDate && t.ActualDate >= fromDate);

            if (all)
            {
                query = query.Where(t => t.Category == EventCategory.ApplicationError || t.Category == EventCategory.ComponentEvent);
            }
            else
            {
                query = query.Where(t => t.Category == EventCategory.ApplicationError);
            }

            var events = query
                         .GroupBy(t => t.EventTypeId)
                         .Select(t => new
            {
                Id          = t.Key,
                Importance  = t.Max(z => z.Importance),
                Count       = t.Sum(z => z.Count),
                LastMessage = t.OrderByDescending(z => z.StartDate).FirstOrDefault().Message
            })
                         .ToArray();

            var model = new ComponentShowTimelinesGroupModel()
            {
                FromDate   = fromDate,
                ToDate     = toDate,
                HideUptime = true,
                Items      = events
                             .Select(t => new
                {
                    Id          = t.Id,
                    Importance  = t.Importance,
                    Count       = t.Count,
                    Name        = eventTypes[t.Id].DisplayName,
                    LastMessage = t.LastMessage
                })
                             .OrderByDescending(t => t.Importance)
                             .ThenByDescending(t => t.Count)
                             .ThenBy(t => t.Name)
                             .Take(MaxEventTimelineCount)
                             .Select(t => new ComponentShowTimelinesGroupItemModel()
                {
                    Action      = "ForEventType",
                    Category    = null,
                    OwnerId     = id,
                    EventTypeId = t.Id,
                    Importance  = t.Importance,
                    Name        = t.Name,
                    Count       = t.Count,
                    Comment     = t.LastMessage,
                    Url         = Url.Action("Show", "EventTypes", new { Id = t.Id })
                })
                             .ToArray()
            };

            return(PartialView("~/Views/Components/ShowTimelinesPartialGroup.cshtml", model));
        }