public JsonResult Add(AddEventModel model) { try { var component = GetComponentById(model.ComponentId); var client = GetDispatcherClient(); var response = client.SendEvent(CurrentUser.AccountId, new SendEventData() { ComponentId = component.Id, TypeSystemName = model.EventType, TypeDisplayName = model.EventType, Message = model.Message, Importance = model.EventImportance, JoinInterval = (model.JoinInterval != null ? model.JoinInterval.Value.TotalSeconds : (double?)null), Category = EventCategory.ComponentEvent }); response.Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult Enable(Guid id) { try { var client = GetDispatcherClient(); client.SetMetricEnable(CurrentUser.AccountId, id).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult Delete(Guid id, string fake) { try { var client = GetDispatcherClient(); client.DeleteUnitTest(CurrentUser.AccountId, id).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult ChangeImportance(ChangeImportanceModel model) { try { var eventType = GetEventTypeById(model.EventTypeId); if (model.EventTypeId == Guid.Empty) { throw new UserFriendlyException("Не удалось получить ИД типа события"); } if (model.Importance == null) { throw new UserFriendlyException("Не удалось получить важность"); } if (model.Version != null && VersionHelper.FromString(model.Version) == null) { throw new UserFriendlyException("Неверный формат версии"); } var dispatcher = GetDispatcherClient(); var data = new UpdateEventTypeRequestData() { EventId = model.EventId, EventTypeId = model.EventTypeId, DisplayName = eventType.DisplayName, ImportanceForNew = eventType.ImportanceForNew, ImportanceForOld = eventType.ImportanceForOld, OldVersion = eventType.OldVersion, UpdateActualEvents = true }; if (string.IsNullOrEmpty(model.Version)) { data.ImportanceForNew = model.Importance.Value; data.OldVersion = null; } else { data.ImportanceForOld = model.Importance.Value; data.OldVersion = model.Version; } dispatcher.UpdateEventType(CurrentUser.AccountId, data).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
protected override void OnException(ExceptionContext filterContext) { if (filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.HttpContext.Request.IsSmartBlocksRequest()) { MvcApplication.HandleException(filterContext.Exception); filterContext.ExceptionHandled = true; filterContext.Result = GetErrorJsonResponse(filterContext.Exception); return; } string viewName = null; if (filterContext.Exception is ObjectNotFoundException) { viewName = "~/Views/Errors/ObjectNotFoundError.cshtml"; } else if (filterContext.Exception is AccessDeniedException) { viewName = "~/Views/Errors/AccessDeniedError.cshtml"; } else if (filterContext.Exception is UserFriendlyException) { viewName = "~/Views/Errors/UserFriendlyError.cshtml"; } else { viewName = "~/Views/Errors/CommonError.cshtml"; MvcApplication.HandleException(filterContext.Exception); } filterContext.ExceptionHandled = true; var controllerName = (string)filterContext.RouteData.Values["controller"]; var actionName = (string)filterContext.RouteData.Values["action"]; var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName); var result = new ViewResult { ViewName = viewName, ViewData = new ViewDataDictionary <HandleErrorInfo>(model), TempData = filterContext.Controller.TempData }; result.ViewBag.IsChildAction = filterContext.IsChildAction; filterContext.Result = result; }
public ActionResult Delete(Guid id, string fake) { try { var dispatcher = GetDispatcherClient(); var data = new DeleteMetricTypeRequestData() { MetricTypeId = id }; dispatcher.DeleteMetricType(CurrentUser.AccountId, id).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult Delete(Guid id, string fake) { try { var dispatcher = GetDispatcherClient(); var data = new DeleteMetricRequestData() { MetricId = id, UpdateComponentStatus = true }; dispatcher.DeleteMetric(CurrentUser.AccountId, data).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult Disable(DisableDialogPostModel model) { try { var client = GetDispatcherClient(); var date = model.GetDate(); var data = new SetMetricDisableRequestData() { Comment = model.Comment, ToDate = date, MetricId = model.Id }; client.SetMetricDisable(CurrentUser.AccountId, data).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public JsonResult SetActualValue(SetActualValueModel model) { try { var metric = GetMetricById(model.Id); var client = GetDispatcherClient(); // парсим число double?value = null; if (model.Value != null) { try { value = ParseHelper.ParseDouble(model.Value); } catch (Exception) { throw new UserFriendlyException("Не удалось получить число из строки: " + model.Value); } } var data = new SendMetricRequestData() { ComponentId = metric.ComponentId, Name = metric.MetricType.SystemName, Value = value }; if (model.ActualTime.HasValue) { data.ActualIntervalSecs = model.ActualTime.Value.TotalSeconds; } client.SendMetric(CurrentUser.AccountId, data).Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
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 JsonResult SetResult(UnitTestSetResultModel model) { try { var unitTest = GetUnitTestById(model.Id); var client = GetDispatcherClient(); var response = client.SendUnitTestResult(CurrentUser.AccountId, new SendUnitTestResultRequestData() { UnitTestId = unitTest.Id, Result = model.Result, Message = model.Message, ActualIntervalSeconds = model.ActualInterval.TotalSeconds }); response.Check(); return(GetSuccessJsonResponse()); } catch (Exception exception) { MvcApplication.HandleException(exception); return(GetErrorJsonResponse(exception)); } }
public ActionResult Index(string executeJsonCommand) { try { object result = null; if (executeJsonCommand == "getAllComponentsForGuiSelect") { result = GetAllComponentsForGuiSelect(); } if (executeJsonCommand == "createComponent") { result = CreateComponent(); } else { throw new Exception("Неизвестная команда " + executeJsonCommand); } var response = new { success = true, data = result }; //System.Threading.Thread.Sleep(1000 * 10); return(Json(response)); } catch (Exception exception) { MvcApplication.HandleException(exception); var response = new { success = false, error = exception.Message }; return(Json(response)); } }