Exemple #1
0
        private 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(Task.FromResult(0));
            }

            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(Task.FromResult(0));
            }

            var sagaUpdaterType = typeof(ISagaUpdater <, , ,>).MakeGenericType(
                domainEvent.AggregateType,
                domainEvent.IdentityType,
                domainEvent.EventType,
                details.SagaType);
            var sagaUpdater = (ISagaUpdater)_resolver.Resolve(sagaUpdaterType);

            return(sagaUpdater.ProcessAsync(
                       saga,
                       domainEvent,
                       SagaContext.Empty,
                       cancellationToken));
        }