Exemplo n.º 1
0
        async Task SendToInstance <T>(ConsumeContext <T> context, SqlConnection sqlConnection, ISagaPolicy <TSaga, T> policy, TSaga instance, string tableName,
                                      IPipe <SagaConsumeContext <TSaga, T> > next)
            where T : class
        {
            try
            {
                var sagaConsumeContext = new DapperSagaConsumeContext <TSaga, T>(sqlConnection, context, instance, tableName);

                sagaConsumeContext.LogUsed();

                await policy.Existing(sagaConsumeContext, next).ConfigureAwait(false);

                if (!sagaConsumeContext.IsCompleted)
                {
                    await UpdateSagaInstance(sqlConnection, instance).ConfigureAwait(false);
                }
            }
            catch (SagaException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SagaException(ex.Message, typeof(TSaga), typeof(T), instance.CorrelationId, ex);
            }
        }