protected override UnitTest FindSimpleCheck(EditSimpleModel model)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();

            return(unitTestRepository.QueryAll()
                   .FirstOrDefault(t => t.TypeId == SystemUnitTestTypes.DomainNameTestType.Id && t.DomainNamePaymentPeriodRule != null && t.DomainNamePaymentPeriodRule.Domain == model.Domain && t.IsDeleted == false));
        }
        public T LoadSimpleCheck(Guid?id, Guid?componentId)
        {
            UnitTest unitTest = null;

            if (id.HasValue)
            {
                var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
                unitTest = unitTestRepository.GetByIdOrNull(id.Value);
            }

            if (unitTest == null)
            {
                return(new T()
                {
                    Id = null,
                    ComponentId = componentId,
                    Period = TimeSpan.FromMinutes(10)
                });
            }

            var model = new T()
            {
                Id          = unitTest.Id,
                ComponentId = unitTest.ComponentId,
                Period      = unitTest.PeriodSeconds.HasValue ? TimeSpan.FromSeconds(unitTest.PeriodSeconds.Value) : TimeSpan.FromMinutes(10)
            };

            SetModelParams(model, unitTest);

            return(model);
        }
Beispiel #3
0
        protected override UnitTest FindSimpleCheck(EditSimpleModel model)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();

            return(unitTestRepository.QueryAll()
                   .FirstOrDefault(t => t.TypeId == SystemUnitTestTypes.SslTestType.Id && t.SslCertificateExpirationDateRule != null && t.SslCertificateExpirationDateRule.Url == model.Url && t.IsDeleted == false));
        }
        // Рисует диаграмму указанных статусов для проверки
        public ActionResult ForUnitTest(Guid id, EventCategory category, DateTime?fromDate, DateTime?toDate)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTest           = unitTestRepository.GetById(id);

            return(ForOwner(unitTest.Id, category, fromDate, toDate));
        }
Beispiel #5
0
        protected override UnitTest FindSimpleCheck(EditSimpleModel model)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();

            return(unitTestRepository.QueryAll()
                   .FirstOrDefault(t => t.TypeId == SystemUnitTestTypes.PingTestType.Id && t.PingRule != null && t.PingRule.Host == GetModelHost(model) && t.IsDeleted == false));
        }
Beispiel #6
0
        /// <summary>
        /// Детализация по проверке - история
        /// </summary>
        public ActionResult UnittestDetailsHistory(Guid id)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest           = unitTestRepository.GetById(id);

            var model = new UnittestDetailsHistoryModel()
            {
                Id = unittest.Id
            };

            var eventRepository = CurrentAccountDbContext.GetEventRepository();
            var statusEvents    = eventRepository.QueryAll(unittest.Id).Where(t => t.Category == EventCategory.UnitTestStatus).OrderByDescending(t => t.StartDate).Take(10).ToArray();

            var now = MvcApplication.GetServerDateTime();

            model.Statuses = statusEvents.Select(t => new UnittestDetailsHistoryModel.StatusModel()
            {
                EventId    = t.Id,
                StartDate  = t.StartDate,
                Duration   = t.GetDuration(now),
                Message    = t.GetUnitTestMessage(),
                Importance = t.Importance,
                Count      = t.Count
            }).ToArray();

            return(PartialView(model));
        }
Beispiel #7
0
        public ActionResult Edit(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTest   = repository.GetById(id);

            var editAction = unitTest.SimpleMode ? "EditSimple" : "Edit";

            if (unitTest.TypeId == SystemUnitTestTypes.HttpUnitTestType.Id)
            {
                return(RedirectToAction(editAction, "HttpRequestCheck", new { id }));
            }

            if (unitTest.TypeId == SystemUnitTestTypes.PingTestType.Id)
            {
                return(RedirectToAction(editAction, "PingChecks", new { id }));
            }

            if (unitTest.TypeId == SystemUnitTestTypes.SqlTestType.Id)
            {
                return(RedirectToAction(editAction, "SqlChecks", new { id }));
            }

            if (unitTest.TypeId == SystemUnitTestTypes.DomainNameTestType.Id)
            {
                return(RedirectToAction(editAction, "DomainNamePaymentPeriodChecks", new { id }));
            }

            if (unitTest.TypeId == SystemUnitTestTypes.SslTestType.Id)
            {
                return(RedirectToAction(editAction, "SslCertificateExpirationDateChecks", new { id }));
            }

            return(RedirectToAction("Edit", "UnitTests", new { id }));
        }
