public void CustomStaticImageTitleTest()
 {
     using (var x = new UriExtractor(new ProgressBarStatus(), new FirefoxDriver(workingDirectory))
     {
         URI = new Uri($"file://{workingDirectory}//StaticPages/test3.html"),
         ExcludeSymbolsRegEx = excludeSymbolsRegEx,
         SearchTags = searchTags
     })
     {
         Assert.Equal(2, x.GetImages().Count());
         Assert.Equal(22, x.GetWords().Count());
     }
 }
Example #2
0
        private void btn_Go_Click(object sender, EventArgs e)
        {
            // Used factory pattern here instead of DI because the user can change these at will during runtime.
            IWordStemmer stemmer   = Factory.CreateWordStemmer(cb_grouping.Checked);
            IBlacklist   blacklist = Factory.CreateBlacklist(cb_ignoreCommonwords.Checked);

            // Perform in another thread to keep the UI active and display animation to the user.
            DoWait(() =>
            {
                var task = Task.Run(() =>
                {
                    using (var document = new UriExtractor(progressIndicator, webDriver.GetWebDriver())
                    {
                        URI = new Uri(Normalize(txt_URL.Text))
                    })
                    {
                        document.SearchTags.Clear();
                        document.SearchTags.AddRange(CustomSettings.SearchTagNames);
                        document.ExcludeSymbolsRegEx = CustomSettings.RegExExcludeSymbols;

                        _lastGroupOfWords = document
                                            .Filter(blacklist)
                                            .Filter(customIgnorelist)
                                            .OrderBy(w => w) // Sort alpabetically
                                            .CountOccurences()
                                            .GroupByStem(stemmer)
                                            .SortByOccurences() // Sort by occurences
                                            .ToList();          // Remove deffered execution as Extractor will be disposed after this method ends.


                        // Compute top n words.
                        var topWords = _lastGroupOfWords.Take(CustomSettings.TopNumberOfWords);

                        SetWordList(topWords);
                        DoLocal(() => ClearImageList());
                        var images = document.GetImages();
                        foreach (var image in images)
                        {
                            var imageObj = GetImage(image.Item1);
                            if (imageObj == null)
                            {
                                continue;
                            }
                            DoLocal(() => imagesFromCurrentSite.Images.Add(image.Item1, imageObj));
                            DoLocal(() => lv_images.Items.Add(new ListViewItem(image.Item2, image.Item1)
                            {
                                ToolTipText = "Click the image to display full size."
                            }));
                        }
                    }
                });

                // Set callback to check for any errors during execution
                task.GetAwaiter().OnCompleted(() =>
                {
                    if (task.Exception != null)
                    {
                        DoLocal(() => MessageBox.Show(this, $"Sorry the following error occured while trying to execute your last request:\r\n {GetErrorMessage(task.Exception)}"), true);
                        DoLocal(() => txt_URL.BackColor = Color.Red);
                    }
                    else
                    {
                        DoLocal(() => txt_URL.BackColor = Color.Green);
                    }
                });

                // Wait until the task is done so the progress bar doesn't go away.
                task.Wait();
            });
        }