Example #1
0
        /// <summary>
        /// Редактирует подписку
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(Guid id)
        {
            var subscriptionRepository = CurrentAccountDbContext.GetSubscriptionRepository();
            var subscription           = subscriptionRepository.GetById(id);
            var model = new SubscriptionEditModel()
            {
                ModalMode            = Request.IsAjaxRequest(),
                ReturnUrl            = Url.Action("Index", new { userId = subscription.UserId }),
                Id                   = subscription.Id,
                Object               = subscription.Object,
                NotifyBetterStatus   = subscription.NotifyBetterStatus,
                UserId               = subscription.UserId,
                ComponentTypeId      = subscription.ComponentTypeId,
                ComponentId          = subscription.ComponentId,
                Channel              = subscription.Channel,
                CanShowChannel       = false,
                CanShowComponentType = false,
                CanShowComponent     = false,
                IsEnabled            = subscription.IsEnabled,
                Color                = ColorStatusSelectorValue.FromEventImportance(subscription.Importance),
                MinimumDuration      = TimeSpanHelper.FromSeconds(subscription.DurationMinimumInSeconds),
                ResendTime           = TimeSpanHelper.FromSeconds(subscription.ResendTimeInSeconds)
            };

            return(View(model));
        }
        public ActionResult Edit(Guid?id)
        {
            var model = new EditModel()
            {
                ModalMode = Request.IsAjaxRequest()
            };

            if (id.HasValue)
            {
                var metricType = GetMetricTypeById(id.Value);
                model.Id              = metricType.Id;
                model.SystemName      = metricType.SystemName;
                model.DisplayName     = metricType.DisplayName;
                model.NoSignalColor   = ColorStatusSelectorValue.FromColor(metricType.NoSignalColor);
                model.ActualTime      = TimeSpanHelper.FromSeconds(metricType.ActualTimeSecs);
                model.ConditionRed    = metricType.ConditionAlarm;
                model.ConditionYellow = metricType.ConditionWarning;
                model.ConditionGreen  = metricType.ConditionSuccess;
                model.ElseColor       = ColorStatusSelectorValue.FromColor(metricType.ConditionElseColor);
            }
            else
            {
                // значения по умолчанию
                model.NoSignalColor = new ColorStatusSelectorValue()
                {
                    RedChecked = true
                };
                model.ElseColor = new ColorStatusSelectorValue()
                {
                    RedChecked = true
                };
            }
            return(View(model));
        }
 public void Load(Guid?id, Guid?componentId)
 {
     if (id.HasValue)
     {
         var test = GetUnitTest(id.Value);
         CheckName     = test.DisplayName;
         ComponentId   = test.ComponentId;
         Period        = TimeSpan.FromSeconds(test.PeriodSeconds ?? 0);
         ActualTime    = TimeSpanHelper.FromSeconds(test.ActualTimeSecs);
         NoSignalColor = ColorStatusSelectorValue.FromColor(test.NoSignalColor);
         ErrorColor    = ColorStatusSelectorValue.FromUnitTestResultStatus(test.ErrorColor);
         if (ErrorColor.NotChecked)
         {
             ErrorColor.RedChecked = true;
         }
     }
     else
     {
         Period        = TimeSpan.FromMinutes(10);
         ActualTime    = TimeSpan.FromMinutes(20);
         ComponentId   = componentId;
         CheckName     = DefaultCheckName;
         ErrorColor    = ColorStatusSelectorValue.FromUnitTestResultStatus(UnitTestResult.Alarm);
         NoSignalColor = ColorStatusSelectorValue.FromUnitTestResultStatus(UnitTestResult.Alarm);
     }
 }
Example #4
0
        /// <summary>
        /// Добавление новой подписки
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="channel"></param>
        /// <param name="componentTypeId"></param>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public ActionResult Add(
            Guid?userId,
            SubscriptionObject? @object,
            SubscriptionChannel?channel,
            Guid?componentTypeId,
            Guid?componentId)
        {
            if (@object == null)
            {
                throw new UserFriendlyException("Не указан тип добавляемой подписки");
            }
            userId = userId ?? CurrentUser.Id;
            var model = new SubscriptionEditModel()
            {
                ModalMode            = Request.IsAjaxRequest(),
                ReturnUrl            = Url.Action("Index", new { userId = userId }),
                Id                   = null,
                Object               = @object.Value,
                NotifyBetterStatus   = false,
                UserId               = userId,
                CanShowChannel       = channel == null,
                CanShowComponentType = componentTypeId == null,
                CanShowComponent     = componentId == null,
                Channel              = channel ?? SubscriptionChannel.Email,
                IsEnabled            = true,
                Color                = ColorStatusSelectorValue.FromColor(ObjectColor.Gray),
                MinimumDuration      = null,
                ResendTime           = null,
                ComponentTypeId      = componentTypeId,
                ComponentId          = componentId
            };

            return(View("Edit", model));
        }