Beispiel #8
0
        protected override UnitTest FindSimpleCheck(EditSimpleModel model)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTest           = unitTestRepository.QueryAll()
                                     .FirstOrDefault(t => t.TypeId == SystemUnitTestTypes.HttpUnitTestType.Id && t.HttpRequestUnitTest != null && t.IsDeleted == false && t.HttpRequestUnitTest.Rules.Any(x => x.IsDeleted == false && x.SortNumber == 0 && x.Url == model.Url));

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

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

            var now = MvcApplication.GetServerDateTime();

            var systemUnittests = unittests
                                  .Where(t => t.Type.IsSystem)
                                  .Select(t => new ComponentDetailsUnittestsModel.SystemUnittest()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.DisplayName,
                TypeName       = t.Type.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Bulb.GetUnitTestMessage(),
                Interval       = TimeSpan.FromSeconds(t.PeriodSeconds ?? 0),
                IsEnabled      = t.Enable
            })
                                  .OrderByDescending(t => t.Status)
                                  .ThenBy(t => t.Name)
                                  .ToArray();

            var userUnittests = unittests
                                .Where(t => !t.Type.IsSystem)
                                .Select(t => new ComponentDetailsUnittestsModel.UserUnittest()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Bulb.GetUnitTestMessage(),
                ActualDate     = t.Bulb.ActualDate,
                ActualInterval = t.Bulb.ActualDate - now,
                IsEnabled      = t.Enable
            })
                                .OrderByDescending(t => t.Status)
                                .ThenBy(t => t.Name)
                                .ToArray();

            var model = new ComponentDetailsUnittestsModel()
            {
                Id              = id,
                CanEdit         = CurrentUser.CanEditCommonData(),
                SystemUnittests = systemUnittests,
                UserUnittests   = userUnittests
            };

            return(PartialView(model));
        }
Beispiel #10
0
        public ActionResult Delete(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTest   = repository.GetById(id);

            if (unitTest == null)
            {
                throw new UserFriendlyException("Не удалось найти проверку с Id = " + id);
            }
            unitTest.IsDeleted = true;
            CurrentAccountDbContext.SaveChanges();
            return(RedirectToAction("Index", "UnitTests", new { unitTestTypeId = unitTest.TypeId }));
        }
Beispiel #11
0
        /// <summary>
        /// Контейнер разделов детализации по проверке
        /// </summary>
        public ActionResult UnittestDetails(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest   = repository.GetById(id);

            var model = new UnittestDetailsModel()
            {
                Id      = unittest.Id,
                Name    = unittest.DisplayName,
                CanEdit = CurrentUser.CanEditCommonData()
            };

            return(PartialView(model));
        }
Beispiel #12
0
        /// <summary>
        /// Детализация по проверке - общее состояние
        /// </summary>
        public ActionResult UnittestDetailsState(Guid id)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest           = unitTestRepository.GetById(id);

            var model = new UnittestDetailsStateModel()
            {
                Id                  = id,
                Status              = unittest.Bulb.Status,
                StatusEventId       = unittest.Bulb.StatusEventId,
                StatusDuration      = unittest.Bulb.GetDuration(MvcApplication.GetServerDateTime()),
                CanRun              = unittest.IsSystemType,
                CanEdit             = CurrentUser.CanEditCommonData(),
                IsEnabled           = unittest.Enable,
                TypeId              = unittest.TypeId,
                LastExecutionDate   = unittest.Bulb.EndDate,
                LastExecutionResult = unittest.Bulb.GetUnitTestMessage()
            };

            if (model.TypeId == SystemUnitTestTypes.HttpUnitTestType.Id)
            {
                model.RuleData = unittest.HttpRequestUnitTest?.Rules.FirstOrDefault()?.Url;
            }
            else if (model.TypeId == SystemUnitTestTypes.PingTestType.Id)
            {
                model.RuleData = unittest.PingRule?.Host;
            }
            else if (model.TypeId == SystemUnitTestTypes.DomainNameTestType.Id)
            {
                model.RuleData = unittest.DomainNamePaymentPeriodRule?.Domain;
            }
            else if (model.TypeId == SystemUnitTestTypes.SslTestType.Id)
            {
                model.RuleData = unittest.SslCertificateExpirationDateRule?.Url;
            }
            else if (model.TypeId == SystemUnitTestTypes.SqlTestType.Id)
            {
                model.RuleData = unittest.SqlRule?.Query;
            }

            var eventRepository          = CurrentAccountDbContext.GetEventRepository();
            var lastExecutionResultEvent = eventRepository.QueryAll(unittest.Id).Where(t => t.Category == EventCategory.UnitTestResult).OrderByDescending(t => t.StartDate).FirstOrDefault();

            if (lastExecutionResultEvent != null && lastExecutionResultEvent.Properties.Count > 0)
            {
                model.LastExecutionResultProperties = ExtentionPropertiesModel.Create(lastExecutionResultEvent);
            }

            return(PartialView(model));
        }
        public ActionResult Index(
            Guid?componentId               = null,
            Guid?componentTypeId           = null,
            Guid?unitTestTypeId            = null,
            ColorStatusSelectorValue color = null)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();

            if (color == null)
            {
                color = new ColorStatusSelectorValue();
            }

            var statuses = color.GetSelectedMonitoringStatuses();

            var query = repository.QueryForGui(componentTypeId,
                                               componentId,
                                               unitTestTypeId,
                                               statuses)
                        .Include("UnitTestType").Include("Component").Include("Bulb")
                        .GroupBy(t => t.Type);

            var items = query.Select(t => new UnitTestsListItemLevel1Model()
            {
                UnitTestType = t.Key,
                UnitTests    = t.Select(x => new UnitTestsListItemLevel2Model()
                {
                    Id          = x.Id,
                    Component   = x.Component,
                    Date        = x.Bulb.EndDate,
                    DisplayName = x.DisplayName ?? t.Key.DisplayName,
                    Message     = x.Bulb.Message,
                    Result      = x.Bulb.Status,
                    HasBanner   = x.HttpRequestUnitTest != null && x.HttpRequestUnitTest.HasBanner
                }).OrderBy(x => x.DisplayName).ToList()
            })
                        .OrderBy(t => t.UnitTestType.DisplayName)
                        .ToList();

            var model = new UnitTestsListModel()
            {
                AccountId      = CurrentUser.AccountId,
                ComponentId    = componentId,
                UnitTestTypeId = unitTestTypeId,
                UnitTestTypes  = items,
                Color          = color
            };

            return(View(model));
        }
