Beispiel #1
0
        public PartialViewResult DefectControl(Guid eventTypeId)
        {
            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType           = eventTypeRepository.GetById(eventTypeId);

            return(PartialView(eventType));
        }
Beispiel #2
0
        public ActionResult GetEventTypesMiniList(string category = null, string search = null)
        {
            var eventCategory = EnumHelper.StringToEnum <EventCategory>(category);

            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var query      = repository.QueryAll();

            if (eventCategory.HasValue)
            {
                query = query.Where(t => t.Category == eventCategory);
            }

            if (!string.IsNullOrEmpty(search))
            {
                query = query.Where(t => t.DisplayName.Contains(search) || t.SystemName.Contains(search) || t.Id.ToString().Contains(search));
            }

            query = query.OrderBy(t => t.DisplayName).Take(100);

            var eventTypes = query.Select(t => new EventTypesMiniListItemModel()
            {
                Id          = t.Id,
                DisplayName = t.DisplayName
            }).ToArray();

            var model = new EventTypesMiniListModel()
            {
                EventTypes = eventTypes,
                IsLimited  = eventTypes.Length == 100
            };

            return(PartialView("EventTypesMiniList", model));
        }
Beispiel #3
0
        public JsonResult CheckSystemName(ComponentTypeEditModel model)
        {
            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = repository.GetOneOrNullBySystemName(model.SystemName);

            if (eventType != null && (model.Id == Guid.Empty || model.Id != eventType.Id))
            {
                return(Json("Тип события с таким системным именем уже существует", JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        public ActionResult Delete(DeleteConfirmationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model));
            }
            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = repository.GetById(Guid.Parse(model.Id));

            CheckDeletingPermissions(eventType);
            repository.Remove(eventType);
            this.SetTempMessage(TempMessageType.Success, "Тип события удалён");
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult Delete(Guid id)
        {
            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = repository.GetById(id);

            CheckDeletingPermissions(eventType);
            var model = new DeleteConfirmationModel()
            {
                Id        = id.ToString(),
                Title     = "Удаление типа события",
                ModalMode = Request.IsAjaxRequest(),
                Message   = "Вы действительно хотите удалить этот тип события?",
                ReturnUrl = Url.Action("Index")
            };

            return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model));
        }
Beispiel #6
0
        public ActionResult Index(string importance = null, string category = null, string search = null, int?showDeleted = null)
        {
            var eventImportance = EnumHelper.StringToEnum <EventImportance>(importance);
            var eventCategory   = EnumHelper.StringToEnum <EventCategory>(category);

            if (eventCategory == null)
            {
                eventCategory = EventCategory.ComponentEvent;
            }

            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventTypes = repository.QueryAllWithDeleted();

            if (eventImportance.HasValue)
            {
                eventTypes = eventTypes.Where(t => t.ImportanceForNew == eventImportance);
            }

            eventTypes = eventTypes.Where(t => t.Category == eventCategory);

            if (!string.IsNullOrEmpty(search))
            {
                eventTypes = eventTypes.Where(t => t.DisplayName.Contains(search) || t.SystemName.Contains(search) || t.Id.ToString() == search);
            }

            if (showDeleted != 1)
            {
                eventTypes = eventTypes.Where(t => t.IsDeleted == false);
            }

            eventTypes = eventTypes.OrderBy(t => t.DisplayName);

            var model = new EventTypesListModel()
            {
                EventTypes  = eventTypes,
                Category    = eventCategory,
                Importance  = eventImportance,
                Search      = search,
                ShowDeleted = showDeleted == 1
            };

            return(View(model));
        }
Beispiel #7
0
        public ActionResult Edit(Guid id)
        {
            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = repository.GetById(id);

            CheckEditingPermissions(eventType);
            var model = new EventTypeEditModel()
            {
                Id               = eventType.Id,
                DisplayName      = eventType.DisplayName,
                SystemName       = eventType.SystemName,
                Category         = eventType.Category,
                JoinInterval     = eventType.JoinInterval,
                OldVersion       = eventType.OldVersion,
                ImportanceForOld = eventType.ImportanceForOld,
                ImportanceForNew = eventType.ImportanceForNew,
                IsDeleted        = eventType.IsDeleted
            };

            return(View(model));
        }
Beispiel #8
0
        public ActionResult Show(Guid id, TimelineInterval?period)
        {
            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = repository.GetById(id);
            var model      = new EventTypeShowModel()
            {
                Id               = eventType.Id,
                DisplayName      = eventType.DisplayName,
                SystemName       = eventType.SystemName,
                Category         = eventType.Category,
                Code             = eventType.Code,
                JoinInterval     = eventType.JoinInterval,
                OldVersion       = eventType.OldVersion,
                ImportanceForOld = eventType.ImportanceForOld,
                ImportanceForNew = eventType.ImportanceForNew,
                IsSystem         = eventType.IsSystem,
                IsDeleted        = eventType.IsDeleted,
                Created          = eventType.CreateDate,
                Period           = period ?? TimelineInterval.Day
            };

            return(View(model));
        }
