public async Task Send(SagaConsumeContext <TInstance, TData> context, IPipe <SagaConsumeContext <TInstance, TData> > next)
        {
            var eventContext = new StateMachineEventContext <TInstance, TData>(_machine, context.Saga, _event, context.Message, context.CancellationToken);

            eventContext.GetOrAddPayload(() => context);
            eventContext.GetOrAddPayload(() => (ConsumeContext <TData>)context);
            eventContext.GetOrAddPayload(() => (ConsumeContext)context);

            State <TInstance> currentState = await _machine.Accessor.Get(eventContext).ConfigureAwait(false);

            IEnumerable <Event> nextEvents = _machine.NextEvents(currentState);

            if (nextEvents.Contains(_event))
            {
                await _machine.RaiseEvent(eventContext).ConfigureAwait(false);

                if (_machine.IsCompleted(context.Saga))
                {
                    await context.SetCompleted().ConfigureAwait(false);
                }
            }
            else
            {
                throw new NotAcceptedStateMachineException(typeof(TInstance), typeof(TData), context.CorrelationId ?? Guid.Empty, currentState.Name);
            }
        }
Ejemplo n.º 2
0
        public async Task Send(SagaConsumeContext <TInstance, TData> context, IPipe <SagaConsumeContext <TInstance, TData> > next)
        {
            var eventContext = new StateMachineEventContextProxy <TInstance, TData>(context, _machine, context.Saga, _event, context.Message);

            var activity = LogContext.IfEnabled(OperationName.Saga.RaiseEvent)
                           ?.StartSagaActivity(context, (await _machine.Accessor.Get(eventContext).ConfigureAwait(false)).Name);

            try
            {
                await _machine.RaiseEvent(eventContext).ConfigureAwait(false);

                if (await _machine.IsCompleted(context.Saga).ConfigureAwait(false))
                {
                    await context.SetCompleted().ConfigureAwait(false);
                }
            }
            catch (UnhandledEventException ex)
            {
                var currentState = await _machine.Accessor.Get(eventContext).ConfigureAwait(false);

                throw new NotAcceptedStateMachineException(typeof(TInstance), typeof(TData), context.CorrelationId ?? Guid.Empty, currentState.Name, ex);
            }
            finally
            {
                activity?.AddTag(DiagnosticHeaders.EndState, (await _machine.Accessor.Get(eventContext).ConfigureAwait(false)).Name);
                activity?.Stop();
            }
        }
Ejemplo n.º 3
0
        public async Task Send(SagaConsumeContext <TInstance, TData> context, IPipe <SagaConsumeContext <TInstance, TData> > next)
        {
            var eventContext = new StateMachineEventContext <TInstance, TData>(context, _machine, context.Saga, _event, context.Message);

            eventContext.GetOrAddPayload(() => context);
            eventContext.GetOrAddPayload(() => (ConsumeContext <TData>)context);
            eventContext.GetOrAddPayload(() => (ConsumeContext)context);

            State <TInstance> currentState = await _machine.Accessor.Get(eventContext).ConfigureAwait(false);

            try
            {
                await _machine.RaiseEvent(eventContext).ConfigureAwait(false);

                if (_machine.IsCompleted(context.Saga))
                {
                    await context.SetCompleted().ConfigureAwait(false);
                }
            }
            catch (UnhandledEventException ex)
            {
                throw new NotAcceptedStateMachineException(typeof(TInstance), typeof(TData), context.CorrelationId ?? Guid.Empty, currentState.Name, ex);
            }
        }
 public Task SetCompleted()
 {
     return(_context.SetCompleted());
 }
Ejemplo n.º 5
0
 Task SagaConsumeContext <TSaga> .SetCompleted()
 {
     return(_context.SetCompleted());
 }