Ejemplo n.º 1
0
        public CommandExecutionResult CheckContext(IBaseCommand command)
        {
            var result = new CommandExecutionResult(this.teclyn);

            this.CheckContextInternal(command, result);

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <ICommandResult> Execute <TCommand>(TCommand command) where TCommand : ICommand
        {
            var commandHandler = this._dependencyResolver.Get <ICommandHandler <TCommand> >();
            var result         = new CommandExecutionResult(this._dependencyResolver);

            var success = await commandHandler.CheckContext(command, this._context, result) &&
                          await commandHandler.CheckParameters(command, result) &&
                          await this.ExecuteCommandHandler(command, commandHandler, result);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <ICommandResult <TResult> > ExecuteInternal <TCommand, TResult>(TCommand command,
                                                                                          Func <TCommand, TResult> resultAccessor) where TCommand : IBaseCommand
        {
            var result = new CommandExecutionResult <TResult>(teclyn);

            this.CheckContextInternal(command, result);
            this.CheckParametersInternal(command, result);

            if (!result.Errors.Any())
            {
                // execute
                await command.Execute(result);

                // get result
                result.Result = resultAccessor(command);

                result.SetSuccess();
            }

            return(result);
        }
Ejemplo n.º 4
0
 public UserFriendlyCommandResult(CommandExecutionResult result)
 {
     this.Success = result.Success;
     this.Errors  = result.Errors.ToArray();
 }
Ejemplo n.º 5
0
 private void CheckContextInternal(IBaseCommand command, CommandExecutionResult result)
 {
     result.ContextIsValid = command.CheckContext(context, result);
 }
Ejemplo n.º 6
0
 private void CheckParametersInternal(IBaseCommand command, CommandExecutionResult result)
 {
     result.ParametersAreValid = command.CheckParameters(result);
 }
Ejemplo n.º 7
0
        private async Task <bool> ExecuteCommandHandler <TCommand>(TCommand command, ICommandHandler <TCommand> commandHandler, CommandExecutionResult result) where TCommand : ICommand
        {
            try
            {
                await commandHandler.Execute(command, result);

                result.SetSuccess();

                return(true);
            }
            catch (Exception exception)
            {
                result.SetFailure(exception.ToString());

                return(false);
            }
        }