コード例 #1
0
ファイル: NextStepCalculator.cs プロジェクト: b-y-t-e/TheSaga
        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
ファイル: NextStepCalculator.cs プロジェクト: b-y-t-e/TheSaga
        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
ファイル: NextStepCalculator.cs プロジェクト: b-y-t-e/TheSaga
        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);
        }
コード例 #5
0
        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);
 }
コード例 #7
0
 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;
 }
コード例 #9
0
        public ISagaStepBuilder <TContext> With_Roll_Back_Action_On_Error(ISagaStep <TContext> compensateStep)
        {
            if (Steps.Any())
            {
                var lastStep = Steps.Last();
                lastStep.CompensateStep = compensateStep;
            }

            return(this);
        }