Пример #1
0
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            ExecutionContext executionContext = new ExecutionContext();
            ISessionContext  sessionContext   = null;
            IController      controller       = null;

            try
            {
                ControllerCreateParams controllerConfig = ControllerBag.Get(controllerName);
                FillExecutionContext(executionContext, requestContext, controllerConfig);
                string token       = String.Empty;
                string tranAccount = string.Empty;
                if (requestContext.HttpContext.Request.IsAjaxRequest())
                {
                    token       = HttpContext.Current.Request.Headers[TOKEN];
                    tranAccount = HttpContext.Current.Request.Headers[TRANACCOUNT];
                }
                else
                {
                    token       = HttpContext.Current.Request.Params[TOKEN];
                    tranAccount = HttpContext.Current.Request.Params[TRANACCOUNT];
                }
                sessionContext = Validate(token);

                if (sessionContext != null || controllerConfig.AllowAnonymous)
                {
                    //if (AuthenticateCommand(sessionContext, controllerConfig.TaskCode, controllerConfig.AllowAnonymous))
                    //{
                    SetCulture(sessionContext);
                    dynamic command = Activator.CreateInstance(controllerConfig.CommandType);

                    command.TaskId      = controllerConfig.TaskId;
                    command.TranAccount = tranAccount;

                    object resultBuilder = ActionResultBuilderFactory.Create(controllerConfig.ResultBuilder, controllerConfig.ViewName);
                    controller = Activator.CreateInstance(controllerConfig.ControllerType, executionContext, sessionContext, command, resultBuilder) as System.Web.Mvc.Controller;
                    //}
                    //else
                    //{
                    //    throw new FrameworkException(3, "User not authorized to perform this action.");
                    //}
                }
                else if (sessionContext == null && !controllerConfig.AllowAnonymous && !String.IsNullOrEmpty(token))
                {
                    //HttpContext.Current.Response.Redirect("/common_login_logout/Process");
                    throw new FrameworkException(2, "Session expired.");
                }
            }
            catch (FrameworkException exception)
            {
                ControllerConfigurator.utilityProvider.GetLogger().LogFatal("ControllerFactory.CreateController", exception);
                controller = GetExceptionController(exception, executionContext, sessionContext);
            }
            catch (Exception exception)
            {
                ControllerConfigurator.utilityProvider.GetLogger().LogFatal("ControllerFactory.CreateController", exception);
                throw exception;
            }
            return(controller);
        }
Пример #2
0
        public ActionResult BuildException(IExceptionConfig exceptionConfig)
        {
            string viewName = ((ViewException)exceptionConfig).ViewName;
            IActionResultBuilder resultBuilder = ActionResultBuilderFactory.Create(exceptionConfig.ResponseType, viewName);

            return(resultBuilder.Build(exceptionConfig.ErrorData));
        }
Пример #3
0
        public ActionResult BuildException(IExceptionConfig exceptionConfig)
        {
            JsonErrorMessage exceptionMessage = new JsonErrorMessage()
            {
                Message = (exceptionConfig as JsonException).ErrorData.ToString(), ActionCommand = (exceptionConfig as JsonException).ActionConfig
            };
            IActionResultBuilder resultBuilder = ActionResultBuilderFactory.Create(ResponseType, null);

            return(resultBuilder.Build(exceptionMessage));
        }
Пример #4
0
        private IController GetExceptionController(FrameworkException exception, ExecutionContext executionContext, ISessionContext sessionContext)
        {
            System.Web.Mvc.Controller controller      = null;
            IExceptionConfig          exceptionConfig = ExceptionBag.Get(exception.ErrorId.ToString());
            object command        = Activator.CreateInstance(typeof(HandledExceptionCommand), exception);
            object resultBuilder  = ActionResultBuilderFactory.Create(exceptionConfig.ResponseType, null);
            Type   controllerType = typeof(Requestor <,>).MakeGenericType(
                new Type[] { typeof(HandledExceptionCommand), typeof(JsonErrorMessage) });
            ISafeBlockProvider safeBlockProvider = ControllerConfigurator.utilityProvider.GetSafeBlockProvider();

            executionContext.SafeActionBlock = safeBlockProvider.Create("UIDefault");
            controller = Activator.CreateInstance(controllerType, executionContext, sessionContext, command, resultBuilder) as System.Web.Mvc.Controller;
            return(controller);
        }