示例#1
0
        public CommandResult Send <TCommand>(TCommand command) where TCommand : ICommand
        {
            try
            {
                var innerHandler = (ICommandHandler <TCommand>)
                                   _scope.ResolveOptional(typeof(ICommandHandler <TCommand>));

                if (innerHandler != null)
                {
                    command.Validate();

                    if (command.IsValid)
                    {
                        _innerOkResult = innerHandler.Handle(command);
                        var commandResult = GetCommandResultFromCommandHandlerResult(_innerOkResult);
                        return(commandResult);
                    }
                    else
                    {
                        return(CommandResult.FromValidationErrors(command.ValidationErrorMessges));
                    }
                }

                return(CommandResult.NonExistentCommand(typeof(TCommand).Name));
            }
            catch (SecurityException ex)
            {
                return(new CommandResult(ex, HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                return(new CommandResult(ex, HttpStatusCode.InternalServerError));
            }
        }
        public static CommandHandlerResult OkDelayed <T>(T owner, Func <T, object> delayed)
        {
            var result = new CommandHandlerResult(HttpStatusCode.OK, null);

            result._delayedContent = delayed;

            return(result);
        }
示例#3
0
        private CommandResult GetCommandResultFromCommandHandlerResult(CommandHandlerResult result)
        {
            if (result == CommandHandlerResult.Ok)
            {
                return(CommandResult.Ok);
            }

            var content = result.Content;

            return(new CommandResult(result.StatusCode, content));
        }