private async Task UpdateSagaAsync( ISaga saga, IDomainEvent domainEvent, SagaDetails details, CancellationToken cancellationToken) { if (saga.State == SagaState.Completed) { _log.Debug(() => string.Format( "Saga '{0}' is completed, skipping processing of '{1}'", details.SagaType.PrettyPrint(), domainEvent.EventType.PrettyPrint())); return; } if (saga.State == SagaState.New && !details.IsStartedBy(domainEvent.EventType)) { _log.Debug(() => string.Format( "Saga '{0}' isn't started yet and not started by '{1}', skipping", details.SagaType.PrettyPrint(), domainEvent.EventType.PrettyPrint())); return; } var sagaUpdaterType = typeof(ISagaUpdater <, , ,>).MakeGenericType( domainEvent.AggregateType, domainEvent.IdentityType, domainEvent.EventType, details.SagaType); var sagaUpdater = (ISagaUpdater)_resolver.Resolve(sagaUpdaterType); await _sagaUpdateLog.BeforeUpdateAsync( saga, domainEvent, details, cancellationToken) .ConfigureAwait(false); try { await sagaUpdater.ProcessAsync( saga, domainEvent, SagaContext.Empty, cancellationToken) .ConfigureAwait(false); await _sagaUpdateLog.UpdateSucceededAsync( saga, domainEvent, details, cancellationToken) .ConfigureAwait(false); } catch (Exception e) { if (!await _sagaUpdateLog.HandleUpdateFailedAsync( saga, domainEvent, details, e, cancellationToken) .ConfigureAwait(false)) { throw; } } }
private async Task UpdateSagaAsync( ISaga saga, IDomainEvent domainEvent, SagaDetails details, CancellationToken cancellationToken) { if (saga.State == SagaState.Completed) { _logger.LogTrace( "Saga {SagaType} is completed, skipping processing of {DomainEventType}", details.SagaType.PrettyPrint(), domainEvent.EventType.PrettyPrint()); return; } if (saga.State == SagaState.New && !details.IsStartedBy(domainEvent.EventType)) { _logger.LogTrace( "Saga {SagaType} isn't started yet and not started by {DomainEventType}, skipping", details.SagaType.PrettyPrint(), domainEvent.EventType.PrettyPrint()); return; } var sagaUpdaterType = typeof(ISagaUpdater <, , ,>).MakeGenericType( domainEvent.AggregateType, domainEvent.IdentityType, domainEvent.EventType, details.SagaType); var sagaUpdater = (ISagaUpdater)_serviceProvider.GetRequiredService(sagaUpdaterType); await _sagaUpdateLog.BeforeUpdateAsync( saga, domainEvent, details, cancellationToken) .ConfigureAwait(false); try { await sagaUpdater.ProcessAsync( saga, domainEvent, SagaContext.Empty, cancellationToken) .ConfigureAwait(false); await _sagaUpdateLog.UpdateSucceededAsync( saga, domainEvent, details, cancellationToken) .ConfigureAwait(false); } catch (Exception e) { if (!await _sagaUpdateLog.HandleUpdateFailedAsync( saga, domainEvent, details, e, cancellationToken) .ConfigureAwait(false)) { throw; } } }