public async Task HandleAsync(T message, ICommandActions actions) { try { AddTelemetryProperties(message); await ProcessAsync(message, actions).ConfigureAwait(false); } catch (CommandPreviouslyProcessedException) when(message.CorrelationId.HasValue) { await _correlationEventHandler.Handle(new CommandPreviouslyProcessedEvent { MessageId = message.MessageId, AggregateRootId = message.AggregateRootId, CorrelationId = message.CorrelationId }).ConfigureAwait(false); } catch (AggregateException exceptions) { var userId = (Guid?)typeof(T).GetProperty("UserId")?.GetValue(message); await _bus.PublishAsync(new TCommandErrorEvent { Id = message.AggregateRootId, CommandMessageId = message.MessageId, CommandName = typeof(T).Name, EventDate = _dateTime.UtcNow, Errors = exceptions.InnerExceptions.Select(x => x.Message).ToList(), UserId = userId }).ConfigureAwait(false); if (exceptions.InnerExceptions.Any(IsExceptionToBeRethrown)) { _exceptionLogger.Log(exceptions); throw; } } catch (Exception ex) { var userId = (Guid?)typeof(T).GetProperty("UserId")?.GetValue(message); await _bus.PublishAsync(new TCommandErrorEvent { Id = message.AggregateRootId, CommandMessageId = message.MessageId, CommandName = typeof(T).Name, EventDate = _dateTime.UtcNow, Errors = new List <string> { ex.Message }, UserId = userId }).ConfigureAwait(false); if (IsExceptionToBeRethrown(ex)) { _exceptionLogger.Log(ex); throw; } } }
public async Task HandleAsync(T evt) { try { await ProcessAsync(evt).ConfigureAwait(false); if (evt is ICorrelationEvent correlationEvent) { await _correlationEventHandler.Handle(correlationEvent).ConfigureAwait(false); } } catch (Exception ex) { _exceptionLogger.Log(ex); throw; } }
public async Task HandleAsync(T evt, IEventActions eventActions) { try { AddTelemetryProperties(evt); await ProcessAsync(evt, eventActions).ConfigureAwait(false); if (evt is ICorrelationEvent correlationEvent) { await _correlationEventHandler.Handle(correlationEvent).ConfigureAwait(false); } } catch (Exception ex) { _exceptionLogger.Log(ex); throw; } }