Beispiel #1
0
        public INode Traverse(IEnumerable <INode> roots, ComponentTraversalStrategy strategy)
        {
            var compTrav = GetTraverserForStrategy(strategy);

            BuildComponentCache(roots);

            INode result, root;

            while (this.components.Any())
            {
                root   = this.components.First().Value;
                result = compTrav.Traverse(root);

                // in case we found something
                if (result != null)
                {
                    logger.Debug("Node found: {0}", result);
                    UnsubscribeFromComponentTraverser(compTrav);
                    return(result);
                }

                OnVisitedComponent(root);
            }

            UnsubscribeFromComponentTraverser(compTrav);
            return(null);
        }
Beispiel #2
0
        private ComponentTraverser GetTraverserForStrategy(ComponentTraversalStrategy strategy)
        {
            ComponentTraverser instance;

            switch (strategy)
            {
            case ComponentTraversalStrategy.BFS:
                instance = new BFSGraphTraverser();
                break;

            case ComponentTraversalStrategy.DFS:
                instance = new DFSGraphTraverser();
                break;

            default:
                logger.Fatal("Not supported component traversal strategy: {0}", strategy);
                throw new InvalidOperationException("Not supported component traversal strategy.");
            }

            instance.VisitedNode  += this.HandleVisitedNode;
            instance.VisitingNode += this.HandleVisitingNodeInComponent;

            return(instance);
        }
Beispiel #3
0
 public static INode Traverse(this Traverser self, ComponentTraversalStrategy strategy, params INode[] nodes)
 {
     return(self.Traverse(nodes, strategy));
 }