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
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("SAGA:{0}:{1} Used {2}", TypeMetadataCache <TSaga> .ShortName, instance.CorrelationId, TypeMetadataCache <T> .ShortName);
                }

                var sagaConsumeContext = new DapperSagaConsumeContext <TSaga, T>(sqlConnection, context, instance, tableName);

                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);
            }
        }
        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);
            }
        }
            public async Task Send(SagaConsumeContext <TSaga, TMessage> context)
            {
                var sagaConsumeContext = new DapperSagaConsumeContext <TSaga, TMessage>(_sqlConnection, context, context.Saga, _tableName, false);

                sagaConsumeContext.LogAdded();

                await _next.Send(sagaConsumeContext).ConfigureAwait(false);

                if (!sagaConsumeContext.IsCompleted)
                {
                    await _insertSagaInstance(_sqlConnection, context.Saga).ConfigureAwait(false);
                }
            }
            public async Task Send(SagaConsumeContext <TSaga, TMessage> context)
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("SAGA:{0}:{1} Added {2}", TypeMetadataCache <TSaga> .ShortName,
                                    context.Saga.CorrelationId,
                                    TypeMetadataCache <TMessage> .ShortName);
                }

                var sagaConsumeContext = new DapperSagaConsumeContext <TSaga, TMessage>(_sqlConnection, context, context.Saga, _tableName, false);

                await _next.Send(sagaConsumeContext).ConfigureAwait(false);

                if (!sagaConsumeContext.IsCompleted)
                {
                    await _insertSagaInstance(_sqlConnection, context.Saga).ConfigureAwait(false);
                }
            }