예제 #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 static void Configure(IConfigService configService, IUtilityProvider _utilityProvider, IResourceService _iResourceSerive)
        {
            utilityProvider  = _utilityProvider;
            iResourceService = _iResourceSerive;
            /*Call LoadCommandConfig Method to Load all the Command Configuration through ConfigService.*/
            IEnumerable <CommandConfig>       commands         = configService.Get <CommandConfig>("CommandTypeConfig");
            IEnumerable <CommandActionConfig> actionConfigList = configService.Get <CommandActionConfig>("CommandActionTypeConfig");

            foreach (CommandActionConfig actionConfig in actionConfigList)
            {
                ControllerCreateParams controllerConfig = new ControllerCreateParams();
                controllerConfig.Name            = actionConfig.ActionKey;
                controllerConfig.AllowAnonymous  = actionConfig.AllowAnonymous;
                controllerConfig.ExceptionPolicy = actionConfig.ExceptionPolicy;
                controllerConfig.TaskId          = actionConfig.TaskId;
                CommandConfig cmd = commands.Where <CommandConfig>(o => o.CommandKey == actionConfig.CommandConfig).FirstOrDefault();
                if (cmd != null)
                {
                    Type commandType = Type.GetType(cmd.CommandUri);
                    controllerConfig.CommandType = commandType;


                    if (commandType != null)
                    {
                        while (commandType.Name != typeof(ProcessCommand <,>).Name && commandType.Name != typeof(ParameterizedActionCommand <>).Name && commandType.Name != typeof(RequestCommand <>).Name && commandType.Name != typeof(ExecutorCommand).Name)
                        {
                            commandType = commandType.BaseType;
                        }

                        Type[] param = commandType.GetGenericArguments();

                        if (commandType.Name == typeof(ProcessCommand <,>).Name)
                        {
                            controllerConfig.RequestViewModel = param[0];
                            controllerConfig.ReponseViewModel = param[1];
                            controllerConfig.ControllerType   = typeof(Processor <, ,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.RequestViewModel, controllerConfig.ReponseViewModel });
                        }
                        else if (commandType.Name == typeof(ParameterizedActionCommand <>).Name)
                        {
                            controllerConfig.RequestViewModel = param[0];
                            controllerConfig.ControllerType   = typeof(ParamterizedExecutor <,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.RequestViewModel });
                        }
                        else if (commandType.Name == typeof(RequestCommand <>).Name)
                        {
                            controllerConfig.ReponseViewModel = param[0];
                            controllerConfig.ControllerType   = typeof(Requestor <,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.ReponseViewModel });
                        }
                        else if (commandType.Name == typeof(ExecutorCommand).Name)
                        {
                            controllerConfig.ControllerType = typeof(Executor <>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType });
                        }


                        controllerConfig.DivId    = actionConfig.RefreshDiv;
                        controllerConfig.ViewName = actionConfig.ViewName;
                        ResultType result;
                        Enum.TryParse(actionConfig.ResultType, out result);
                        controllerConfig.ResultBuilder = result;
                        ControllerBag.Add(controllerConfig.Name, controllerConfig);
                    }
                    else
                    {
                        utilityProvider.GetLogger().LogFatal("Controller Configurator", 9000);
                    }
                }
                else
                {
                    utilityProvider.GetLogger().LogFatal("Controller Configurator", 9001);
                }
            }
        }
예제 #3
0
 internal static void Add(String name, ControllerCreateParams @params)
 {
     _nameCreateParamMap.Add(name, @params);
 }
예제 #4
0
 private IExecutionContext FillExecutionContext(ExecutionContext _executionContext, RequestContext requestContext, ControllerCreateParams controllerConfig)
 {
     if (!String.IsNullOrEmpty(controllerConfig.DivId))
     {
         _executionContext.ResponseHeader.Add(Constants.REFRESHDIV, controllerConfig.DivId);
     }
     ISafeBlockProvider safeBlockProvider = ControllerConfigurator.utilityProvider.GetSafeBlockProvider();
     _executionContext.SafeActionBlock = safeBlockProvider.Create(controllerConfig.ExceptionPolicy);
     return _executionContext;
 }