Example #5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
            var colorValue  = new ColorStatusSelectorValue();

            if (valueResult == null)
            {
                return(colorValue);
            }

            var value = valueResult.ConvertTo(typeof(string)) as string;

            if (string.IsNullOrWhiteSpace(value))
            {
                //if (bindingContext.ModelType.IsGenericType && .GetGenericTypeDefinition() == typeof(Nullable<>))
                // что нужно делать, если тип модели не nullable не понятно
                return(colorValue);
            }

            try
            {
                value = value.ToLowerInvariant();
                colorValue.RedChecked    = value.Contains("red");
                colorValue.YellowChecked = value.Contains("yellow");
                colorValue.GreenChecked  = value.Contains("green");
                colorValue.GrayChecked   = value.Contains("gray");
                return(colorValue);
            }
            catch (FormatException)
            {
                bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Неверный формат");
                bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueResult);
                return(new ColorStatusSelectorValue());
            }
        }
Example #6
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));
        }
Example #7
0
        public ActionResult Edit(Guid?id, Guid?componentId, Guid?metricTypeId)
        {
            var model = new EditModel()
            {
                ComponentId  = componentId,
                MetricTypeId = metricTypeId
            };

            if (id.HasValue)
            {
                var metric = GetMetricById(id.Value);
                if (metric != null)
                {
                    model.Metric          = metric;
                    model.MetricType      = metric.MetricType;
                    model.Id              = metric.Id;
                    model.ComponentId     = metric.ComponentId;
                    model.MetricTypeId    = metric.MetricTypeId;
                    model.ConditionRed    = metric.ConditionAlarm;
                    model.ConditionYellow = metric.ConditionWarning;
                    model.ConditionGreen  = metric.ConditionSuccess;
                    model.ElseColor       = ColorStatusSelectorValue.FromColor(metric.ConditionElseColor);
                    model.ActualTime      = TimeSpanHelper.FromSeconds(metric.ActualTimeSecs);
                }
            }
            return(View(model));
        }
        public void EditTest()
        {
            // Создадим пользователя
            var account    = TestHelper.GetTestAccount();
            var user       = TestHelper.CreateTestUser(account.Id);
            var dispatcher = TestHelper.GetDispatcherClient();

            var channels = new[]
            {
                SubscriptionChannel.Email,
                SubscriptionChannel.Sms,
                SubscriptionChannel.Http
            };

            foreach (var channel in channels)
            {
                // Получим подписку по умолчанию
                var response = dispatcher.CreateSubscription(account.Id, new CreateSubscriptionRequestData()
                {
                    UserId  = user.Id,
                    Object  = SubscriptionObject.Default,
                    Channel = channel
                });
                var defaultSubscription = response.Data;

                // Изменим подписку по умолчанию
                SubscriptionEditModel model;
                using (var controller = new SubscriptionsController(account.Id, user.Id))
                {
                    var result = (ViewResultBase)controller.Edit(defaultSubscription.Id);
                    model = (SubscriptionEditModel)result.Model;
                }

                model.ReturnUrl       = "/";
                model.IsEnabled       = !model.IsEnabled;
                model.Color           = ColorStatusSelectorValue.FromEventImportance(EventImportance.Success);
                model.MinimumDuration = TimeSpan.FromSeconds(10);
                model.ResendTime      = TimeSpan.FromSeconds(20);

                using (var controller = new SubscriptionsController(account.Id, user.Id))
                {
                    controller.Edit(model);
                }

                // Проверим подписку по умолчанию
                var response2 = dispatcher.CreateSubscription(account.Id, new CreateSubscriptionRequestData()
                {
                    UserId  = user.Id,
                    Object  = SubscriptionObject.Default,
                    Channel = channel
                });
                var newDefaultSubscription = response2.Data;

                Assert.Equal(model.IsEnabled, newDefaultSubscription.IsEnabled);
                Assert.Equal(EventImportance.Success, newDefaultSubscription.Importance);
                Assert.Equal(10, newDefaultSubscription.DurationMinimumInSeconds);
                Assert.Equal(20, newDefaultSubscription.ResendTimeInSeconds);
            }
        }
        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));
        }
