Ejemplo n.º 1
0
        public void GetHtml_GivenAWebsite_ReturnsTheRawHtmlAndRedersInWPFControl()
        {
            Spider s = new Spider();

            string result = s.GetHtml(startingSite);

            Assert.IsNotNullOrEmpty(result);
            Console.WriteLine(result);
        }
Ejemplo n.º 2
0
        public void worker_DoWork(object sender, DoWorkEventArgs args)
        {
            object[] arguments = (object[])args.Argument;

            string startingSite = (string)arguments[0];
            string numberOfJumpsAsString = (string)arguments[1];
            int numberOfJumps = Convert.ToInt32(numberOfJumpsAsString);

            Spider s = new Spider();

            //deferred execution ie it wont call RunSpiderGetNext until it is iterated over in the foreach block
            //a lazy enumerator sequence?
            IEnumerable<WebPageInfo> listOfWebPageInfoOfSiteCurrentlyOn = s.RunSpiderGetNext(startingSite, numberOfJumps);

            int bytesTransferred = 0;
            foreach (var item in listOfWebPageInfoOfSiteCurrentlyOn)
            {
                textBoxSitesVisited.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate { textBoxSitesVisited.Text += item.Uri + "\r\n"; });
                textBoxSitesVisited.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate { textBoxSitesVisited.ScrollToEnd(); });

                textBoxMessages.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate { textBoxMessages.Text = item.Messages + "\r\n"; });

                webBrowser.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate { webBrowser.NavigateToString(item.Html); });

                bytesTransferred += item.SizeOfPageInBytes;

                var megaBytesTransferred = (decimal)bytesTransferred / 1048576;
                textBoxMBTransferred.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate { textBoxMBTransferred.Text = megaBytesTransferred.ToString("#.##"); });

                //assigning the variable therefore I don't need a return
                //bool? isSleepChecked = null;
                //checkBoxSleep.Dispatcher.Invoke(new Action(() =>
                //                                            {
                //                                                isSleepChecked = checkBoxSleep.IsChecked;
                //                                            })
                //                                ,DispatcherPriority.Normal);

                //using the func to return the nullable boolean.  lambda expression
                //bool? isSleepChecked = (bool?)checkBoxSleep.Dispatcher.Invoke(new Func<bool?>(() => checkBoxSleep.IsChecked));
                //rewritten using a delegate
                bool? isSleepChecked = (bool?)checkBoxSleep.Dispatcher.Invoke(new Func<bool?>(delegate { return checkBoxSleep.IsChecked; }));

                if (isSleepChecked == true)
                    Thread.Sleep(2000);
            }
        }
Ejemplo n.º 3
0
 public void setup()
 {
     s = new Spider();
 }