示例#1
0
        static async Task SendToInstance <T>(ConsumeContext <T> context,
                                             ISagaPolicy <TSaga, T> policy, TSaga instance,
                                             IPipe <SagaConsumeContext <TSaga, T> > next, IDocumentSession session)
            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 MartenSagaConsumeContext <TSaga, T>(session, context, instance);

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

                if (!sagaConsumeContext.IsCompleted)
                {
                    session.Store(instance);
                    session.SaveChanges();
                }
            }
            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,
                                      ISagaPolicy <TSaga, T> policy, TSaga instance,
                                      IPipe <SagaConsumeContext <TSaga, T> > next, IDocumentSession session)
            where T : class
        {
            var sagaConsumeContext = new MartenSagaConsumeContext <TSaga, T>(session, context, instance);

            try
            {
                sagaConsumeContext.LogUsed();

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

                if (!sagaConsumeContext.IsCompleted)
                {
                    await session.SaveChangesAsync().ConfigureAwait(false);
                }
            }
            catch (SagaException sex)
            {
                sagaConsumeContext.LogFault(sex);

                throw;
            }
            catch (Exception ex)
            {
                sagaConsumeContext.LogFault(ex);

                throw new SagaException(ex.Message, typeof(TSaga), typeof(T), instance.CorrelationId, ex);
            }
        }
            public async Task Send(SagaConsumeContext <TSaga, TMessage> context)
            {
                SagaConsumeContext <TSaga, TMessage> proxy = new MartenSagaConsumeContext <TSaga, TMessage>(_session, context, context.Saga);

                proxy.LogAdded();

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

                if (!proxy.IsCompleted)
                {
                    _session.Store(context.Saga);
                    await _session.SaveChangesAsync().ConfigureAwait(false);
                }
            }
示例#4
0
            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);
                }

                SagaConsumeContext <TSaga, TMessage> proxy = new MartenSagaConsumeContext <TSaga, TMessage>(_session,
                                                                                                            context, context.Saga);

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

                if (!proxy.IsCompleted)
                {
                    _session.Store(context.Saga);
                    _session.SaveChanges();
                }
            }