Beispiel #9
0
        public ActionResult Add(EventTypeEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var repository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventType  = new EventType()
            {
                DisplayName         = model.DisplayName,
                SystemName          = model.SystemName,
                Category            = EventCategory.ComponentEvent,
                JoinIntervalSeconds = TimeSpanHelper.GetSeconds(model.JoinInterval),
                OldVersion          = model.OldVersion,
                ImportanceForOld    = model.ImportanceForOld,
                ImportanceForNew    = model.ImportanceForNew
            };

            repository.Add(eventType);
            this.SetTempMessage(TempMessageType.Success, string.Format("Добавлен тип события <a href='{1}' class='alert-link'>{0}</a>", eventType.DisplayName, Url.Action("Show", new { id = eventType.Id })));
            return(RedirectToAction("Index"));
        }
Beispiel #10
0
        public ActionResult Index(Guid?componentId = null, string fromDate = null, string toDate = null,
                                  string category  = null, string channel  = null, string status = null, Guid?userId = null)
        {
            var sDate = !string.IsNullOrEmpty(fromDate) ? DecodeDateTimeParameter(fromDate) : (DateTime?)null;
            var eDate = !string.IsNullOrEmpty(toDate) ? DecodeDateTimeParameter(toDate) : (DateTime?)null;

            var eventCategory = EnumHelper.StringToEnum <EventCategory>(category);
            var nChannel      = EnumHelper.StringToEnum <NotificationType>(channel);
            var nStatus       = EnumHelper.StringToEnum <NotificationStatus>(status);

            var componentRepository = CurrentAccountDbContext.GetComponentRepository();
            var userRepository      = CurrentAccountDbContext.GetUserRepository();

            if (!CurrentUser.CanManageAccount())
            {
                userId = CurrentUser.Id;
            }

            if (userId.HasValue)
            {
                userRepository.GetById(userId.Value);
            }

            var users = userRepository.QueryAll().ToArray();
            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventTypes          = eventTypeRepository.QueryAll().ToArray();
            var allComponents       = componentRepository.QueryAllWithDeleted();

            var notificationRepository = CurrentAccountDbContext.GetNotificationRepository();
            var query = notificationRepository.QueryAllForGui(componentId, sDate, eDate, eventCategory, nChannel, nStatus, userId);

            query = query.OrderByDescending(t => t.CreationDate).Take(1000);
            var notifications = query.ToArray()
                                .Join(users, a => a.UserId, b => b.Id, (a, b) => new { Notification = a, User = b })
                                .Join(eventTypes, a => a.Notification.Event.EventTypeId, b => b.Id,
                                      (a, b) => new { Notification = a, EventType = b })
                                .Select(t => new NotificationsListItemModel()
            {
                Id           = t.Notification.Notification.Id,
                CreationDate = t.Notification.Notification.CreationDate,
                Event        = t.Notification.Notification.Event,
                User         = t.Notification.User,
                Component    = allComponents.Single(x => x.Id == t.Notification.Notification.Event.OwnerId),
                Address      = t.Notification.Notification.Address,
                Channel      = t.Notification.Notification.Type,
                Status       = t.Notification.Notification.Status,
                SendError    = t.Notification.Notification.SendError,
                SendDate     = t.Notification.Notification.SendDate,
                NextDate     = null,
                EventType    = t.EventType
            });

            var model = new NotificationsListModel()
            {
                AccountId     = CurrentUser.AccountId,
                ComponentId   = componentId,
                FromDate      = sDate,
                ToDate        = eDate,
                Category      = eventCategory,
                Channel       = nChannel,
                Status        = nStatus,
                UserId        = userId,
                Notifications = notifications.OrderByDescending(t => t.CreationDate).ToList()
            };

            return(View(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));
        }
Beispiel #12
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));
        }
