Beispiel #1
0
        /// <summary>
        /// Детализация по метрике - Значения
        /// </summary>
        public ActionResult MetricDetailsValues(Guid id)
        {
            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            var metricHistoryRepository = CurrentAccountDbContext.GetMetricHistoryRepository();
            var rows = metricHistoryRepository
                       .QueryAllByMetricType(metric.ComponentId, metric.MetricTypeId)
                       .OrderByDescending(t => t.BeginDate)
                       .Take(10);

            var model = new MetricDetailsValuesModel()
            {
                Id   = metric.Id,
                Data = rows.Select(t => new MetricDetailsValuesModel.History()
                {
                    Date      = t.BeginDate,
                    Value     = t.Value,
                    Color     = t.Color,
                    HasSignal = t.HasSignal
                }).ToArray()
            };

            return(PartialView(model));
        }
Beispiel #2
0
        public ActionResult Show(Guid id)
        {
            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            var storageContext          = CurrentAccountDbContext;
            var metricHistoryRepository = storageContext.GetMetricHistoryRepository();
            var values = metricHistoryRepository.QueryAllByMetricType(metric.ComponentId, metric.MetricTypeId)
                         .OrderByDescending(t => t.BeginDate)
                         .Take(ShowModel.LastValuesCountMax)
                         .ToList();

            var actualTimeSecs = metric.ActualTimeSecs ?? metric.MetricType.ActualTimeSecs;
            var model          = new ShowModel()
            {
                Metric          = metric,
                ConditionRed    = metric.ConditionAlarm ?? metric.MetricType.ConditionAlarm ?? "не задано",
                ConditionYellow = metric.ConditionWarning ?? metric.MetricType.ConditionWarning ?? "не задано",
                ConditionGreen  = metric.ConditionSuccess ?? metric.MetricType.ConditionSuccess ?? "не задано",
                ElseColor       = metric.ConditionElseColor ?? metric.MetricType.ConditionElseColor,
                NoSignalColor   = metric.NoSignalColor ?? metric.MetricType.NoSignalColor,
                ActualInterval  = actualTimeSecs.HasValue ? TimeSpan.FromSeconds(actualTimeSecs.Value) : (TimeSpan?)null,
                Values          = values
            };

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Values(Guid?metricTypeId, Guid?componentId, ColorStatusSelectorValue color)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();
            var query      = repository.QueryAll()
                             .Include("Component")
                             .Include("MetricType");

            if (metricTypeId.HasValue)
            {
                query = query.Where(t => t.MetricTypeId == metricTypeId.Value);
            }

            if (componentId.HasValue)
            {
                query = query.Where(t => t.ComponentId == componentId.Value);
            }

            if (color.Checked)
            {
                var colors = color.GetSelectedMonitoringStatuses();
                query = query.Where(t => colors.Contains(t.Bulb.Status));
            }
            query = query.OrderBy(t => t.Component.DisplayName).ThenBy(t => t.MetricType.DisplayName);

            var model = new ValuesModel()
            {
                Color        = color,
                MetricTypeId = metricTypeId,
                ComponentId  = componentId,
                Items        = query
            };

            return(View(model));
        }
        // Рисует диаграмму указанных статусов для метрики
        public ActionResult ForMetric(Guid id, EventCategory category, DateTime?fromDate, DateTime?toDate)
        {
            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            return(ForOwner(metric.Id, category, fromDate, toDate));
        }
Beispiel #5
0
        /// <summary>
        /// Детализация по метрике - история
        /// </summary>
        public ActionResult MetricDetailsHistory(Guid id)
        {
            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            var model = new MetricDetailsHistoryModel()
            {
                Id = metric.Id
            };

            return(PartialView(model));
        }
Beispiel #6
0
        /// <summary>
        /// Контейнер разделов детализации по метрике
        /// </summary>
        public ActionResult MetricDetails(Guid id)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();
            var metric     = repository.GetById(id);

            var model = new MetricDetailsModel()
            {
                Id      = metric.Id,
                Name    = metric.MetricType.DisplayName,
                CanEdit = CurrentUser.CanEditCommonData()
            };

            return(PartialView(model));
        }
        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));
        }