Beispiel #14
0
        public ActionResult Results()
        {
            var r         = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTests = r.QueryAll()
                            .Include("Bulb")
                            .Include("Type")
                            .Include("Component");

            var model = new ResultsModel()
            {
                Tests = unitTests.ToList()
            };

            return(View(model));
        }
Beispiel #15
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 #16
0
        /// <summary>
        /// Детализация по проверке - настройки
        /// </summary>
        public ActionResult UnitTestDetailsSettings(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest   = repository.GetById(id);

            var model = new UnittestDetailsSettingsModel()
            {
                Id                = unittest.Id,
                TypeName          = unittest.Type.DisplayName,
                Name              = unittest.DisplayName,
                IsSystem          = unittest.IsSystemType,
                ExecutionInterval = unittest.PeriodSeconds != null?TimeSpan.FromSeconds(unittest.PeriodSeconds.Value) : (TimeSpan?)null,
                                        ActualInterval = unittest.ActualTimeSecs != null?TimeSpan.FromSeconds(unittest.ActualTimeSecs.Value) : (TimeSpan?)null,
                                                             TypeId = unittest.TypeId,
            };

            if (model.TypeId == SystemUnitTestTypes.HttpUnitTestType.Id)
            {
                model.HttpUrl     = unittest.HttpRequestUnitTest?.Rules.FirstOrDefault()?.Url;
                model.HttpTimeout = TimeSpan.FromSeconds(unittest.HttpRequestUnitTest?.Rules.FirstOrDefault()?.TimeoutSeconds ?? 0);
            }
            else if (model.TypeId == SystemUnitTestTypes.PingTestType.Id)
            {
                model.PingHost    = unittest.PingRule?.Host;
                model.PingTimeout = TimeSpan.FromMilliseconds(unittest.PingRule?.TimeoutMs ?? 0);
            }
            else if (model.TypeId == SystemUnitTestTypes.DomainNameTestType.Id)
            {
                model.DomainName = unittest.DomainNamePaymentPeriodRule?.Domain;
            }
            else if (model.TypeId == SystemUnitTestTypes.SslTestType.Id)
            {
                model.SslHost = unittest.SslCertificateExpirationDateRule?.Url;
            }
            else if (model.TypeId == SystemUnitTestTypes.SqlTestType.Id)
            {
                model.SqlQuery = unittest.SqlRule?.Query;
            }

            return(PartialView(model));
        }
Beispiel #17
0
        public ActionResult Index()
        {
            var client         = GetDispatcherClient();
            var limitsResponse = client.GetAccountLimits(CurrentUser.AccountId, 30);

            if (!limitsResponse.Success)
            {
                throw new UserFriendlyException("Не удалось получить лимиты аккаунта: " + limitsResponse.ErrorMessage);
            }

            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unitTests          = unitTestRepository.QueryAllWithDeleted().Include("Component").Include("Type");

            var model = new IndexModel()
            {
                Limits    = limitsResponse.Data,
                UnitTests = unitTests.ToDictionary(t => t.Id, t => t)
            };

            return(View(model));
        }
Beispiel #18
0
        /// <summary>
        /// Детализация по проверке - результаты
        /// </summary>
        public ActionResult UnittestDetailsResults(Guid id)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest           = unitTestRepository.GetById(id);

            var model = new UnittestDetailsResultsModel()
            {
                Id = unittest.Id
            };

            var eventRepository = CurrentAccountDbContext.GetEventRepository();
            var resultEvents    = eventRepository.QueryAll(unittest.Id).Where(t => t.Category == EventCategory.UnitTestResult).OrderByDescending(t => t.StartDate).Take(10).ToArray();

            model.Results = resultEvents.Select(t => new UnittestDetailsResultsModel.ResultModel()
            {
                Date       = t.StartDate,
                Importance = t.Importance,
                Message    = t.GetUnitTestMessage(),
                EventId    = t.Id
            }).ToArray();

            return(PartialView(model));
        }
Beispiel #19
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));
        }