Example #10
0
        public PartialViewResult GetComponentsTree(
            ColorStatusSelectorValue color,
            Guid?componentTypeId = null,
            string search        = null)
        {
            var expandedItems = GetExpandedItemsFromCookie();
            var now           = MvcApplication.GetServerDateTime();
            var statuses      = color.GetSelectedMonitoringStatuses();
            var components    = GetSimplifiedComponentList();
            var root          = components.Single(t => t.Parent == null);

            var model = GetTreeItemModel(statuses, componentTypeId, search, root, now, expandedItems);

            return(PartialView("ComponentsTreeElement", model));
        }
Example #11
0
        public ActionResult Show(Guid id)
        {
            var repository   = CurrentAccountDbContext.GetUnitTestTypeRepository();
            var unitTestType = repository.GetById(id);

            var model = new UnitTestTypeEditModel()
            {
                Id            = unitTestType.Id,
                DisplayName   = unitTestType.DisplayName,
                SystemName    = unitTestType.SystemName,
                ActualTime    = TimeSpanHelper.FromSeconds(unitTestType.ActualTimeSecs),
                NoSignalColor = ColorStatusSelectorValue.FromColor(unitTestType.NoSignalColor),
                IsDeleted     = unitTestType.IsDeleted,
                IsSystem      = unitTestType.IsSystem
            };

            return(View(model));
        }
Example #12
0
        public ActionResult Color(string ids, string color, Guid userId, SubscriptionChannel channel)
        {
            var colorValue = ColorStatusSelectorValue.FromString(color);
            var colors     = colorValue.GetSelectedEventImportances();

            var subscriptionRepository = CurrentAccountDbContext.GetSubscriptionRepository();

            var list = ids.Split(',');

            foreach (var item in list)
            {
                var id = new Guid(item);

                var subscription = subscriptionRepository.GetById(id);
                CheckEditingPermissions(subscription);

                var client   = GetDispatcherClient();
                var response = client.CreateSubscription(CurrentUser.AccountId, new CreateSubscriptionRequestData()
                {
                    UserId          = subscription.UserId,
                    ComponentTypeId = subscription.ComponentTypeId,
                    Channel         = subscription.Channel,
                    Object          = subscription.Object
                });
                var data = response.Data;

                var response2 = client.UpdateSubscription(CurrentUser.AccountId, new UpdateSubscriptionRequestData()
                {
                    Id         = data.Id,
                    IsEnabled  = data.IsEnabled,
                    Importance = colors.Count > 0 ? colors[0] : data.Importance,
                    DurationMinimumInSeconds = data.DurationMinimumInSeconds,
                    ResendTimeInSeconds      = data.ResendTimeInSeconds
                });
                response2.Check();
            }

            if (Request.IsAjaxRequest())
            {
                return(new EmptyResult());
            }

            return(RedirectToAction("Index", new { userId = userId, channel = channel }));
        }
        public ActionResult Edit(Guid id)
        {
            var unitTest = GetUnitTestById(id);

            var model = new UnitTestEditModel()
            {
                Id            = unitTest.Id,
                ComponentId   = unitTest.Component.Id,
                Date          = unitTest.Bulb.EndDate,
                DisplayName   = unitTest.DisplayName,
                IsDeleted     = unitTest.IsDeleted,
                Message       = unitTest.Bulb.Message,
                PeriodSeconds = unitTest.PeriodSeconds,
                ActualTime    = TimeSpanHelper.FromSeconds(unitTest.ActualTimeSecs),
                NoSignalColor = ColorStatusSelectorValue.FromColor(unitTest.NoSignalColor),
                Status        = unitTest.Bulb.Status,
                UnitTestType  = unitTest.Type,
                UnitTest      = unitTest
            };

            return(View(model));
        }
Example #14
0
        public ActionResult Index(
            ColorStatusSelectorValue color,
            Guid?componentTypeId = null,
            string search        = null,
            string save          = null)
        {
            if (save == "1")
            {
                var service = CurrentAccountDbContext.GetUserSettingService();
                service.ShowComponentsAsList(CurrentUser.Id, false);
                CurrentAccountDbContext.SaveChanges();
                return(RedirectToAction("Index", new { color = color.HasValue ? color : null, componentTypeId, search }));
            }

            var model = new ComponentsTreeModel()
            {
                ComponentTypeId = componentTypeId,
                Color           = color,
                Search          = search
            };

            return(View(model));
        }
Example #15
0
 public StatesModel()
 {
     Color = new ColorStatusSelectorValue();
     Rows  = new List <StatesModelRow>();
 }
Example #16
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));
        }