Beispiel #8
0
        public PartialViewResult LastEventInfo(Guid id)
        {
            var eventRepository = CurrentAccountDbContext.GetEventRepository();
            var lastEvent       = eventRepository.GetLastEventByEndDate(id);

            if (lastEvent == null)
            {
                return(PartialView("NoLastEventInfo"));
            }

            var model = new EventTypeLastEventModel()
            {
                Id      = lastEvent.Id,
                EndDate = lastEvent.EndDate,
                Message = lastEvent.Message
            };

            model.Properties = ExtentionPropertiesModel.Create(lastEvent);

            // событие метрики
            if (lastEvent.Category.IsMetricCategory())
            {
                var metricRepository = CurrentAccountDbContext.GetMetricRepository();
                var metric           = metricRepository.GetById(lastEvent.OwnerId);
                model.Metric    = metric;
                model.Component = metric.Component;
            }
            // событие проверки
            else if (lastEvent.Category.IsUnitTestCategory())
            {
                var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
                var unitTest           = unitTestRepository.GetById(lastEvent.OwnerId);
                model.Unittest  = unitTest;
                model.Component = unitTest.Component;
            }
            else // событие компонента
            {
                var componentRepository = CurrentAccountDbContext.GetComponentRepository();
                model.Component = componentRepository.GetById(lastEvent.OwnerId);
            }

            return(PartialView(model));
        }
Beispiel #9
0
        /// <summary>
        /// Детализация по компоненту - метрики
        /// </summary>
        public ActionResult ComponentDetailsMetrics(Guid id)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();

            var metrics = repository.QueryAll()
                          .Where(t => t.ComponentId == id)
                          .Include("MetricType")
                          .Include("Bulb")
                          .ToArray();

            var now = MvcApplication.GetServerDateTime();

            var metricInfos = metrics
                              .Select(t => new ComponentDetailsMetricsModel.MetricInfo()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.MetricType.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Value,
                ActualDate     = t.Bulb.ActualDate,
                ActualInterval = t.Bulb.ActualDate - now,
                IsEnabled      = t.Enable,
                HasSignal      = t.Bulb.HasSignal
            })
                              .OrderByDescending(t => t.Status)
                              .ThenBy(t => t.Name)
                              .ToArray();

            var model = new ComponentDetailsMetricsModel()
            {
                Id      = id,
                CanEdit = CurrentUser.CanEditCommonData(),
                Metrics = metricInfos
            };

            return(PartialView(model));
        }
Beispiel #10
0
        /// <summary>
        /// Детализация по метрике - общее состояние
        /// </summary>
        public ActionResult MetricDetailsState(Guid id)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();
            var metric     = repository.GetById(id);
            var now        = MvcApplication.GetServerDateTime();

            var model = new MetricDetailsStateModel()
            {
                Id             = metric.Id,
                Status         = metric.Bulb.Status,
                StatusEventId  = metric.Bulb.StatusEventId,
                StatusDuration = metric.Bulb.GetDuration(now),
                LastResultDate = metric.Bulb.EndDate,
                Value          = metric.Value,
                ActualDate     = metric.Bulb.ActualDate,
                ActualInterval = metric.Bulb.ActualDate - now,
                IsEnabled      = metric.Enable,
                HasSignal      = metric.Bulb.HasSignal,
                CanEdit        = CurrentUser.CanEditCommonData()
            };

            return(PartialView(model));
        }
