Beispiel #1
0
        protected override async Task <CommandBusResult> EnqueueInternalAsync(ICommand cmd)
        {
            Precondition.For(cmd, nameof(cmd)).IsValidCommand();
            CommandBusResult result = await HandleCommand(cmd);

            return(result);
        }
Beispiel #2
0
        public Task <CommandBusResult> EnqueueAsync(ICommand cmd)
        {
            Precondition.For(cmd, nameof(cmd)).IsValidCommand();

            if (condition == null || condition(cmd))
            {
                return(EnqueueInternalAsync(cmd));
            }

            return(Task.FromResult(CommandBusResult.Filtered()));
        }
Beispiel #3
0
        public Task <CommandBusResult> EnqueueAsync(ICommand cmd)
        {
            Precondition.For(cmd, nameof(cmd)).IsValidCommand();

            var type = cmd.GetType();

            if (condition == null || condition(cmd))
            {
                logger.LogTrace("Sending \"{type}\" command.", type);
                return(EnqueueInternalAsync(cmd));
            }

            logger.LogTrace("Command \"{type}\" not set due to filter.", type);
            return(Task.FromResult(CommandBusResult.Filtered()));
        }
Beispiel #4
0
        private async Task <CommandBusResult> HandleCommand(ICommand cmd)
        {
            CommandBusResult result;

            try
            {
                await handler.ExecuteAsync(cmd);

                result = CommandBusResult.Succeeded();
            }
            catch (Exception err)
            {
                Debug.WriteLine($"Error handling command \"{cmd.GetType().Name}\" - {err.Message}");
                result = CommandBusResult.Failed(err);
            }

            return(result);
        }
        private async Task <CommandBusResult> HandleCommand(ICommand cmd)
        {
            CommandBusResult result;

            try
            {
                await handler.ExecuteAsync(cmd);

                result = CommandBusResult.Succeeded();
            }
            catch (Exception err)
            {
                var type = cmd.GetType();
                var msg  = err.Message;
                logger.LogError(err, "Error handling command \"{type}\" - {msg}", type, msg);

                result = CommandBusResult.Failed(err);
            }

            return(result);
        }