Exemplo n.º 1
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            string[] actionParts = command?.Action.Split('.');

            if (actionParts == null || actionParts.Length != 2)
            {
                return(command.CreateExceptionResponse <ExecuteResponse>(
                           new FormatException("Wrong format of action name.")));
            }

            string actionHandlerName = actionParts[0];
            string actionName        = actionParts[1];

            Type actionHandlerType = actionMapper.GetHandler(actionHandlerName);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(actionName, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       new UnauthorizedException("User is not allowed to execute actions of this handler")));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       new UnauthorizedException("User is not allowed to execute action")));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>(new HandlerNotFoundException()));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>(new ActionNotFoundException()));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>(new ActionHandlerNotFoundException()));
        }
Exemplo n.º 2
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            string[] actionParts = command?.Action.Split('.');

            if (actionParts == null || actionParts.Length != 2)
            {
                return(command.CreateExceptionResponse <ExecuteResponse>("The format the action name was false."));
            }

            string actionHandlerName = actionParts[0];
            string actionName        = actionParts[1];

            Type actionHandlerType = actionMapper.GetHandler(actionHandlerName);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(actionName, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       "User is not allowed to execute actions of this handler."));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>("User is not allowed to execute action."));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>("No handler was found."));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>("No action to execute was found."));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>("No action handler type was matching"));
        }
Exemplo n.º 3
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            Type actionHandlerType = actionMapper.GetHandler(command);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(command, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       "User is not allowed to execute actions of this handler."));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>("User is not allowed to execute action."));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>("No handler was found."));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>("No action to execute was found."));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>("No action handler type was matching"));
        }