Beispiel #11
0
        /// <summary>
        /// Вывод списка событий
        /// </summary>
        public ActionResult Index(
            Guid?componentId               = null,
            Guid?componentTypeId           = null,
            ColorStatusSelectorValue color = null,
            Guid?eventTypeId               = null,
            EventCategory?category         = null,
            string search      = null,
            DateTime?fromDate  = null,
            DateTime?toDate    = null,
            Guid?unitTestId    = null,
            Guid?metricId      = null,
            string dataType    = null,
            string versionFrom = null)
        {
            var model = new EventsListModel()
            {
                ComponentId = componentId,
                Color       = color ?? new ColorStatusSelectorValue(),
                EventTypeId = eventTypeId,
                Category    = category,
                Search      = search,
                FromDate    = fromDate,
                ToDate      = toDate,
                VersionFrom = versionFrom
            };

            IQueryable <Event> eventsQuery;

            var componentRepository = CurrentAccountDbContext.GetComponentRepository();
            var eventRepository     = CurrentAccountDbContext.GetEventRepository();

            if (componentId.HasValue)
            {
                eventsQuery = eventRepository.QueryAll(componentId.Value);
            }
            else if (unitTestId.HasValue)
            {
                model.UnitTest = CurrentAccountDbContext.GetUnitTestRepository().GetById(unitTestId.Value);
                eventsQuery    = eventRepository.QueryAll(unitTestId.Value);
            }
            else if (metricId.HasValue)
            {
                model.Metric = CurrentAccountDbContext.GetMetricRepository().GetById(metricId.Value);
                eventsQuery  = eventRepository.QueryAll(metricId.Value);
            }
            else
            {
                if (componentTypeId.HasValue)
                {
                    // поиск по типу компонента
                    var componentIds = componentRepository
                                       .QueryAll()
                                       .Where(t => t.ComponentTypeId == componentTypeId)
                                       .Select(t => t.Id)
                                       .ToArray();
                    eventsQuery = eventRepository.QueryAllByComponentId(componentIds);
                }
                else
                {
                    //  все события аккаунта
                    eventsQuery = eventRepository.QueryAllByAccount();
                }
            }

            if (eventTypeId.HasValue)
            {
                eventsQuery = eventsQuery.Where(t => t.EventTypeId == eventTypeId.Value);
            }

            if (category.HasValue)
            {
                eventsQuery = eventsQuery.Where(t => t.Category == category.Value);
            }
            else
            {
                var categories = new[]
                {
                    EventCategory.ApplicationError,
                    EventCategory.ComponentEvent
                };
                eventsQuery = eventsQuery.Where(t => categories.Contains(t.Category));
            }

            if (model.Color.Checked)
            {
                var importanceLevels = color.GetSelectedEventImportances();
                eventsQuery = eventsQuery.Where(t => importanceLevels.Contains(t.Importance));
            }

            if (fromDate.HasValue)
            {
                eventsQuery = eventsQuery.Where(t => t.ActualDate >= fromDate.Value);
            }

            if (toDate.HasValue)
            {
                eventsQuery = eventsQuery.Where(t => t.StartDate <= toDate.Value);
            }

            if (!string.IsNullOrEmpty(search))
            {
                eventsQuery = eventsQuery.Where(t => t.Message != null && t.Message.Contains(search));
            }

            if (!string.IsNullOrEmpty(versionFrom))
            {
                var versionFromLong = VersionHelper.FromString(versionFrom) ?? -1;
                eventsQuery = eventsQuery.Where(t => (t.VersionLong ?? long.MaxValue) > versionFromLong);
            }

            eventsQuery = eventsQuery.OrderByDescending(t => t.StartDate);

            var eventsModel = eventsQuery.Select(t => new EventsListItemModel()
            {
                Id          = t.Id,
                Message     = t.Message,
                OwnerId     = t.OwnerId,
                Category    = t.Category,
                EventTypeId = t.EventTypeId,
                StartDate   = t.StartDate,
                Importance  = t.Importance,
                EndDate     = t.EndDate,
                ActualDate  = t.ActualDate,
                Count       = t.Count,
                JoinKey     = t.JoinKeyHash
            });

            model.Events = eventsModel;

            model.Components = componentRepository
                               .QueryAllWithDeleted()
                               .ToArray()
                               .Select(t => new EventsListComponentModel()
            {
                Id          = t.Id,
                DisplayName = t.DisplayName,
                SystemName  = t.SystemName,
                FullName    = t.GetFullDisplayName()
            })
                               .ToDictionary(t => t.Id, t => t);

            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();

            model.EventTypes = eventTypeRepository
                               .QueryAllWithDeleted()
                               .Select(t => new EventsListEventTypeModel()
            {
                Id          = t.Id,
                DisplayName = t.DisplayName,
                SystemName  = t.SystemName,
                Code        = t.Code,
                Category    = t.Category
            })
                               .ToDictionary(t => t.Id, t => t);


            if (dataType == "xml")
            {
                var xmlEvents = model.GetXmlEvents(CurrentAccountDbContext);
                return(new ActionXmlFileResult(xmlEvents, "events.xml"));
            }

            return(View(model));
        }