Example #1
0
        private static void TraverseDiagram(WorkflowGraphNode currentNode, ISet <WorkflowGraphNode> visitedNodes)
        {
            if (visitedNodes.Contains(currentNode))
            {
                return;
            }

            visitedNodes.Add(currentNode);

            foreach (var nextNode in currentNode.NextNodes.Where(node => !visitedNodes.Contains(node)))
            {
                TraverseDiagram(nextNode, visitedNodes);
            }
        }
Example #2
0
        public WorkflowGraph(IeWorkflow workflow)
        {
            if (workflow == null)
            {
                throw new ArgumentNullException(nameof(workflow));
            }

            if (workflow.States == null)
            {
                throw new ArgumentNullException(nameof(workflow.States));
            }

            if (workflow.TransitionEvents == null)
            {
                throw new ArgumentNullException(nameof(workflow.TransitionEvents));
            }

            _nodesByName = new Dictionary <string, WorkflowGraphNode>();

            foreach (var state in workflow.States)
            {
                if (string.IsNullOrWhiteSpace(state.Name))
                {
                    throw new ArgumentException(StateHasNoNameError);
                }

                var node = new WorkflowGraphNode(state);
                _nodesByName[state.Name] = node;

                if (node.IsInitial)
                {
                    _initialNode = node;
                }
            }

            if (_initialNode == null)
            {
                throw new ArgumentException(NoInitialStateError);
            }

            foreach (var transition in workflow.TransitionEvents)
            {
                if (string.IsNullOrWhiteSpace(transition.FromState))
                {
                    throw new ArgumentException(TransitionHasNoFromStateError);
                }

                if (string.IsNullOrWhiteSpace(transition.ToState))
                {
                    throw new ArgumentException(TransitionHasNoToStateError);
                }

                WorkflowGraphNode fromNode;
                WorkflowGraphNode toNode;

                if (_nodesByName.TryGetValue(transition.FromState, out fromNode) &&
                    _nodesByName.TryGetValue(transition.ToState, out toNode))
                {
                    fromNode.AddNextNode(toNode);
                }
            }
        }
Example #3
0
 public void AddNextNode(WorkflowGraphNode node)
 {
     _nextNodes.Add(node);
 }