示例#1
0
        private FlowDiagramNode AddFlowDiagramDecisionNode(int stepIndex, IFlowDefinition flowDefinition, FlowDiagram flowDiagram,
                                                           FlowStep flowStep, DecisionFlowStepBase decisionFlowStep, ref int endCount)
        {
            var decisionRequest = GetFlowStepRequest(flowStep.Definition);

            var decisionNode = flowDiagram.AddNode(new FlowDiagramNode
            {
                NodeType            = FlowDiagramNodeType.Decision,
                Name                = flowStep.Name,
                Text                = GetFlowDiagramNodeText(flowStep, decisionRequest),
                OverrideKey         = flowStep.OverrideKey?.Value,
                OverrideDescription = flowStep.OverrideKey?.Description,
            });

            SetFlowDiagramNodeInputSummaries(flowStep, decisionRequest, decisionNode);

            foreach (var branch in decisionFlowStep.Branches)
            {
                if (branch.IsUnhandled)
                {
                    continue;
                }

                var linkCriteria = branch.Targets?.ToList().ConvertAll(c => c?.ToString());

                if (branch.IsEnd)
                {
                    var endNode = AddFlowDiagramEndNode(flowDiagram, ref endCount);

                    decisionNode.Links.Add(new FlowDiagramLink
                    {
                        TargetNodeName = endNode.Name,
                        Criteria       = linkCriteria
                    });
                }
                else
                {
                    if (string.IsNullOrEmpty(branch.NextStepName))
                    {
                        endCount = AddFlowDiagramDefaultLink(decisionNode, stepIndex, flowDefinition, flowDiagram, endCount);
                    }
                    else
                    {
                        decisionNode.Links.Add(new FlowDiagramLink
                        {
                            TargetNodeName = branch.NextStepName,
                            Criteria       = linkCriteria
                        });
                    }
                }
            }

            return(decisionNode);
        }
示例#2
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);
        }