Beispiel #13
0
        /// <summary>
        /// Статистика запусков
        /// </summary>
        public ActionResult Starts(Guid?componentTypeId = null, Guid?componentId = null, string fromDate = null, string toDate = null)
        {
            var sDate = !string.IsNullOrEmpty(fromDate) ? DecodeDateTimeParameter(fromDate) : (DateTime?)null;
            var eDate = !string.IsNullOrEmpty(toDate) ? DecodeDateTimeParameter(toDate) : (DateTime?)null;

            Component component           = null;
            var       componentRepository = CurrentAccountDbContext.GetComponentRepository();

            if (componentId.HasValue)
            {
                component = componentRepository.GetById(componentId.Value);
            }

            ComponentType componentType           = null;
            var           componentTypeRepository = CurrentAccountDbContext.GetComponentTypeRepository();

            if (componentTypeId.HasValue)
            {
                componentType = componentTypeRepository.GetById(componentTypeId.Value);
            }
            else
            {
                componentType = componentTypeRepository.QueryAll().Where(t => t.IsDeleted == false).OrderBy(t => t.DisplayName).FirstOrDefault();
            }

            EventType startEventType = null;

            Component[] components;
            var         items = new List <StartsReportItemModel>();
            var         graph = new List <StartsReportGrapthItemModel>();
            string      error = null;

            if (componentType != null)
            {
                if (component != null)
                {
                    components = new[] { component }
                }
                ;
                else
                {
                    components =
                        componentRepository.QueryAll()
                        .Where(t => t.ComponentTypeId == componentType.Id && t.IsDeleted == false)
                        .ToArray();
                }

                var componentsIds = components.Select(t => t.Id).ToArray();

                var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
                startEventType = eventTypeRepository.GetOneOrNullBySystemName(SystemEventType.ComponentStart);
                if (startEventType != null)
                {
                    var startEventTypeId = startEventType.Id;
                    var listLockObject   = new Object();

                    var eventRepository = CurrentAccountDbContext.GetEventRepository();

                    // Все события запуска за указанный интервал
                    var allEventsQuery = eventRepository.QueryAllByComponentId(componentsIds)
                                         .Where(t => t.EventTypeId == startEventTypeId);
                    if (sDate.HasValue)
                    {
                        allEventsQuery = allEventsQuery.Where(t => t.StartDate >= sDate.Value);
                    }
                    if (eDate.HasValue)
                    {
                        allEventsQuery = allEventsQuery.Where(t => t.StartDate <= eDate.Value);
                    }

                    // События запуска по компонентам
                    var startEventsQuery =
                        allEventsQuery.Select(
                            t => new { Id = t.Id, StartDate = t.StartDate, ComponentId = t.OwnerId, Count = t.Count });
                    var startEvents = startEventsQuery.GroupBy(t => t.ComponentId).ToArray();

                    var list =
                        startEvents.Join(components, a => a.Key, b => b.Id, (a, b) => new { Component = b, Events = a })
                        .Select(t => new StartsReportItemModel()
                    {
                        ComponentId          = t.Component.Id,
                        ComponentDisplayName = t.Component.DisplayName,
                        ComponentSystemName  = t.Component.SystemName,
                        CreateDate           = t.Component.CreatedDate,
                        Version    = t.Component.Version,
                        FirstStart =
                            t.Events.OrderBy(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(),
                        FirstStartId = t.Events.OrderBy(x => x.StartDate).Select(x => x.Id).FirstOrDefault(),
                        LastStart    =
                            t.Events.OrderByDescending(x => x.StartDate)
                            .Select(x => x.StartDate)
                            .FirstOrDefault(),
                        LastStartId =
                            t.Events.OrderByDescending(x => x.StartDate).Select(x => x.Id).FirstOrDefault(),
                        Count = t.Events.Sum(x => x.Count)
                    }).ToList();

                    // События запуска по датам
                    var statsEventsQuery = allEventsQuery.Select(t => new { StartDate = t.StartDate, Count = t.Count });
                    var stats            =
                        statsEventsQuery.GroupBy(t => DbFunctions.TruncateTime(t.StartDate))
                        .Select(t => new StartsReportGrapthItemModel()
                    {
                        Date  = t.Key.Value,
                        Count = t.Sum(x => x.Count)
                    }).ToList();

                    lock (listLockObject)
                    {
                        items.AddRange(list);
                        graph.AddRange(stats);
                    }
                }
                else
                {
                    error = "У выбранного типа компонента нет типа события с системным именем '" +
                            SystemEventType.ComponentStart + "'";
                }
            }

            var model = new StartsReportModel()
            {
                AccountId        = CurrentUser.AccountId,
                ComponentId      = componentId,
                ComponentTypeId  = componentTypeId,
                FromDate         = sDate,
                ToDate           = eDate,
                Items            = items.OrderBy(t => t.ComponentDisplayName).ToList(),
                Graph            = graph.OrderBy(t => t.Date).ToList(),
                Error            = error,
                StartEventTypeId = startEventType != null ? startEventType.Id : (Guid?)null,
                Total            = items.Sum(t => t.Count)
            };

            return(View(model));
        }