private async Task SendToInstance <T>(ConsumeContext <T> context, ISagaPolicy <TSaga, T> policy, IPipe <SagaConsumeContext <TSaga, T> > next, TSaga instance) 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 V2DynamoDbEventStoreSagaConsumeContext <TSaga, T>(_connection, context, instance, _options); await policy.Existing(sagaConsumeContext, next).ConfigureAwait(false); if (!sagaConsumeContext.IsCompleted) { await _connection.SaveEventsAsync(instance, _options); } } catch (SagaException sagaException) { if (Log.IsDebugEnabled) { Log.Error(sagaException.Message, 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 instance = context.Saga; if (Log.IsDebugEnabled) { Log.DebugFormat("SAGA:{0}:{1} Added {2}", TypeMetadataCache <TSaga> .ShortName, instance.CorrelationId, TypeMetadataCache <TMessage> .ShortName); } SagaConsumeContext <TSaga, TMessage> proxy = new V2DynamoDbEventStoreSagaConsumeContext <TSaga, TMessage>(_connection, context, instance, _options); await _next.Send(proxy).ConfigureAwait(false); if (!proxy.IsCompleted) { await _connection.SaveEventsAsync(instance, _options); } }