Beispiel #1
0
    /// <summary>crawls the process starting from the node and state</summary>
    private Step Crawl(int node, State state, List <Step> steps)
    {
        // already crawled?
        var existingStep = FindStep(node, state, steps);

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

        var step = new Step(steps.Count, node, state);

        steps.Add(step);

        foreach (var transition in transitions)
        {
            // skip irrelevant transitions
            if (transition.source != node)
            {
                continue;
            }

            // try to execute script
            var nextState = transition.script.Execute(state);
            if (nextState == null)
            {
                continue;                    // preconditions not met
            }
            var nextNode = transition.target;

            // recurse
            var nextStep = Crawl(nextNode, nextState, steps);

            // link
            step.AddSuccessor(nextStep);
            nextStep.AddPredecessor(step);
        }

        return(step);
    }