예제 #1
0
        private async Task DoActivity(ActivityFlowStep activityFlowStep, FlowContext stepFlowContext,
                                      FlowValues flowValues, FlowTrace flowTrace, CancellationToken cancellationToken)
        {
            var activityRequest = CreateRequest(stepFlowContext, activityFlowStep, flowValues);

            if (IsRequestDisabled(activityRequest))
            {
                _logger?.LogActivityRequestDisabled(stepFlowContext, activityRequest);
                return;
            }

            _logger?.LogActivityRequest(stepFlowContext, activityRequest);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            object activityResponse =
                await GetActivityResponse(
                    stepFlowContext, activityFlowStep, activityRequest, cancellationToken);

            stopWatch.Stop();

            ValidateFlowObjectValues(activityResponse, activityResponse.GetType().GetFlowObjectType(), activityFlowStep.Name);

            flowTrace.AddStep(new FlowTraceStep {
                StepType = FlowTraceStepType.Activity, Name = activityFlowStep.Name
            });

            _logger?.LogActivityResponse(stepFlowContext, activityResponse, stopWatch.ElapsedMilliseconds);

            SetFlowValuesFromResponse(activityFlowStep.Definition, stepFlowContext, flowValues, activityRequest, activityResponse);

            AppendResponseFlowTrace(flowTrace, activityResponse);
        }
예제 #2
0
        private void RecordLabelStep(FlowTrace flowTrace, FlowContext stepFlowContext)
        {
            _logger.LogLabel(stepFlowContext);

            flowTrace.AddStep(new FlowTraceStep {
                StepType = FlowTraceStepType.Label, Name = stepFlowContext.FlowStepName
            });
        }
예제 #3
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);
        }