Beispiel #1
0
        static ISagaStep getNextStep(
            ISagaAction sagaAction,
            ISagaStep step,
            SagaExecutionState sagaState)
        {
            ISagaStep nextStepForWhile = getNextStepForWhile(sagaAction, step);

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

            // szukamy kolejnego kroku
            ISagaStep nextStep = GetNextStepElsewhere(
                sagaAction.ChildSteps,
                step);

            // sprawdzenie czy rodzic to ELSE
            nextStep = getNextStepForElse(
                sagaAction,
                nextStep,
                sagaState);

            return(nextStep);
        }
Beispiel #2
0
        static NextStepInfo getNextStepForIf(
            ISagaAction sagaAction,
            ISagaStep step,
            SagaExecutionState sagaState)
        {
            if (step.Is <ISagaStepForIf>())
            {
                IStepData currentStepData = sagaState.History.
                                            GetLatestByStepName(step.StepName);

                if (currentStepData?.ExecutionData?.ConditionResult == true)
                {
                    return(new NextStepInfo {
                        NextStep = step.ChildSteps.GetFirstStep()
                    });
                }
                else
                {
                    return(new NextStepInfo {
                        NextStep = GetNextStepElsewhere(sagaAction.ChildSteps, step)
                    });
                }
            }
            return(null);
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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));
        }
Beispiel #5
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 ExecutionContext(TSagaData data, SagaExecutionInfo info, SagaExecutionState state, SagaExecutionValues sagaExecutionValues, StepExecutionValues stepExecutionValues)
 {
     Data                = data;
     ExecutionInfo       = info;
     ExecutionState      = state;
     ExecutionValues     = sagaExecutionValues;
     StepExecutionValues = stepExecutionValues;
 }
Beispiel #7
0
 static public StepData SetSucceeded(this StepData data, SagaExecutionState state, IDateTimeProvider dateTimeProvider)
 {
     if (state.IsResuming)
     {
         data.ResumeData.SucceedTime = dateTimeProvider.Now;
     }
     else if (state.IsCompensating)
     {
         data.CompensationData.SucceedTime = dateTimeProvider.Now;
     }
     else
     {
         data.ExecutionData.SucceedTime = dateTimeProvider.Now;
     }
     return(data);
 }
 public StepData SetSucceeded(SagaExecutionState state, IDateTimeProvider dateTimeProvider)
 {
     if (state.IsResuming)
     {
         ResumeData.SucceedTime = dateTimeProvider.Now;
     }
     else if (state.IsCompensating)
     {
         CompensationData.SucceedTime = dateTimeProvider.Now;
     }
     else
     {
         ExecutionData.SucceedTime = dateTimeProvider.Now;
     }
     return(this);
 }
Beispiel #9
0
 static public StepData SetFailed(this StepData data, SagaExecutionState state, IDateTimeProvider dateTimeProvider, Exception error)
 {
     if (state.IsResuming)
     {
         data.ResumeData.Error    = error.ToSagaStepException();
         data.ResumeData.FailTime = dateTimeProvider.Now;
     }
     else if (state.IsCompensating)
     {
         data.CompensationData.Error    = error.ToSagaStepException();
         data.CompensationData.FailTime = dateTimeProvider.Now;
     }
     else
     {
         data.ExecutionData.Error    = error.ToSagaStepException();
         data.ExecutionData.FailTime = dateTimeProvider.Now;
     }
     return(data);
 }
 public StepData SetFailed(SagaExecutionState state, IDateTimeProvider dateTimeProvider, Exception error)
 {
     if (state.IsResuming)
     {
         ResumeData.Error    = error.ToSagaStepException();
         ResumeData.FailTime = dateTimeProvider.Now;
     }
     else if (state.IsCompensating)
     {
         CompensationData.Error    = error.ToSagaStepException();
         CompensationData.FailTime = dateTimeProvider.Now;
     }
     else
     {
         ExecutionData.Error    = error.ToSagaStepException();
         ExecutionData.FailTime = dateTimeProvider.Now;
     }
     return(this);
 }