using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Net; using System.Windows.Forms; using System.Threading; using System.IO; using HttpWebCrawler; namespace HttpWebCrawlerForm { public partial class HttpWebCrawlerForm : Form { private Thread crawlerThread; private ImageContentAnalysisForm contentAnalysisGUI; private Boolean displayImageContent = false; private int imageListPositionDisplay = 0; private ImageForm imageForm; private void crawlButton_Click(object sender, EventArgs e) { // Initialize the event handler WebPage.UpdateImageURLListEvent += new updateImageURLListDelegate(updateImageURLList); WebPage.UpdateSiteURLListEvent += new updateSiteURLListDelegate(updateSiteURLList); crawlerThread = new Thread(new ParameterizedThreadStart(WebPage.GetAllPagesUnder)); string startURL = urlEdit.Text; if (startURL != null) { crawlerThread.Start(new Uri(startURL)); } } private void contentAnalysisButton_Click(object sender, EventArgs e) { if (contentAnalysisGUI.IsDisposed) { contentAnalysisGUI = new ImageContentAnalysisForm(this); contentAnalysisGUI.Visible = true; } else if (!contentAnalysisGUI.Visible) contentAnalysisGUI.Show(); } private void HttpWebCrawlerForm_FormClosed(object sender, FormClosedEventArgs e) { if (crawlerThread != null) crawlerThread.Abort(); Application.Exit(); } private void updateImageURLList(string imageURL, Image image, int imageCount) { imageCountLabel.Text = "image count " + imageCount; imageURLListBox.Items.Add(imageURL); if (displayImageContent) displayImage(imageURL, image, imageCount); } private void updateSiteURLList(string url) { siteURLListBox.Items.Add(url); } /* private void displayImageContent() { // Displays the content of each image taken from the imageURLListBox control imageListPositionDisplay = 0; while (imageURLListBox.Items.Count == 0) { } while (true) { while (imageListPositionDisplay >= imageURLListBox.Items.Count) { } lock (this) while ((displayContentThreadPaused) || (imageForm.IsDisposed)) Monitor.Wait(this); // Display images found by crawler string imageURL = (string)imageURLListBox.Items[imageListPositionDisplay]; displayImage(imageURL); } } */ private void displayImage(string url, Image image, int imageCount) { int width = image.Width; int height = image.Height; if (!imageForm.IsDisposed) { imageForm.ImageURL = "Image:" + imageCount + " URL:" + url + " " + width + " x " + height; imageForm.ImageFormPictureBox.Image = image; } } public Boolean DisplayImageContent { get { return displayImageContent; } set { displayImageContent = value; } } public ImageForm ImageForm { get { return imageForm; } set { imageForm = value; } } public HttpWebCrawlerForm() { InitializeComponent(); urlEdit.Text = "http://www.eee.bham.ac.uk/spannm/links.htm"; contentAnalysisGUI = new ImageContentAnalysisForm(this); imageForm = new ImageForm(); } } }