Exemple #1
0
        private int CheckDecision(int flowStepIndex, DecisionFlowStepBase decisionFlowStep, FlowDefinition <TFlowRequest, TFlowResponse> flowDefinition,
                                  FlowContext stepFlowContext, FlowValues flowValues, FlowTrace flowTrace)
        {
            var decisionRequest = (FlowDecisionBase)CreateRequest(stepFlowContext, decisionFlowStep, flowValues);

            // TODO: Pass the targets directly into GetMatchingBranchIndex
            decisionFlowStep.Branches.ForEach(b => decisionRequest.AddBranch(b.Targets));

            _logger?.LogDecisionRequest(stepFlowContext, decisionRequest);

            var branchIndex = decisionRequest.GetMatchingBranchIndex();

            if (branchIndex < 0 || branchIndex >= decisionFlowStep.Branches.Count)
            {
                throw new FlowException($"The branch index returned was out of bounds of the branch array: {branchIndex}");
            }

            var branch = decisionFlowStep.Branches[branchIndex];

            flowTrace.AddStep(new FlowTraceStep
            {
                StepType = FlowTraceStepType.Decision, Name = decisionFlowStep.Name, BranchTargets = branch.Targets
            });

            _logger?.LogDecisionResponse(stepFlowContext, branch);

            if (branch.IsEnd)
            {
                return(int.MaxValue);
            }

            if (branch.IsUnhandled)
            {
                throw new FlowUnhandledElseException($"Unhandled ELSE for decision '{decisionFlowStep.Name}'");
            }

            var isContinue = (branch.NextStepName == null);

            if (isContinue)
            {
                return(flowStepIndex + 1);
            }

            var nextFlowStepIndex = flowDefinition.GetStepIndex(branch.NextStepName);

            return(nextFlowStepIndex);
        }