Beispiel #1
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            if (viewModel.Folderpath == null || viewModel.Folderpath.Length == 0)
            {
                MessageBox.Show("Folderpath is empty.");
                return;
            }

            viewModel.Results.Clear();
            viewModel.ClearLog();
            crawler = new Crawler(viewModel.Url,
                                  viewModel.Folderpath,
                                  viewModel.MaxLimitInt);
            crawler.CrawlPageStarted += url => AddLogInUiThread($"Craw {url} started.");
            crawler.CrawlPageFailed  += (url, msg) =>
            {
                AddItemInUiThread(url, msg, false);
                AddLogInUiThread($"Craw {url} failed. Msg: {msg}");
            };
            crawler.CrawlPageSucceeded += (url, html) =>
            {
                AddItemInUiThread(url, html, true);
                AddLogInUiThread($"Craw {url} succeeded.");
            };
            crawler.CrawlTaskEnded += () => CrawlEndedActionInUiThread();
            startButton.IsEnabled   = false;
            Task.Run(() =>
            {
                if (viewModel.IsBfsChecked)
                {
                    crawler.BfsCraw();
                }
                else
                {
                    crawler.DfsCraw();
                }
            });
        }