Example #1
0
        public async Task Publish <T>(T message) where T : class
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(message);
                    }
                    await _eventPublisher.Publish(message);

                    if (_hook?.OnProcessed != null)
                    {
                        _hook.OnProcessed(message);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, message);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _eventPublisher.Publish(message);
            }
        }
Example #2
0
        public async Task Handle(T command, CancellationToken cancellationToken = default)
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }
                    await _handler.Handle(command, cancellationToken);

                    if (_hook?.OnHandled != null)
                    {
                        _hook.OnHandled(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _handler.Handle(command, cancellationToken);
            }
        }
        public async Task HandleAsync(AuthorizationHandlerContext context)
        {
            if (_authContextHook != null)
            {
                try
                {
                    if (_authContextHook?.OnReceived != null)
                    {
                        _authContextHook.OnReceived(context);
                    }
                    await _handler.HandleAsync(context);

                    if (_authContextHook?.OnProcessed != null)
                    {
                        _authContextHook.OnProcessed(context);
                    }
                }
                catch (Exception ex)
                {
                    if (_authContextHook?.OnErrored != null)
                    {
                        _authContextHook.OnErrored(ex, context);
                    }
                    throw;
                }
            }
            else
            {
                await _handler.HandleAsync(context);
            }
        }
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            if (_actionResultHook != null)
            {
                try
                {
                    if (_actionResultHook?.OnReceived != null)
                    {
                        _actionResultHook.OnReceived(context.Result);
                    }
                    await next();

                    if (_actionResultHook?.OnProcessed != null)
                    {
                        _actionResultHook.OnProcessed(context.Result);
                    }
                }
                catch (Exception ex)
                {
                    if (_actionResultHook?.OnErrored != null)
                    {
                        _actionResultHook.OnErrored(ex, context.Result);
                    }
                    throw;
                }
            }
            else
            {
                await next();
            }
        }
        public async Task Publish <T>(T command, CancellationToken cancellationToken = default) where T : class, ICommand
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }
                    await _commandPublisher.Publish(command);

                    if (_hook?.OnPublished != null)
                    {
                        _hook.OnPublished(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _commandPublisher.Publish(command);
            }
        }
        public async Task Send <TCommand>(TCommand command, CancellationToken cancellationToken = default) where TCommand : ICommand
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }

                    await _commandDispatcher.Send(command);

                    if (_hook?.OnProcessed != null)
                    {
                        _hook.OnProcessed(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _commandDispatcher.Send(command);
            }
        }
        public async Task Send <T>(T command, TimeSpan delay, CancellationToken cancellationToken = default(CancellationToken)) where T : class, ICommand
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }

                    await _messageSession.Send(command, delay, cancellationToken);

                    if (_hook?.OnProcessed != null)
                    {
                        _hook.OnProcessed(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _messageSession.Send(command, delay, cancellationToken);
            }
        }