示例#1
0
        private async Task DispatchEventsToBeProcessed(CancellationToken cancellationToken)
        {
            var eventId = Guid.Empty;

            try
            {
                _logger.Debug("About to dispatch EventsToBeProcessed...");
                foreach (var @event in _eventBag.EventsToBeProcessed.ToList())
                {
                    eventId = @event.Id;
                    _logger.Debug($"Publishing event. Id: {@event.Id} SourceType: {@event.SourceTypeName}");
                    await _eventDispatcher.DispatchAsync(@event, cancellationToken);

                    _eventBag.EventsToBeProcessed.Remove(@event);

                    if (_cqrsOptions.PurgeEventsToBeProcessed)
                    {
                        await PurgeEvent(@event, cancellationToken);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Dispatching failed. Id: {eventId}");
                _logger.Error(ex);
            }
        }
示例#2
0
        private TResponse ExecuteInterceptors <TResponse>(IRequest <TResponse> request,
                                                          Func <IRequest <TResponse>, TResponse> handle)
        {
            _logger.Debug("Running Interceptors...");
            var next = _interceptors.Reverse().Aggregate(handle,
                                                         (handleDelegate, interceptor) => (req) => interceptor.Run <IRequest <TResponse>, TResponse>(req, handleDelegate));

            try
            {
                return(next.Invoke(request));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
            finally
            {
                _interceptors.ToList().ForEach(m => m.Dispose());
            }
        }
示例#3
0
        private async Task <TResponse> ExecuteInterceptorsAsync <TResponse>(IRequest <TResponse> request,
                                                                            Func <IRequest <TResponse>, CancellationToken, Task <TResponse> > handleAsync, CancellationToken cancellationToken)
        {
            _logger.Debug("Running Interceptors...");
            var next = _interceptors.Reverse().Aggregate(handleAsync,
                                                         (handleDelegate, interceptor) => (req, token) => interceptor.RunAsync(req, token, handleDelegate));

            try
            {
                return(await next.Invoke(request, cancellationToken).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
            finally
            {
                _interceptors.ToList().ForEach(m => m.Dispose());
            }
        }