public ActionResult Delete(Guid id) { var repository = CurrentAccountDbContext.GetComponentTypeRepository(); var componentType = repository.GetById(id); CheckDeletingPermissions(componentType); var model = new DeleteConfirmationModel() { Id = id.ToString(), Title = "Удаление типа компонента", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить этот тип компонента?", ReturnUrl = Url.Action("Index") }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
public ActionResult Edit(Guid id) { var repository = CurrentAccountDbContext.GetComponentTypeRepository(); var componentType = repository.GetById(id); CheckEditingPermissions(componentType); var model = new ComponentTypeEditModel() { Id = componentType.Id, DisplayName = componentType.DisplayName, SystemName = componentType.SystemName, IsCommon = componentType.IsSystem, IsDeleted = componentType.IsDeleted }; return(View(model)); }
/// <summary> /// Детализация по компоненту - лог /// </summary> public ActionResult ComponentDetailsLog(Guid id, LogLevel?level, int?count) { level = level ?? LogLevel.Trace; count = count ?? 10; const int maxCount = 500; if (count > maxCount) { count = maxCount; } var model = new ComponentDetailsLogModel() { ComponentId = id, Level = level.Value, Count = count.Value }; var levels = new[] { LogLevel.Trace, LogLevel.Debug, LogLevel.Info, LogLevel.Warning, LogLevel.Error, LogLevel.Fatal }; var levelFilter = levels.Where(x => x >= level.Value).ToArray(); var messages = CurrentAccountDbContext.GetLogRepository() .GetLastRecords(id, null, levelFilter, null, count.Value) .ToArray(); model.Messages = messages .OrderBy(x => x.Date) .ThenBy(x => x.Order) .Select(x => new ComponentDetailsLogModel.LogMessage() { Id = x.Id, Level = x.Level, Message = x.Message, Time = x.Date, HasProperties = x.ParametersCount > 0 }).ToArray(); return(PartialView(model)); }
public ActionResult DeleteRule(Guid id) { var repository = CurrentAccountDbContext.GetHttpRequestUnitTestRuleRepository(); var rule = repository.GetById(id); CheckRuleDeletingPermissions(rule); var model = new DeleteConfirmationModel() { Id = id.ToString(), Title = "Удаление правила проверки", ModalMode = Request.IsAjaxRequest(), Message = "Вы действительно хотите удалить это правило?", ReturnUrl = Url.Action("Edit", new { id = rule.HttpRequestUnitTestId }) }; return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); }
/// <summary> /// Подгружаемая часть с блоком N предыдущих записей /// </summary> public PartialViewResult GetPreviousRecords(DateTime toDate, int order, LogFiltersModel filters) { if (!filters.ComponentId.HasValue) { return(null); } var levels = GetFilterLevels(filters.LogLevel); var logRepository = CurrentAccountDbContext.GetLogRepository(); var records = logRepository.GetPreviousRecords(filters.ComponentId.Value, toDate, order, levels, filters.Context, OutputRecordCount); var model = new LogPartialModel() { Filters = filters, Items = RecordsToModel(records), OutputRecordCount = OutputRecordCount }; // Рассчитаем ссылку на предыдущие записи if (model.Items.Length > 0) { var firstRecord = model.Items[0]; model.Previous = new LogPartialModel.DateAndOrderModel() { Date = firstRecord.Date, Order = firstRecord.Order }; } else { model.Previous = null; model.NoPreviousRecords = true; } model.Next = null; model.MarkAsNew = true; if (model.Items.Length > 0) { model.ScrollToId = model.Items.Last().Id; } return(PartialView("Partial", 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)); }
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)); }
public ActionResult GetLogFile(Guid componentId, Guid id, Guid fileId) { var componentRepository = CurrentAccountDbContext.GetComponentRepository(); componentRepository.GetById(componentId); var repository = CurrentAccountDbContext.GetLogRepository(); var row = repository.Find(id, componentId); var file = row.Parameters.SingleOrDefault(x => x.Id == fileId); if (file == null) { throw new HttpException(404, "Файл не найден"); } var contentType = GuiHelper.GetContentType(file.Name); var bytes = Convert.FromBase64String(file.Value); return(File(bytes, contentType, file.Name)); }
public ActionResult ChangeStatusDialogPost(ChangeDefectStatusDialogModel model) { if (model.DefectId == null) { throw new Exception("model.DefectId == null"); } if (model.Status == null) { throw new Exception("model.Status == null"); } var defect = GetDefectById(model.DefectId.Value); var defectService = CurrentAccountDbContext.GetDefectService(); var user = GetUserById(CurrentUser.Id); defectService.ChangeStatus(CurrentUser.AccountId, defect, model.Status.Value, user, model.Comment); CurrentAccountDbContext.SaveChanges(); return(GetSuccessJsonResponse()); }
public ActionResult Delete(DeleteConfirmationModel model) { if (!ModelState.IsValid) { return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model)); } var repository = CurrentAccountDbContext.GetComponentTypeRepository(); var componentType = repository.GetById(Guid.Parse(model.Id)); CheckDeletingPermissions(componentType); var client = GetDispatcherClient(); client.DeleteComponentType(CurrentUser.AccountId, componentType.Id); this.SetTempMessage(TempMessageType.Success, "Тип компонента удалён"); return(Redirect(model.ReturnUrl)); }
/// <summary> /// Подгружаемая часть лога, не для режима следующие N / предыдущие N /// </summary> public PartialViewResult Partial(LogFiltersModel filters) { if (!filters.ComponentId.HasValue) { return(null); } // Если явно указана запись, отобразим как при поиске, с центрированием if (filters.Id.HasValue) { return(Center(filters)); } var levels = GetFilterLevels(filters.LogLevel); IQueryable <Log> records; var logRepository = CurrentAccountDbContext.GetLogRepository(); if (filters.Date.HasValue) { records = logRepository.GetFirstRecords(filters.ComponentId.Value, filters.Date, levels, filters.Context, OutputRecordCount); } else { records = logRepository.GetLastRecords(filters.ComponentId.Value, null, levels, filters.Context, OutputRecordCount); } var model = new LogPartialModel() { Filters = filters, Items = RecordsToModel(records), OutputRecordCount = OutputRecordCount }; // Если показываем записи с конца, то прокрутим до последней записи if (!filters.Date.HasValue && model.Items.Length > 0) { model.ScrollToId = model.Items.Last().Id; } FillRecordLinks(model); return(PartialView(model)); }
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 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)); }
public ActionResult DeleteContact(DeleteConfirmationModel model) { var repository = CurrentAccountDbContext.GetUserRepository(); var contact = repository.GetContactById(Guid.Parse(model.Id)); if (!CurrentUser.CanManageAccount() && contact.UserId != CurrentUser.Id) { throw new NoAccessToPageException(); } repository.DeleteContactById(contact.Id); if (model.ModalMode) { return(new EmptyResult()); } return(Redirect(model.ReturnUrl)); }
public ActionResult AddContact(Guid userId) { var repository = CurrentAccountDbContext.GetUserRepository(); var user = repository.GetById(userId); if (!CurrentUser.CanManageAccount() && user.Id != CurrentUser.Id) { throw new NoAccessToPageException(); } var model = new UserContactModel() { ModalMode = Request.IsAjaxRequest(), ReturnUrl = Url.Action("Edit", new { id = userId.ToString() }), UserId = user.Id }; return(View(model)); }
public ActionResult Index(string search = null) { var repository = CurrentAccountDbContext.GetComponentTypeRepository(); var query = repository.QueryAll(); if (!string.IsNullOrEmpty(search)) { query = query.Where(t => t.SystemName.Contains(search) || t.DisplayName.Contains(search) || t.Id.ToString().Equals(search)); } var model = new ComponentTypesListModel { Search = search, ComponentTypes = query.OrderBy(t => t.DisplayName) }; return(View(model)); }
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)); }
public ActionResult Edit(Guid componentId) { var repository = CurrentAccountDbContext.GetLogConfigRepository(); var config = repository.GetByComponentId(componentId); var model = new EditLogModel { Id = componentId, IsFatalEnabled = config.IsFatalEnabled, IsErrorEnabled = config.IsErrorEnabled, IsWarningEnabled = config.IsWarningEnabled, IsInfoEnabled = config.IsInfoEnabled, IsDebugEnabled = config.IsDebugEnabled, IsTraceEnabled = config.IsTraceEnabled, ComponentName = config.Component.DisplayName }; return(PartialView(model)); }
/// <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)); }
public ActionResult Index(TimelineInterval?interval) { var userSettingService = CurrentAccountDbContext.GetUserSettingService(); var savedInterval = (TimelineInterval?)userSettingService.ComponentHistoryInterval(CurrentUser.Id) ?? TimelineInterval.Hour; if (interval != null) { userSettingService.ComponentHistoryInterval(CurrentUser.Id, (int)interval.Value); DbContext.SaveChanges(); } var model = new IndexModel() { Interval = interval ?? savedInterval }; model.ToDate = MvcApplication.GetServerDateTime(); model.FromDate = TimelineHelper.IntervalToStartDate(model.ToDate, model.Interval); return(View(model)); }
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)); }
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)); }
/// <summary> /// Главная страница лога /// </summary> public ActionResult Index(LogFiltersModel filters) { filters = filters ?? new LogFiltersModel(); var model = new LogIndexModel() { ComponentId = filters.ComponentId, LogLevel = filters.LogLevel, Context = filters.Context, Date = filters.Date, Text = filters.Text, Id = filters.Id }; if (model.ComponentId.HasValue) { var componentRepository = CurrentAccountDbContext.GetComponentRepository(); model.Component = componentRepository.GetById(model.ComponentId.Value); } return(View(model)); }
/// <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)); }
public ActionResult EditContact(Guid id) { var repository = CurrentAccountDbContext.GetUserRepository(); var contact = repository.GetContactById(id); if (!CurrentUser.CanManageAccount() && contact.UserId != CurrentUser.Id) { throw new NoAccessToPageException(); } var model = new UserContactModel() { ModalMode = Request.IsAjaxRequest(), ReturnUrl = Url.Action("Edit", new { id = contact.UserId.ToString() }), Id = id, UserId = contact.UserId, Type = contact.Type, Value = contact.Value }; return(View(model)); }
public ActionResult Edit(EditModel model) { try { model.Validate(); } catch (UserFriendlyException exception) { ModelState.AddModelError(string.Empty, exception.Message); } if (!ModelState.IsValid) { return(View(model)); } model.SaveCommonSettings(); model.SaveRule(); CurrentAccountDbContext.SaveChanges(); return(RedirectToAction("ResultDetails", "UnitTests", new { id = model.Id })); }
public ActionResult CreateDefectDialog(Guid?eventTypeId, Guid?userId, string comment) { if (eventTypeId == null) { throw new Exception("eventTypeId == null"); } if (userId == null) { throw new Exception("userId == null"); } var eventType = GetEventTypeById(eventTypeId.Value); var defectService = CurrentAccountDbContext.GetDefectService(); var createUser = GetUserById(CurrentUser.Id); var responsibleUser = GetUserById(userId.Value); var defect = defectService.GetOrCreateDefectForEventType(CurrentUser.AccountId, eventType, createUser, responsibleUser, comment); CurrentAccountDbContext.SaveChanges(); return(GetSuccessJsonResponse(new { defectId = defect.Id })); }
public ActionResult Delete(DeleteConfirmationSmartModel model) { try { // TODO Удаление подписок нужно делать через Диспетчер var repository = CurrentAccountDbContext.GetSubscriptionRepository(); var subscription = repository.GetById(model.Id); CheckEditingPermissions(subscription); var subscriptionService = new SubscriptionService(DbContext); subscriptionService.Remove(CurrentUser.AccountId, subscription); CurrentAccountDbContext.SaveChanges(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public ActionResult Add(Guid?componentId = null) { // зарегистрируем дефолтный тип пльзовательской проверки // чтобы в выпадающем списке всегда была хотя был хотя бы один тип пользовательской проверки var dispatcher = GetDispatcherClient(); dispatcher.GetOrCreateUnitTestType(CurrentUser.AccountId, new GetOrCreateUnitTestTypeRequestData() { SystemName = "CustomUnitTestType", DisplayName = "Пользовательская проверка" }); var model = new UnitTestAddModel(); if (componentId.HasValue) { var componentRepository = CurrentAccountDbContext.GetComponentRepository(); var component = componentRepository.GetById(componentId.Value); model.ComponentId = component.Id; } return(View(model)); }
public ActionResult Edit(EditLogModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } var repository = CurrentAccountDbContext.GetLogConfigRepository(); var config = repository.GetByComponentId(model.Id); model.ComponentName = config.Component.DisplayName; config.IsFatalEnabled = model.IsFatalEnabled; config.IsErrorEnabled = model.IsErrorEnabled; config.IsWarningEnabled = model.IsWarningEnabled; config.IsInfoEnabled = model.IsInfoEnabled; config.IsDebugEnabled = model.IsDebugEnabled; config.IsTraceEnabled = model.IsTraceEnabled; config.LastUpdateDate = Now(); CurrentAccountDbContext.SaveChanges(); return(GetSuccessJsonResponse()); }