示例#1
0
        public static ISagaStep GetNextStepToExecute(
            this ISagaAction sagaAction,
            ISagaStep step,
            SagaExecutionState sagaState)
        {
            NextStepInfo nextStepForWhile = getNextStepForWhile(sagaAction, step, sagaState);

            if (nextStepForWhile != null)
            {
                return(nextStepForWhile.NextStep);
            }

            NextStepInfo nextStepForIf = getNextStepForIf(sagaAction, step, sagaState);

            if (nextStepForIf != null)
            {
                return(nextStepForIf.NextStep);
            }

            NextStepInfo nextChildStep = getChildNextStep(step);

            if (nextChildStep != null)
            {
                return(nextChildStep.NextStep);
            }

            return(getNextStep(sagaAction, step, sagaState));
        }
示例#2
0
        static bool getResultFromPrevIfElse(
            SagaSteps childSteps,
            ISagaStep step,
            SagaExecutionState sagaState)
        {
            while (true)
            {
                ISagaStep prevStepIf = GetPrevStepSameLevel(childSteps, step.ParentStep, step);
                if (prevStepIf.Is <ISagaStepForIf>())
                {
                    IStepData stepDataIf = sagaState.History.
                                           GetLatestByStepName(prevStepIf.StepName);

                    if (stepDataIf?.ExecutionData?.ConditionResult == true)
                    {
                        return(true);
                    }

                    if (!prevStepIf.Is <ISagaStepForElse>())
                    {
                        return(false);
                    }

                    step = prevStepIf;
                }
                else
                {
                    return(false);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="SagaConsumerOf{TS,TM,TK}"/>.
 /// </summary>
 /// <param name="sagaLifecycle">Управляет жизненным циклом саги.</param>
 /// <param name="sagaStep">Обработчик шага саги.</param>
 /// <param name="canInitiate">Если <c>true</c> - тогда сага может быть создана обработчиком сообщения.</param>
 /// <param name="failedHandler">Обработчик ошибок в саге.</param>
 public SagaConsumerOf(ISagaLifecycle <TS, TM, TK> sagaLifecycle, ISagaStep <TS, TM, TK> sagaStep, bool canInitiate, ISagaFailedHandler <TS, TM, TK> failedHandler)
 {
     this.SagaLifecycle     = sagaLifecycle;
     this.SagaStep          = sagaStep;
     this.CanInitiate       = canInitiate;
     this.SagaFailedHandler = failedHandler;
 }
示例#4
0
        static ISagaStep getNextStepForElse(
            ISagaAction sagaAction,
            ISagaStep step,
            SagaExecutionState sagaState)
        {
            if (step.Is <ISagaStepForElse>())
            {
                bool ifElseResult = getResultFromPrevIfElse(
                    sagaAction.ChildSteps,
                    step,
                    sagaState);

                // jesli if-else jest spelniony to nie wchodzimy juz do niego
                // czyli szukamy kolengo kroku poza if-else
                if (ifElseResult)
                {
                    ISagaStep nextStepAfterIfElse = GetNextStepAfterIfElse(
                        sagaAction.ChildSteps,
                        step);

                    if (nextStepAfterIfElse != null)
                    {
                        return(nextStepAfterIfElse);
                    }
                }

                return(getNextStep(sagaAction, step, sagaState));
            }
            return(step);
        }
        public static ISagaAction FindActionForStep(
            this ISagaModel model, ISagaStep sagaStep)

        {
            return(model.Actions.
                   FindActionByStep(sagaStep?.StepName));
        }
示例#6
0
 public static async Task ExecuteChain(
     List <NextMiddleware> middlewaresChain,
     ISaga saga,
     ISagaStep sagaStep,
     StepData stepData)
 {
     await middlewaresChain[0].Invoke(saga, sagaStep, stepData);
 }
 static ISagaStep getChildNextStep(
     ISagaStep step)
 {
     if (step.ChildSteps.Any())
     {
         return(step.ChildSteps.GetFirstStep());
     }
     return(null);
 }
示例#8
0
 public SagaBuilderState(Type currentEvent, string currentState, ISagaModel model,
                         IServiceProvider serviceProvider, UniqueNameGenerator uniqueNameGenerator, ISagaStep parentStep)
 {
     CurrentEvent        = currentEvent;
     CurrentState        = currentState;
     Model               = model;
     ServiceProvider     = serviceProvider;
     UniqueNameGenerator = uniqueNameGenerator;
     ParentStep          = parentStep;
 }
        public ISagaStepBuilder <TContext> With_Roll_Back_Action_On_Error(ISagaStep <TContext> compensateStep)
        {
            if (Steps.Any())
            {
                var lastStep = Steps.Last();
                lastStep.CompensateStep = compensateStep;
            }

            return(this);
        }