예제 #5
0
 internal static void Add(String name,ControllerCreateParams @params)
 {
     _nameCreateParamMap.Add(name, @params);
 }
예제 #6
0
        private IExecutionContext FillExecutionContext(ExecutionContext _executionContext, RequestContext requestContext, ControllerCreateParams controllerConfig)
        {
            if (!String.IsNullOrEmpty(controllerConfig.DivId))
            {
                _executionContext.ResponseHeader.Add(Constants.REFRESHDIV, controllerConfig.DivId);
            }
            ISafeBlockProvider safeBlockProvider = ControllerConfigurator.utilityProvider.GetSafeBlockProvider();

            _executionContext.SafeActionBlock = safeBlockProvider.Create(controllerConfig.ExceptionPolicy);
            return(_executionContext);
        }
예제 #7
0
        public static void Configure(IConfigService configService, IUtilityProvider _utilityProvider, IResourceService _iResourceSerive)
        {
            utilityProvider = _utilityProvider;
            iResourceService = _iResourceSerive;
            /*Call LoadCommandConfig Method to Load all the Command Configuration through ConfigService.*/
            IEnumerable<CommandConfig> commands = configService.Get<CommandConfig>("CommandTypeConfig");
            IEnumerable<CommandActionConfig> actionConfigList = configService.Get<CommandActionConfig>("CommandActionTypeConfig");

            foreach (CommandActionConfig actionConfig in actionConfigList)
            {
                ControllerCreateParams controllerConfig = new ControllerCreateParams();
                controllerConfig.Name = actionConfig.ActionKey;
                controllerConfig.AllowAnonymous = actionConfig.AllowAnonymous;
                controllerConfig.ExceptionPolicy = actionConfig.ExceptionPolicy;
                controllerConfig.TaskId = actionConfig.TaskId;
                CommandConfig cmd = commands.Where<CommandConfig>(o => o.CommandKey == actionConfig.CommandConfig).FirstOrDefault();
                if (cmd != null)
                {
                    Type commandType = Type.GetType(cmd.CommandUri);
                    controllerConfig.CommandType = commandType;


                    if (commandType != null)
                    {
                        while (commandType.Name != typeof(ProcessCommand<,>).Name && commandType.Name != typeof(ParameterizedActionCommand<>).Name && commandType.Name != typeof(RequestCommand<>).Name && commandType.Name != typeof(ExecutorCommand).Name)
                        {
                            commandType = commandType.BaseType;
                        }

                        Type[] param = commandType.GetGenericArguments();

                        if (commandType.Name == typeof(ProcessCommand<,>).Name)
                        {
                            controllerConfig.RequestViewModel = param[0];
                            controllerConfig.ReponseViewModel = param[1];
                            controllerConfig.ControllerType = typeof(Processor<,,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.RequestViewModel, controllerConfig.ReponseViewModel });
                        }
                        else if (commandType.Name == typeof(ParameterizedActionCommand<>).Name)
                        {
                            controllerConfig.RequestViewModel = param[0];
                            controllerConfig.ControllerType = typeof(ParamterizedExecutor<,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.RequestViewModel });
                        }
                        else if (commandType.Name == typeof(RequestCommand<>).Name)
                        {
                            controllerConfig.ReponseViewModel = param[0];
                            controllerConfig.ControllerType = typeof(Requestor<,>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType, controllerConfig.ReponseViewModel });
                        }
                        else if (commandType.Name == typeof(ExecutorCommand).Name)
                        {
                            controllerConfig.ControllerType = typeof(Executor<>).MakeGenericType(
                                new Type[] { controllerConfig.CommandType });
                        }


                        controllerConfig.DivId = actionConfig.RefreshDiv;
                        controllerConfig.ViewName = actionConfig.ViewName;
                        ResultType result;
                        Enum.TryParse(actionConfig.ResultType, out result);
                        controllerConfig.ResultBuilder = result;
                        ControllerBag.Add(controllerConfig.Name, controllerConfig);
                    }
                    else
                    {
                        utilityProvider.GetLogger().LogFatal("Controller Configurator", 9000);
                    }
                }
                else
                {
                    utilityProvider.GetLogger().LogFatal("Controller Configurator", 9001);
                }
            }
        }