Ejemplo n.º 1
0
        // search for the finishing website
        // inputs: strings for start and end, ArticleCollection to store webpages in, ForbiddenLinks object
        void searchForWebsite(string StartPageName, string FinishPageName, ArticleCollection Webpages, ForbiddenLinks Forbidden) {
            // get data for first webpage
            WikipediaWebRequest request = new WikipediaWebRequest("wiki/"+StartPageName, Webpages, Forbidden, null);          
            
            // successful request, start program
            if (request.SuccessfulWebRequest()) {
                WikipediaSearcher s = null;
                
                // create article crawler
                ArticleCrawler c = new ArticleCrawler(Webpages, Forbidden);
                Thread crawler = new Thread(() => c.Start());
                crawler.Start();
                crawler.Priority = ThreadPriority.Normal;

                // create searcher
                Console.WriteLine("Creating Searcher....");
                Thread searcher = new Thread(() => {s = new WikipediaSearcher(Webpages, StartPageName, FinishPageName, Forbidden, "BFS");});
                searcher.Start();
                searcher.Priority = ThreadPriority.AboveNormal;

                // wait for searcher to complete   
                searcher.Join();

                // try to stop crawler
                try {
                    crawler.Abort();
                }
                catch (PlatformNotSupportedException) {
                    // TODO: investigate this further
                    Console.WriteLine("System does not support abort of threads. Please terminate manually");
                }
            }
        }