www.pudn.com > Crawler_bemjh.rar > MainForm.cs
using System;
using System.Drawing;
using System.Xml;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Resources;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Net;
using System.Net.Sockets;
using CrawlerLib;
using ShootSeg;
// 程序目的 :程序是抓取某一类型的网站数据
// 制作时间 :2006-12-12
// 设计制作人:马建华
// 待改进的地方:计算权值,代码优化。
namespace Crawler
{
///
/// 小马的主题蜘蛛
///
public class CrawlerForm : System.Windows.Forms.Form
{
// 用户代码:
// 自定义变量
// 自定义的各种函数
#region 用户代码
// 用户自定义的变量
#region 用户自定义的变量
// URL队列表
private Queue queueURLS;
// URL队列表
private Queue queueSubURLS;
// 二叉树,使URL保持唯一性
private SortTree urlStorage;
// 统计CPU的使用率
private System.Diagnostics.PerformanceCounter cpuCounter;
// 统计内存的使用率
private System.Diagnostics.PerformanceCounter ramCounter;
// 要下载的子页面个数
private int vSubPageLimitNum;
private int SubPageLimitNum
{
get { return vSubPageLimitNum; }
set { vSubPageLimitNum = value;}
}
// 下载的超时时间
private int vDownloadTimeOut;
private int DownloadTimeOut
{
get { return vDownloadTimeOut; }
set { vDownloadTimeOut = value;}
}
// 计数所用的时间秒数
private int vCountSecond;
private int CountTime
{
get { return vCountSecond; }
set { vCountSecond = value;}
}
// 是否要保存到文件夹
private bool nIsSaveToFolder;
private bool IsSaveToFolder
{
get { return nIsSaveToFolder; }
set { nIsSaveToFolder = value;}
}
// 下载的字节数
private int nByteCount;
private int ByteCount
{
get { return nByteCount; }
set
{
nByteCount = value;
this.statusBarPanelByteCount.Text = Commas(nByteCount/1024+1)+ " KB";
}
}
// 统计错误的URL条数
private int nErrorCount;
private int ErrorCount
{
get { return nErrorCount; }
set
{
nErrorCount = value;
this.statusBarPanelErrors.Text = Commas(nErrorCount) + " 错误";
}
}
// 统计待处理的URL条数
private int nURLQueueCount;
private int URLQueueCount
{
get { return nURLQueueCount; }
set
{
nURLQueueCount = value;
}
}
// // 统计已下载的URL条数
// private int nURLdownloadedCount;
// private int URLdownloadCount
// {
// get { return nURLdownloadedCount; }
// set
// {
// nURLdownloadedCount = value;
// this.statusBarPanelFiles.Text = Commas(URLdownloadCount)+" 条已下载";
// }
// }
// 统计找到的主URL条数
private int nURLCount;
private int URLCount
{
get { return nURLCount; }
set
{
nURLCount = value;
this.statusBarPanelURLs.Text = "新发现"+Commas(nURLCount)+ "条URL";
}
}
// 统计内存的可用大小
private float nFreeMemory;
private float FreeMemory
{
get { return nFreeMemory; }
set
{
nFreeMemory = value;
this.statusBarPanelMem.Text = nFreeMemory + " Mb 可用";
}
}
// CPU的使用率
private int nCPUUsage;
private int CPUUsage
{
get { return nCPUUsage; }
set
{
nCPUUsage = value;
this.statusBarPanelCPU.Text = "CPU 使用率 " + nCPUUsage +"%";
Icon icon = Icon.FromHandle(((Bitmap)imageListPercentage.Images[value/10]).GetHicon());
this.statusBarPanelCPU.Icon = icon;
}
}
// 下载的临时目录
private string strDownloadfolder;
private string Downloadfolder
{
get { return strDownloadfolder; }
set
{
strDownloadfolder = value;
strDownloadfolder = strDownloadfolder.TrimEnd('\\');
}
}
// 下载的文件统计
private int nFileCount;
private int FileCount
{
get { return nFileCount; }
set { nFileCount = value; }
}
// 下载的子页面个数统计
private int nSubURLCount;
private int SubURLCount
{
get { return nSubURLCount; }
set { nSubURLCount = value; }
}
// 线程数组
private Thread[] threadsRun;
// 下载子页面线程数组
private Thread[] threadsSubRun;
// 统计正在运行的线程数
private int nThreadCount;
private int ThreadCount
{
get { return nThreadCount; }
set
{
Monitor.Enter(this.listViewThreads);
try
{
for(int nIndex = 0; nIndex < value; nIndex ++)
{
// check if thread not created or not suspended
if(threadsRun[nIndex] == null || threadsRun[nIndex].ThreadState != ThreadState.Suspended)
{
// create new thread
threadsRun[nIndex] = new Thread(new ThreadStart(ThreadRunFunction));
// set thread name equal to its index
threadsRun[nIndex].Name = nIndex.ToString();
// start thread working function
threadsRun[nIndex].Start();
// check if thread dosn't added to the view
if(nIndex == this.listViewThreads.Items.Count)
{
// add a new line in the view for the new thread
ListViewItem item = this.listViewThreads.Items.Add((nIndex+1).ToString(), 0);
string[] subItems = { "", "", "", "0", "0%","0" };
item.SubItems.AddRange(subItems);
}
}
// check if the thread is suspended
else if(threadsRun[nIndex].ThreadState == ThreadState.Suspended)
{
// get thread item from the list
ListViewItem item = this.listViewThreads.Items[nIndex];
item.ImageIndex = 1;
item.SubItems[2].Text = "Resume";
// resume the thread
threadsRun[nIndex].Resume();
}
}
// change thread value
nThreadCount = value;
}
catch(Exception)
{
}
Monitor.Exit(this.listViewThreads);
}
}
// 统计正在运行的子页面线程数
private int nThreadSubCount;
private int ThreadSubCount
{
get { return nThreadSubCount; }
set
{
try
{
for(int nIndex = 0; nIndex < value; nIndex ++)
{
// check if thread not created or not suspended
if(threadsSubRun[nIndex] == null || threadsSubRun[nIndex].ThreadState != ThreadState.Suspended)
{
// create new thread
threadsSubRun[nIndex] = new Thread(new ThreadStart(ThreadSubRunFunction));
// set thread name equal to its index
threadsSubRun[nIndex].Name = Convert.ToString(nIndex);
// start thread working function
threadsSubRun[nIndex].Start();
}
// check if the thread is suspended
else if(threadsSubRun[nIndex].ThreadState == ThreadState.Suspended)
{
// resume the thread
threadsSubRun[nIndex].Resume();
}
}
// change thread value
nThreadSubCount = value;
}catch(Exception){}
}
}
// MIME 类型变量
private string strMIMETypes = GetMIMETypes();
private string MIMETypes
{
get { return strMIMETypes; }
set { strMIMETypes = value; }
}
// 对文本进行解码
private Encoding encoding = GetTextEncoding();
private Encoding TextEncoding
{
get { return encoding; }
set { encoding = value; }
}
// 设置请求的超时时间
private int nRequestTimeout;
private int RequestTimeout
{
get { return nRequestTimeout; }
set { nRequestTimeout = value; }
}
// 当下载列队为空时设置线程的睡眠时间
private int nSleepFetchTime;
private int SleepFetchTime
{
get { return nSleepFetchTime; }
set { nSleepFetchTime = value;}
}
//列出用户用于限制下载的词
private string[] strExcludeWords;
private string[] ExcludeWords
{
get { return strExcludeWords; }
set { strExcludeWords = value; }
}
//列出用户用于限制下载的文件扩展名
private string[] strExcludeFiles;
private string[] ExcludeFiles
{
get { return strExcludeFiles; }
set { strExcludeFiles = value; }
}
//列出用户用于限制下载的主机名
private string[] strExcludeHosts;
private string[] ExcludeHosts
{
get { return strExcludeHosts; }
set { strExcludeHosts = value; }
}
//保存请求的数目,为了查看时提供详细的信息
private int nLastRequestCount;
private int LastRequestCount
{
get { return nLastRequestCount; }
set { nLastRequestCount = value; }
}
//设置每一个线程在完成一个请求后的时间,
//这个时间很重要,阻止一个主机对线程的锁定
private int nSleepConnectTime;
private int SleepConnectTime
{
get { return nSleepConnectTime; }
set { nSleepConnectTime = value; }
}
//保存要抓取的深度值
private int nWebDepth;
private int WebDepth
{
get { return nWebDepth; }
set { nWebDepth = value; }
}
//记录用于可下载的类型元数
private bool bAllMIMETypes;
private bool AllMIMETypes
{
get { return bAllMIMETypes; }
set { bAllMIMETypes = value; }
}
//设置是否要抓取同一个服务器下的网站
private bool bKeepSameServer;
private bool KeepSameServer
{
get { return bKeepSameServer; }
set { bKeepSameServer = value; }
}
// 设置是否要保持联连,以便在处理同一个域名下的网站时提高效率
private bool bKeepAlive;
private System.Windows.Forms.Label labelTotaldownloadSizes;
private bool KeepAlive
{
get { return bKeepAlive; }
set { bKeepAlive = value; }
}
// 数据库连接字符串
private ConnectionString cs = new ConnectionString();
// 过滤对象
private LogicalLayer llay = new LogicalLayer();
private FilterURL filterURL;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer isOvertimer;
private System.Windows.Forms.ColumnHeader columnHeaderCountTime;
private System.Windows.Forms.Timer countTimetimer;
private System.Windows.Forms.StatusBarPanel statusBarPanelSubURLs;
// 线程运行状态标志
bool ThreadsRunning;
#endregion
// 调用系统的API函数显示连接的状态
[DllImport("wininet")]
public static extern int InternetGetConnectedState(ref int lpdwFlags, int dwReserved);
[DllImport("wininet")]
public static extern int InternetAutodial(int dwFlags, int hwndParent);
int nFirstTimeCheckConnection = 0;
string InternetGetConnectedStateString()
{
string strState = "";
try
{
int nState = 0;
// check internet connection state
// 核对连接的状态
if(InternetGetConnectedState(ref nState, 0) == 0)
return "您还没有准备好网络连接";
if((nState & 1) == 1)
strState = "使用 Modem 连接";
else if((nState & 2) == 2)
strState = "使用局域网连接";
else if((nState & 4) == 4)
strState = "使用代理连接";
else if((nState & 8) == 8)
strState = "Modem ,";
else if((nState & 0x10) == 0x10)
strState = "远程访问服务器已安装";
else if((nState & 0x20) == 0x20)
return "掉线";
else if((nState & 0x40) == 0x40)
return "正在配置网络连接";
// get current machine IP
// 获得该机的IP地址
IPHostEntry he = Dns.Resolve(Dns.GetHostName());
strState += ", 本机IP地址: "+he.AddressList[0].ToString();
}
catch
{
}
return strState;
}
void ConnectionInfo()
{
try
{
int nState = 0;
if(InternetGetConnectedState(ref nState, 0) == 0)
{
if(nFirstTimeCheckConnection++ == 0)
// ask for dial up or DSL connection
if(InternetAutodial(1, 0) != 0)
// check internet connection state again
InternetGetConnectedState(ref nState, 0);
}
if((nState & 2) == 2 || (nState & 4) == 4)
// reset to reask for connection agina
nFirstTimeCheckConnection = 0;
}
catch
{
}
labelNetInfo.Text = InternetGetConnectedStateString();
}
// 初始化与数据库的连接
void InitDataBaseConnection()
{
try
{
cs.DataBaseAddress = Settings.GetValue("Database Address");
cs.DataBaseName = Settings.GetValue("Database Name");
cs.DataBaseUserName = Settings.GetValue("Database User Name");
cs.DataBasePassword = Settings.GetValue("Database Password");
if(cs.DataBaseName.Equals("") || cs.DataBaseAddress.Equals(""))
{
MessageBox.Show(null,"请配置数据库连接选项!","错误提示",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
// 初始化连接字符串
llay.InitConnString(cs);
}
}
catch(Exception e)
{
MessageBox.Show(null,e.Message,"错误提示",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
// 初始化各个环境变量的值
void InitValues()
{
DownloadTimeOut = Settings.GetValue("download time out", 200);
SubPageLimitNum = Settings.GetValue("download Sub Page Num", 20);
WebDepth = Settings.GetValue("Web depth", 3);
IsSaveToFolder = Settings.GetValue("Is Save to Folder", false);
RequestTimeout = Settings.GetValue("Request timeout", 20);
SleepFetchTime = Settings.GetValue("Sleep fetch time", 2);
SleepConnectTime = Settings.GetValue("Sleep connect time", 1);
KeepSameServer = Settings.GetValue("Keep same URL server", false);
AllMIMETypes = Settings.GetValue("Allow all MIME types", false);
KeepAlive = Settings.GetValue("Keep connection alive", true);
ExcludeHosts = Settings.GetValue("Exclude Hosts", " .gov;").Replace("*", "").ToLower().Split(';');
ExcludeWords = Settings.GetValue("Exclude words", "").Split(';');
ExcludeFiles = Settings.GetValue("Exclude files", "").Replace("*", "").ToLower().Split(';');
LastRequestCount = Settings.GetValue("View last requests count", 20);
Downloadfolder = Settings.GetValue("Download folder", System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal));
MIMETypes = GetMIMETypes();
TextEncoding = GetTextEncoding();
}
// 初始化URLQueue,将URL从indexPage表取出来,并显示在URLQueueListview当中
void InitIndexURLQueue()
{
ArrayList coreURLList = null;
//获取要下载的种子网址列表
coreURLList = llay.GetCoreURL();
if(coreURLList.Count == 0)
{
llay.refreshCoreURL();
}
PageElement pe = new PageElement();
//从表中读出记录,并插入到websites表中.
foreach(Object record in coreURLList)
{
pe.URL = record.ToString();
Normalize(ref pe);
MyUri newUri = new MyUri(pe.URL);
// 指定传输类型为HTTP及HTTPS
if(newUri.Scheme != Uri.UriSchemeHttp && newUri.Scheme != Uri.UriSchemeHttps)
continue;
if(this.EnqueueUri(newUri, true) == true)
{}
}
}
// 初始化IndexURLQueue,将URL从subPage表中读取出来,并显示在URLQueueListview当中
void InitSubURLQueue()
{
ArrayList indexURLList = null;
//获取要下载的种子网址列表
indexURLList = llay.GetIndexURL();
PageElement pe = new PageElement();
foreach(Object record in indexURLList)
{
pe.URL = record.ToString();
MyUri newUri = new MyUri(pe.URL);
if(this.EnqueueSubUri(newUri, true) == true)
{}
}
}
// 获得文本的编码
static Encoding GetTextEncoding()
{
Encoding code ;
if(Settings.GetValue("Use windows default code page", true) == true)
code = Encoding.Default;
else
{
string strCodePage = Settings.GetValue("Settings code page");
Regex reg = new Regex(@"\([0-9]*\)");
strCodePage = reg.Match(strCodePage).Value;
code = Encoding.GetEncoding(int.Parse(strCodePage.Trim('(', ')')));
}
return code;
}
// construct MIME types string from settings xml file
// 从XML获得 MIME 的类型
static string GetMIMETypes()
{
string str = "";
// check for settings xml file existence
// 检查XML文件是否存在
if(File.Exists(Application.StartupPath+"\\Settings.xml"))
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath+"\\Settings.xml");
XmlNode element = doc.DocumentElement.SelectSingleNode("SettingsForm-listViewFileMatches");
if(element != null)
{
for(int n = 0; n < element.ChildNodes.Count; n++)
{
XmlNode xmlnode = element.ChildNodes[n];
XmlAttribute attribute = xmlnode.Attributes["Checked"];
if(attribute == null || attribute.Value.ToLower() != "true")
continue;
string[] items = xmlnode.InnerText.Split('\t');
if(items.Length > 1)
{
str += items[0];
if(items.Length > 2)
str += '['+items[1]+','+items[2]+']';
str += ';';
}
}
}
}
return str;
}
// 开始或继续下载
void StartOrContinueParsing()
{
InitDataBaseConnection() ;
DateTime dt = DateTime.Now;
labelStartTime.Text = string.Format("{0:G}",dt);//2005-11-5 14:23:23
InitIndexURLQueue();
InitSubURLQueue();
// 初始化多线程,并分配任务
CountSecondtimer.Start();
this.countTimetimer.Start();
filterURL= new FilterURL();
ThreadsRunning = true;
this.toolBarButtonContinue.Enabled = false;
this.toolBarButtonStop.Enabled = true;
this.toolBarButtonPause.Enabled = true;
this.statusBarPanelInfo.Text = " 网络蜘蛛正在运行...";
ThreadCount = Settings.GetValue("Threads count", 10);
}
// 暂停所有的线程的工作
void PauseParsing()
{
CountSecondtimer.Stop();
isOvertimer.Stop();
this.countTimetimer.Stop();
for(int n = 0; n < ThreadCount; n++)
{
Thread thread = this.threadsRun[n];
if(thread.ThreadState == ThreadState.Running)
thread.Suspend();
}
for(int n = 0; n < ThreadSubCount; n++)
{
Thread thread = this.threadsSubRun[n];
if(thread.ThreadState == ThreadState.Running)
thread.Suspend();
}
this.toolBarButtonContinue.Enabled = true;
this.toolBarButtonPause.Enabled = false;
this.statusBarPanelInfo.Text = " 网络蜘蛛暂停运行...";
}
// 停止所有线程的工作
void StopParsing()
{
CountSecondtimer.Stop();
isOvertimer.Stop();
this.queueURLS.Clear();
this.queueSubURLS.Clear();
this.countTimetimer.Stop();
ThreadsRunning = false;
Thread.Sleep(500);
Monitor.Enter(this.listViewThreads);
for(int n = 0; n < ThreadCount; n++)
{
try
{
Thread thread = this.threadsRun[n];
ListViewItem itemLog = this.listViewThreads.Items[int.Parse(thread.Name)];
itemLog.SubItems[2].Text = "Stop";
itemLog.BackColor = Color.WhiteSmoke;
itemLog.ImageIndex = 3;
if(thread != null && thread.IsAlive)
{
if(thread.ThreadState == ThreadState.Suspended)
thread.Resume();
thread.Abort();
}
}
catch(Exception)
{
}
}
for(int n = 0; n < ThreadSubCount; n++)
{
try
{
Thread thread = this.threadsSubRun[n];
ListViewItem itemLog = this.listViewThreads.Items[int.Parse(thread.Name)];
itemLog.SubItems[2].Text = "Stop";
itemLog.BackColor = Color.WhiteSmoke;
itemLog.ImageIndex = 3;
if(thread != null && thread.IsAlive)
{
if(thread.ThreadState == ThreadState.Suspended)
thread.Resume();
thread.Abort();
}
}
catch(Exception)
{
}
}
Monitor.Exit(this.listViewThreads);
this.toolBarButtonContinue.Enabled = true;
this.toolBarButtonPause.Enabled = false;
this.toolBarButtonStop.Enabled = false;
this.statusBarPanelInfo.Text = " 网络蜘蛛停止运行...";
}
// 将找到的URL插入到URL队列中
bool EnqueueUri(MyUri uri, bool bCheckRepetition)
{
// 用二叉树检查URL是否存在,如果存在则不插入
if(bCheckRepetition == true && AddURL(ref uri) == false)
return false;
Monitor.Enter(queueURLS);
try
{
// 将此URL插入到队列中
queueURLS.Enqueue(uri);
}
catch(Exception)
{
}
Monitor.Exit(queueURLS);
return true;
}
// 将找到的URL插入到SubURL队列中
bool EnqueueSubUri(MyUri uri, bool bCheckRepetition)
{
// 用二叉树检查URL是否存在,如果存在则不插入
if(bCheckRepetition == true && AddURL(ref uri) == false)
return false;
Monitor.Enter(queueSubURLS);
try
{
// 将此URL插入到队列中
queueSubURLS.Enqueue(uri);
}
catch(Exception)
{
}
Monitor.Exit(queueSubURLS);
return true;
}
// 将URL从队列中删除
MyUri DequeueUri()
{
Monitor.Enter(queueURLS);
MyUri uri = null;
try
{
uri = (MyUri)queueURLS.Dequeue();
}
catch(Exception)
{
}
Monitor.Exit(queueURLS);
return uri;
}
MyUri DequeueSubUri()
{
Monitor.Enter(queueSubURLS);
MyUri uri = null;
try
{
uri = (MyUri)queueSubURLS.Dequeue();
}
catch(Exception)
{
}
Monitor.Exit(queueSubURLS);
return uri;
}
// 将一条URL网址正常化,实现一条完整的URL
// 即判断前面是否有http://
private void Normalize(ref PageElement pe)
{
if(pe.URL.StartsWith("http://") == false)
pe.URL = "http://"+pe.URL;
if(pe.URL.IndexOf("/", 8) == -1)
pe.URL += '/';
}
// 将URL加入到二叉树URL列表中
bool AddURL(ref MyUri uri)
{
foreach(string str in ExcludeHosts)
if(str.Trim().Length > 0 && uri.Host.ToLower().IndexOf(str.Trim()) != -1)
{
LogError(uri.AbsoluteUri, "\r\nHost excluded as it includes reserved pattern ("+str+")");
return false;
}
Monitor.Enter(urlStorage);
bool bNew = false;
try
{
string strURL = uri.AbsoluteUri;
bNew = urlStorage.Add(ref strURL).Count == 1;
}
catch(Exception){}
Monitor.Exit(urlStorage);
return bNew;
}
// 将错误信息保存到日志文件当中
private void SaveErrorInfo()
{
//如果有错误信息,则保存到错误日志
if(listViewErrors.Items.Count>0)
{
try
{
string myFileName;
DateTime CT = DateTime.Now;
myFileName = "Log" + CT.ToFileTime() + ".txt";
if(myFileName=="") return;
StreamWriter sw = File.CreateText(myFileName);
sw.WriteLine ("= = = = = = = = = = = = = = = = = = = = = = 蜘蛛运行日志 = = = = = = = = = = = = = = = = = = = = = =");
sw.WriteLine ("");
sw.WriteLine ("");
sw.WriteLine (" 日志保存时间:" + System.DateTime.Now.ToString());
sw.WriteLine ("");
sw.WriteLine ("");
sw.WriteLine ("- - the Beginning of the log - -");
sw.WriteLine ("");
ListViewItem item ;
for(int i=0; i 3)
{
str = str.Insert(nIndex-3, ",");
nIndex -= 3;
}
return str;
}
// 运行线程要实现的功能
void ThreadRunFunction()
{
MyWebRequest request = null;
while(ThreadsRunning && int.Parse(Thread.CurrentThread.Name) < this.ThreadCount)
{
MyUri uri = DequeueUri();
if(uri != null)
{
if(SleepConnectTime > 0)
Thread.Sleep(SleepConnectTime*1000);
ParseUri(uri, ref request);
}
else
Thread.Sleep(SleepFetchTime*1000);
}
Monitor.Enter(this.listViewThreads);
try
{
ListViewItem item = this.listViewThreads.Items[int.Parse(Thread.CurrentThread.Name)];
if(ThreadsRunning == false)
{
item.SubItems[2].Text = "Stop";
}
item.ImageIndex = 0;
}
catch(Exception)
{
}
Monitor.Exit(this.listViewThreads);
}
// 运行线程要实现的功能
void ThreadSubRunFunction()
{
MyWebRequest request = null;
while(ThreadsRunning && int.Parse(Thread.CurrentThread.Name) < this.ThreadCount)
{
MyUri uri = DequeueSubUri();
if(uri != null)
{
if(SleepConnectTime > 0)
Thread.Sleep(SleepConnectTime*1000);
ParseIndexUri(uri);
}
else
Thread.Sleep(SleepFetchTime*1000);
}
Monitor.Enter(this.listViewThreads);
try
{
ListViewItem item = this.listViewThreads.Items[int.Parse(Thread.CurrentThread.Name)];
if(ThreadsRunning == false)
{
item.SubItems[2].Text = "Stop";
}
item.ImageIndex = 0;
}
catch(Exception)
{
}
Monitor.Exit(this.listViewThreads);
}
///
/// 函数的功能包括:
/// 1.检查是否为合法的URL(MIME类型,扩展名,非法单词,扩展域名)
/// 2.请求下载指定的URL网页的内容
/// 3.更新显示ListView中的内容的状态条中的内容
/// 4.发现新的URL
/// 5.下载指定的层数的网页
///
/// 网址
/// 请求对象
void ParseUri(MyUri uri, ref MyWebRequest request)
{
string strStatus = "";
// check if connection is kept alive from previous connections or not
//判断是否还保持着活动的连接
if(request != null && request.response.KeepAlive)
strStatus += "Connection live to: "+uri.Host+"\r\n\r\n";
else
strStatus += "Connecting: "+uri.Host+"\r\n\r\n";
ListViewItem itemLog = null;
//更新显示ListView中的内容
Monitor.Enter(this.listViewThreads);
try
{
// update thread information in the threads view list
itemLog = this.listViewThreads.Items[int.Parse(Thread.CurrentThread.Name)];
int nDepth = uri.Depth;
itemLog.SubItems[1].Text = nDepth.ToString();
itemLog.ImageIndex = 1;
itemLog.BackColor = Color.WhiteSmoke;
// initialize status to Connect
itemLog.SubItems[2].Text = "Connect";
itemLog.ForeColor = Color.Red;
itemLog.SubItems[3].Text = uri.AbsoluteUri;
itemLog.SubItems[4].Text = "";
itemLog.SubItems[5].Text = "";
itemLog.SubItems[6].Text = "0";
}
catch(Exception)
{
}
Monitor.Exit(this.listViewThreads);
try
{
// create web request
// 创建一个web request 对象
request = MyWebRequest.Create(uri, request, KeepAlive);
// set request timeout
//设置超时时间
request.Timeout = RequestTimeout*1000;
// retrieve response from web request
// 获取来自服务器的回应
MyWebResponse response = request.GetResponse();
// update status text with the request and response headers
// 更新文件头的状态信息
strStatus += request.Header+response.Header;
// check for redirection
// 检查是否为重定向
if(response.ResponseUri.Equals(uri) == false)
{
// add the new uri to the queue
// 将URL加入到队列中
//this.EnqueueUri(new MyUri(response.ResponseUri.AbsoluteUri), true);
// update status
// 更新状态信息
strStatus += "Redirected to: "+response.ResponseUri+"\r\n";
// log current uri status
// 写入日志文件
LogUri(uri.AbsoluteUri, strStatus);
// reset current request to avoid response socket opening case
// 将当前请求复位
request = null;
return;
}
// check for allowed MIME types
// 检查文件中的MIME类型
if(AllMIMETypes == false && response.ContentType != null && MIMETypes.Length > 0)
{
string strContentType = response.ContentType.ToLower();
int nExtIndex = strContentType.IndexOf(';');
if(nExtIndex != -1)
strContentType = strContentType.Substring(0, nExtIndex);
if(strContentType.IndexOf('*') == -1 && (nExtIndex = MIMETypes.IndexOf(strContentType)) == -1)
{
LogError(uri.AbsoluteUri, strStatus+"\r\nUnlisted Content-Type ("+strContentType+"), check settings.");
request = null;
return;
}
// find numbers
Match match = new Regex(@"\d+").Match(MIMETypes, nExtIndex);
int nMin = int.Parse(match.Value)*1024;
match = match.NextMatch();
int nMax = int.Parse(match.Value)*1024;
if(nMin < nMax && (response.ContentLength < nMin || response.ContentLength > nMax))
{
LogError(uri.AbsoluteUri, strStatus+"\r\nContentLength limit error ("+response.ContentLength+")");
request = null;
return;
}
}
// check for response extention
// 检查文件的扩展名是否为要排除的
bool bParse = true;
foreach(string ext in ExcludeFiles)
if(ext.Trim().Length > 0 && uri.AbsoluteUri.ToLower().EndsWith(ext) == true)
{
bParse = false;
break;
}
FileStream streamOut = null;
BinaryWriter writer = null;
string PathName = null;
// 如果要将文件下载到文件夹中
if(IsSaveToFolder)
{
// construct path in the hard disk
string strLocalPath = uri.LocalPath;
// check if the path ends with / to can crate the file on the HD
if(strLocalPath.EndsWith("/") == true)
// check if there is no query like (.asp?i=32&j=212)
if(uri.Query == "")
// add a default name for / ended pathes
strLocalPath += "default.html";
// check if the uri includes a query string
if(uri.Query != "")
// construct the name from the query hash value to be the same if we download it again
strLocalPath += uri.Query.GetHashCode()+".html";
// construct the full path folder
string BasePath = this.Downloadfolder+"\\"+uri.Host+Path.GetDirectoryName(uri.AbsolutePath);
// check if the folder not found
if(Directory.Exists(BasePath) == false)
// create the folder
Directory.CreateDirectory(BasePath);
// construct the full path name of the file
PathName = this.Downloadfolder+"\\"+uri.Host+strLocalPath.Replace("%20", " ");
// open the output file
streamOut = File.Open(PathName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
writer = new BinaryWriter(streamOut);
}
itemLog.SubItems[2].Text = "Download";
itemLog.ForeColor = Color.Black;
// receive response buffer
string strResponse = "";
byte[] RecvBuffer = new byte[10240];
int nBytes, nTotalBytes = 0;
// loop to receive response buffer
while((nBytes = response.socket.Receive(RecvBuffer, 0, 10240, SocketFlags.None)) > 0)
{
// increment total received bytes
nTotalBytes += nBytes;
// write received buffer to file
// 将下载到的内容写入文件
if(IsSaveToFolder)
writer.Write(RecvBuffer, 0, nBytes);
// check if the uri type not binary to can be parsed for refs
if(bParse == true)
// add received buffer to response string
strResponse += Encoding.Default.GetString(RecvBuffer, 0, nBytes);
// update view text
itemLog.SubItems[4].Text = Commas(nTotalBytes);
if(response.ContentLength > 0)
itemLog.SubItems[5].Text = '%'+(100-(response.ContentLength-nTotalBytes)*100/response.ContentLength).ToString();
// check if connection Keep-Alive to can break the loop if response completed
if(response.KeepAlive && nTotalBytes >= response.ContentLength && response.ContentLength > 0)
break;
}
// // close output stream
if(IsSaveToFolder)
{
writer.Close();
streamOut.Close();
}
if(response.KeepAlive)
strStatus += "Connection kept alive to be used in subpages.\r\n";
else
{
// close response
response.Close();
strStatus += "Connection closed.\r\n";
}
// update status
// increment total file count
FileCount++;
// increment total bytes count
ByteCount += nTotalBytes;
if(ThreadsRunning == true && bParse == true && uri.Depth < WebDepth)
{
strStatus += "\r\nParsing page ...\r\n";
// check for restricted words
foreach(string strExcludeWord in ExcludeWords)
if(strExcludeWord.Trim().Length > 0 && strResponse.IndexOf(strExcludeWord) != -1)
{
LogError(uri.AbsoluteUri, strStatus+"\r\nPage includes reserved word ("+strExcludeWord+")");
EraseItem(itemLog);
return;
}
FindIndexPage(uri.AbsoluteUri, strResponse, ref request);
}
LogUri(uri.AbsoluteUri, strStatus);
}
catch(Exception e)
{
LogError(uri.AbsoluteUri, strStatus+e.Message);
request = null;
}
finally
{
EraseItem(itemLog);
}
}
void ParseIndexUri(MyUri uri)
{
try
{
DataTable myTable = llay.GetIndexURL(uri.AbsoluteUri);
foreach(DataRow dRow in myTable.Rows)
{
string pageContent = System.Text.Encoding.Default.GetString((byte[])dRow[1]);
int id= Convert.ToInt32(dRow[0]);
string url= uri.AbsoluteUri;
FindSubPage(Convert.ToInt32(dRow[0]), uri.AbsoluteUri, pageContent);
break;
}
}catch(Exception e){}
}
///
/// 将从源码中取出超链接,取出有用的插入到数据库
///
/// 完整的网址
/// 网页的内容源代码
public void FindIndexPage(string strURL, string strPageContent, ref MyWebRequest request)
{
PageElement pe = new PageElement();
HtmlParser myParser = null;
HtmlParser myParser1 = null;
try
{
myParser = new HtmlParser(strPageContent);
}
catch(System.UriFormatException eURI){}
catch(System.NullReferenceException nr){}
//对URL文本进行分析,添加有用的URL
foreach(Anchor myAnchor in myParser.GetURLs())
{
MyUri newUri=null;
MyUri uri=null;
try
{
//获得网址
pe.URL = myAnchor.AnchorUri;
newUri = new MyUri(strURL);
// 如果是外部链接
uri = new MyUri(pe.URL);
if(pe.URL.Length>8 && pe.URL.Length<26 && pe.URL.IndexOf("?")==-1 && pe.URL.IndexOf (newUri.Host) ==-1 && pe.URL.IndexOf ("http://") !=-1)
{
pe.URL = uri.AbsoluteUri;
//获取锚文本
pe.HrefText = myAnchor.AnchorText;
// // 获得源代码
// pe.PageSourceCode = GetPageSourceCode(pe.URL, ref request, false);
// myParser1 = new HtmlParser(pe.PageSourceCode);
// //获取关键词
// pe.Keywords = myParser1.GetKeywords();
// //获取标题
// pe.Title = myParser1.GetTitle();
// 判断是否为要过滤的网址
if(!filterURL.isFilterURL(ref pe))
{
// 获得源代码
pe.PageSourceCode = GetPageSourceCode(pe.URL, ref request, false, false);
if(pe.PageSourceCode.Length<20)
continue;
//插入到 URLs 表
Monitor.Enter(URLCount);
llay.InsertIndexPage(pe);
URLCount += 1;
if(URLCount==ThreadCount)
{
ThreadSubCount =ThreadCount;
}
Monitor.Exit(URLCount);
}//end if
}
}
catch(System.NullReferenceException eNull){ continue;}
catch(Exception ne){continue;}
}//end foreach
}
///
/// 取得子页面
///
/// 父亲页面的ID号
/// 完整的网址
/// 网页的内容源代码
public void FindSubPage(int parentID, string strURL, string strPageContent)
{
MyWebRequest request = null;
PageElement pe = new PageElement();
HtmlParser myParser = null;
HtmlParser myParser1 = null;
int urlCount = 0;
try
{
myParser = new HtmlParser(strPageContent);
}
catch(System.UriFormatException eURI){}
catch(System.NullReferenceException nr){}
//对URL文本进行分析,添加有用的URL
foreach(Anchor myAnchor in myParser.GetURLs())
{
try
{
//获得网址
pe.URL = myAnchor.AnchorUri;
MyUri uri = new MyUri(strURL);
//如果是内部的
if((pe.URL.IndexOf (uri.Host) !=-1 || pe.URL.IndexOf ("http://") ==-1) && (pe.URL.Length>4 && pe.URL.Length<40) && (pe.URL.IndexOf("#")==-1))// && aUrl.IndexOf("?")==-1)
{
if(pe.URL.IndexOf("..") != -1 || pe.URL.StartsWith("/") == true || pe.URL.StartsWith("http://") == false)
pe.URL = new Uri(uri, pe.URL).AbsoluteUri;
Normalize(ref pe);
//获取锚文本
pe.HrefText = myAnchor.AnchorText;
// 判断是否为要过滤的网址
if(!filterURL.isFilterURL(ref pe) && urlCount < SubPageLimitNum)
{
// 获得源代码
pe.PageSourceCode = GetPageSourceCode(pe.URL, ref request, true, false);
pe.IndexPageID = parentID;
// myParser1 = new HtmlParser(pe.PageSourceCode);
// //获取关键词
// pe.Keywords = myParser1.GetKeywords();
// //获取标题
// pe.Title = myParser1.GetTitle();
//插入到 URLs 表
if(pe.PageSourceCode.Length<20)
continue;
Monitor.Enter(this);
llay.InsertSubPage(pe);
SubURLCount+=1;
statusBarPanelSubURLs.Text = SubURLCount+"条子页面";
urlCount += 1;
Monitor.Exit(this);
}//end if
}
}
catch(System.NullReferenceException eNull){ continue;}
catch(Exception ne){continue;}
}
}
// 取得一个给定的URL的源代码
///
/// 取得一个给定的URL的源代码
///
/// URL
/// 请求对象
/// 是否保存连接
///
public string GetPageSourceCode(string strURL, ref MyWebRequest request, bool KeepAlive, bool isDisplay)
{
string strResponse = "";
string strStatus = "";
MyUri uri = new MyUri(strURL);
if(request != null && request.response.KeepAlive)
strStatus += "Connection live to: "+uri.Host+"\r\n\r\n";
else
strStatus += "Connecting: "+uri.Host+"\r\n\r\n";
ListViewItem itemLog = null;
if(isDisplay)
{
//更新显示ListView中的内容
Monitor.Enter(this.listViewThreads);
try
{
// update thread information in the threads view list
itemLog = this.listViewThreads.Items[int.Parse(Thread.CurrentThread.Name)];
int nDepth = uri.Depth;
itemLog.SubItems[1].Text = nDepth.ToString();
itemLog.ImageIndex = 1;
itemLog.BackColor = Color.WhiteSmoke;
// initialize status to Connect
itemLog.SubItems[2].Text = "Connect";
itemLog.ForeColor = Color.Red;
itemLog.SubItems[3].Text = uri.AbsoluteUri;
itemLog.SubItems[4].Text = "";
itemLog.SubItems[5].Text = "";
itemLog.SubItems[6].Text = "0";
}
catch(Exception){}
Monitor.Exit(this.listViewThreads);
}
try
{
// create web request
// 创建一个web request 对象
request = MyWebRequest.Create(uri, request, KeepAlive);
// set request timeout
//设置超时时间
request.Timeout = RequestTimeout*1000;
// retrieve response from web request
// 获取来自服务器的回应
MyWebResponse response = request.GetResponse();
// update status text with the request and response headers
// 更新文件头的状态信息
strStatus += request.Header+response.Header;
// check for redirection
// 检查是否为重定向
if(response.ResponseUri.Equals(uri) == false)
{
// add the new uri to the queue
// 将URL加入到队列中
//this.EnqueueUri(new MyUri(response.ResponseUri.AbsoluteUri), true);
// update status
// 更新状态信息
strStatus += "Redirected to: "+response.ResponseUri+"\r\n";
// log current uri status
// 写入日志文件
if(isDisplay)
LogUri(uri.AbsoluteUri, strStatus);
// reset current request to avoid response socket opening case
// 将当前请求复位
request = null;
return "";
}
// check for allowed MIME types
// 检查文件中的MIME类型
if(AllMIMETypes == false && response.ContentType != null && MIMETypes.Length > 0)
{
string strContentType = response.ContentType.ToLower();
int nExtIndex = strContentType.IndexOf(';');
if(nExtIndex != -1)
strContentType = strContentType.Substring(0, nExtIndex);
if(strContentType.IndexOf('*') == -1 && (nExtIndex = MIMETypes.IndexOf(strContentType)) == -1)
{
if(isDisplay)
LogError(uri.AbsoluteUri, strStatus+"\r\nUnlisted Content-Type ("+strContentType+"), check settings.");
request = null;
return "";
}
// find numbers
Match match = new Regex(@"\d+").Match(MIMETypes, nExtIndex);
int nMin = int.Parse(match.Value)*1024;
match = match.NextMatch();
int nMax = int.Parse(match.Value)*1024;
if(nMin < nMax && (response.ContentLength < nMin || response.ContentLength > nMax))
{
LogError(uri.AbsoluteUri, strStatus+"\r\nContentLength limit error ("+response.ContentLength+")");
request = null;
return "";
}
}
// check for response extention
// 检查文件的扩展名是否为要排除的
bool bParse = true;
foreach(string ext in ExcludeFiles)
if(ext.Trim().Length > 0 && uri.AbsoluteUri.ToLower().EndsWith(ext) == true)
{
bParse = false;
break;
}
FileStream streamOut = null;
BinaryWriter writer = null;
string PathName = null;
// 如果要将文件下载到文件夹中
if(IsSaveToFolder)
{
// construct path in the hard disk
string strLocalPath = uri.LocalPath;
// check if the path ends with / to can crate the file on the HD
if(strLocalPath.EndsWith("/") == true)
// check if there is no query like (.asp?i=32&j=212)
if(uri.Query == "")
// add a default name for / ended pathes
strLocalPath += "default.html";
// check if the uri includes a query string
if(uri.Query != "")
// construct the name from the query hash value to be the same if we download it again
strLocalPath += uri.Query.GetHashCode()+".html";
// construct the full path folder
string BasePath = this.Downloadfolder+"\\"+uri.Host+Path.GetDirectoryName(uri.AbsolutePath);
// check if the folder not found
if(Directory.Exists(BasePath) == false)
// create the folder
Directory.CreateDirectory(BasePath);
// construct the full path name of the file
PathName = this.Downloadfolder+"\\"+uri.Host+strLocalPath.Replace("%20", " ");
// open the output file
streamOut = File.Open(PathName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
writer = new BinaryWriter(streamOut);
}
if(isDisplay)
{
itemLog.SubItems[2].Text = "Download";
itemLog.ForeColor = Color.Black;
}
// receive response buffer
byte[] RecvBuffer = new byte[50240];
int nBytes, nTotalBytes = 0;
// loop to receive response buffer
while((nBytes = response.socket.Receive(RecvBuffer, 0, 50240, SocketFlags.None)) > 0)
{
// increment total received bytes
nTotalBytes += nBytes;
// write received buffer to file
// 将下载到的内容写入文件
if(IsSaveToFolder)
writer.Write(RecvBuffer, 0, nBytes);
// check if the uri type not binary to can be parsed for refs
if(bParse == true)
// add received buffer to response string
strResponse += Encoding.Default.GetString(RecvBuffer, 0, nBytes);
// update view text
itemLog.SubItems[4].Text = Commas(nTotalBytes);
if(response.ContentLength > 0)
itemLog.SubItems[5].Text = '%'+(100-(response.ContentLength-nTotalBytes)*100/response.ContentLength).ToString();
// check if connection Keep-Alive to can break the loop if response completed
if(response.KeepAlive && nTotalBytes >= response.ContentLength && response.ContentLength > 0)
break;
}
// // close output stream
if(IsSaveToFolder)
{
writer.Close();
streamOut.Close();
}
if(response.KeepAlive)
strStatus += "Connection kept alive to be used in subpages.\r\n";
else
{
// close response
response.Close();
strStatus += "Connection closed.\r\n";
}
// increment total bytes count
ByteCount += nTotalBytes;
}
catch(Exception e)
{ request = null; }
return strResponse;
}
#endregion
// 工具栏事件
#region 工具栏事件
// 工具栏的按钮事件
private void toolBarMain_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button == this.toolBarButtonContinue)
StartOrContinueParsing(); // 开始
else if(e.Button == this.toolBarButtonPause)
PauseParsing(); // 继续
else if(e.Button == this.toolBarButtonStop)
StopParsing(); // 停止
else if(e.Button == this.toolBarButtonDeleteAll)
DeleteAllItems(); // 删除所有下载
else if(e.Button == this.toolBarButtonSettings)
ShowSettings(-1); // 显示设置选项窗口
}
// 将清除所有ListView中的所有信息
void DeleteAllItems()
{
if(MessageBox.Show(this, "你确认要删除所有的吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.listViewRequests.Items.Clear();
this.listViewThreads.Items.Clear();
this.listViewErrors.Items.Clear();
this.URLCount = 0;
this.labelStartTime.Text = "";
this.queueURLS.Clear();
this.urlStorage.Clear();
this.urlStorage = new SortTree();
this.URLCount = 0;
this.FileCount = 0;
this.ByteCount = 0;
this.ErrorCount = 0;
}
}
#endregion
// 所有的菜单事件
#region 所有的菜单事件
// "文件" 菜单中的退出菜单的事件
private void menuItemExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
// "选项" 菜单的设置菜单
private void menuItemSettings_Click(object sender, System.EventArgs e)
{
ShowSettings(-1);
}
// "选项" 菜单的设置实现函数
void ShowSettings(int nSelectedIndex)
{
SettingsForm form = new SettingsForm();
form.SelectedIndex = nSelectedIndex;
if(form.ShowDialog(this) == DialogResult.OK)
{
//重新获得线程的大小
ThreadCount = Settings.GetValue("Threads count", 10);
//重新设置环境变量的各个值
InitValues();
}
}
// "关于" 菜单的事件
private void menuItemAbout_Click(object sender, System.EventArgs e)
{
AboutForm form = new AboutForm();
form.ShowDialog();
}
// 清除菜单的事件
private void menuItemListDeleteAll_Click(object sender, System.EventArgs e)
{
DeleteAllItems();
}
// "选项" 菜单中的 "MIME 类型" 菜单项的事件
private void menuItemFileMatches_Click(object sender, System.EventArgs e)
{
ShowSettings(0);
}
// "选项" 菜单中的 "输出" 菜单项的事件
private void menuItemOutput_Click(object sender, System.EventArgs e)
{
ShowSettings(1);
}
// "选项" 菜单中的 "连接" 菜单项的事件
private void menuItemConnections_Click(object sender, System.EventArgs e)
{
ShowSettings(2);
}
// "选项" 菜单中的 "高级" 菜单项的事件
private void menuItemAdvanced_Click(object sender, System.EventArgs e)
{
ShowSettings(3);
}
// 工具栏中的 "选项" 菜单中的 "MIME 类型" 菜单项的事件
private void menuItemSettingsFileMatches_Click(object sender, System.EventArgs e)
{
ShowSettings(0);
}
// 工具栏中的"选项" 菜单中的 "输出" 菜单项的事件
private void menuItemSettingsOutput_Click(object sender, System.EventArgs e)
{
ShowSettings(1);
}
// 工具栏中的"选项" 菜单中的 "连接" 菜单项的事件
private void menuItemSettingsConnections_Click(object sender, System.EventArgs e)
{
ShowSettings(2);
}
// 工具栏中的"选项" 菜单中的 "高级" 菜单项的事件
private void menuItemSettingsAdvanced_Click(object sender, System.EventArgs e)
{
ShowSettings(3);
}
// 清除所有ListView菜单项的事件
private void menuItemListClear_Click(object sender, System.EventArgs e)
{
switch(this.tabControlRightView.SelectedTab.Text)
{
case "Threads":
this.listViewThreads.Items.Clear();
break;
case "Requests":
this.listViewRequests.Items.Clear();
break;
case "Errors":
this.listViewErrors.Items.Clear();
break;
}
}
#endregion
// 计时器代码:
// 实时显示连接的状态信息
// 实时更新显示内存和CPU的使用容量信息
#region 计时器代码
// 统计一个线程的下载时间,超时则删除
private void countTimetimer_Tick(object sender, System.EventArgs e)
{
ListViewItem itemThread;
for(int i=0;iDownloadTimeOut)
{
LogError(itemThread.SubItems[3].Text,"下载超时,虽然可以连接成功,但由于下但时间太长而停止");
EraseItem(itemThread);
Thread thread = this.threadsRun[i];
try
{
if(thread.ThreadState == ThreadState.Suspended)
thread.Resume();
thread.Abort();
}
catch(Exception ee){}
itemThread.SubItems[6].Text = "0";
threadsRun[i] = new Thread(new ThreadStart(ThreadRunFunction));
threadsRun[i].Name = i.ToString();
threadsRun[i].Start();
}
else
itemThread.SubItems[6].Text = Convert.ToString((Convert.ToInt32(itemThread.SubItems[6].Text)+1));
}
}
}
// 实时显示连接的状态信息
private void timerConnectionInfo_Tick(object sender, System.EventArgs e)
{
ConnectionInfo();
}
// 实时更新显示内存和CPU的使用容量信息
private void timerMem_Tick(object sender, System.EventArgs e)
{
FreeMemory = ramCounter.NextValue();
CPUUsage = (int)cpuCounter.NextValue();
}
// 实时更新输出信息选项卡的内容
private void CountSecondtimer_Tick(object sender, System.EventArgs e)
{
CountTime += 1;
tp_tSpentAllTime.Text = Convert.ToString(CountTime/60/60)+" 时"+
Convert.ToString(CountTime/60%60)+" 分"+
Convert.ToString(CountTime%60)+" 秒";
tp_tAlreadyDownNum.Text = Commas(this.URLCount+this.SubURLCount)+" 条";
labelActiveThread.Text = ThreadCount.ToString()+" 条";
labelTotaldownloadSizes.Text = Commas(nByteCount/1024+1)+ " KB";
labelErrorNum.Text = Commas(ErrorCount)+" 条";
// 如果当下载等待队列的URL条数小于十条时,就自动从数据库中读取一定的条数。
// 直到全部下载完
if(this.queueURLS.Count 2)
this.textBoxRequest.Text = item.SubItems[2].Text;
}
// 当显示错误URL的ListView有鼠标选择事件发生时的动作
private void listViewErrors_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.listViewErrors.SelectedItems.Count == 0)
return;
ListViewItem item = this.listViewErrors.SelectedItems[0];
this.textBoxErrorDescription.Text = item.SubItems[3].Text;
}
// 清除主页面ListView中的项
void EraseItem(ListViewItem item)
{
Monitor.Enter(this.listViewThreads);
try
{
item.SubItems[1].Text = "";
item.ImageIndex = 0;
item.BackColor = Color.WhiteSmoke;
item.ForeColor = Color.Black;
item.SubItems[2].Text = "";
item.SubItems[3].Text = "";
item.SubItems[4].Text = "";
item.SubItems[5].Text = "";
item.SubItems[6].Text = "";
}
finally
{
Monitor.Exit(this.listViewThreads);
}
}
// 在请求ListView中显示请示的网址
void LogUri(string strHead, string strBody)
{
if(LastRequestCount > 0)
{
Monitor.Enter(this.listViewRequests);
try
{
ListViewItem item = this.listViewRequests.Items.Insert(0, DateTime.Now.ToString());
item.SubItems.AddRange(new String[] { strHead, strBody });
while(this.listViewRequests.Items.Count > LastRequestCount)
this.listViewRequests.Items.RemoveAt(this.listViewRequests.Items.Count-1);
}
catch(Exception)
{
}
Monitor.Exit(this.listViewRequests);
}
}
// 在错误ListView中显示错误的URL
void LogError(string strHead, string strBody)
{
Monitor.Enter(this.listViewErrors);
try
{
ListViewItem item = this.listViewErrors.Items.Add((ErrorCount+1).ToString());
item.SubItems.AddRange(new String[] { DateTime.Now.ToString(), strHead, strBody });
//while(this.listViewErrors.Items.Count > 1000)
//this.listViewErrors.Items.RemoveAt(0);
}
catch(Exception)
{
}
Monitor.Exit(this.listViewErrors);
ErrorCount++;
}
#endregion
// 系统代码:
// 控件的声明
// 赋值
// 窗口初始化事件
// 窗口关闭事件
// 窗口消毁事件
#region 系统代码
// 系统自动生成的声明控件对象的代码
#region 系统自动生成的系统组件代码
private System.Windows.Forms.MenuItem menuItemFile;
private System.Windows.Forms.MenuItem menuItemExit;
private System.Windows.Forms.MenuItem menuItemOptions;
private System.Windows.Forms.MenuItem menuItemSettings;
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.ToolBar toolBarMain;
private System.Windows.Forms.ImageList imageList2;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.ToolBarButton toolBarButtonPause;
private System.Windows.Forms.ToolBarButton toolBarButtonStop;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButtonDeleteAll;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButtonSettings;
private System.Windows.Forms.MenuItem menuItemAbout;
private System.Windows.Forms.TabControl tabControlRightView;
private System.Windows.Forms.TabPage tabPageThreads;
private System.Windows.Forms.ListView listViewThreads;
private System.Windows.Forms.ColumnHeader columnHeaderTHreadID;
private System.Windows.Forms.ColumnHeader columnHeaderThreadURL;
private System.Windows.Forms.ColumnHeader columnHeaderThreadBytes;
private System.Windows.Forms.ColumnHeader columnHeaderThreadPersentage;
private System.Windows.Forms.ColumnHeader columnHeaderThreadDepth;
private System.Windows.Forms.StatusBarPanel statusBarPanelMem;
private System.Windows.Forms.ColumnHeader columnHeaderThreadAction;
private System.Windows.Forms.StatusBarPanel statusBarPanelByteCount;
private System.Windows.Forms.ImageList imageList3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ImageList imageList4;
private System.Windows.Forms.ToolBarButton toolBarButtonContinue;
private System.Windows.Forms.TabPage tabPageErrors;
private System.Windows.Forms.ColumnHeader columnHeaderErrorID;
private System.Windows.Forms.ColumnHeader columnHeaderErrorDescription;
private System.Windows.Forms.ColumnHeader columnHeaderErrorItem;
private System.Windows.Forms.Splitter splitter3;
private System.Windows.Forms.TextBox textBoxErrorDescription;
private System.Windows.Forms.ListView listViewErrors;
private System.Windows.Forms.ContextMenu contextMenuBrowse;
private System.Windows.Forms.MenuItem menuItemBrowseHttp;
private System.Windows.Forms.StatusBarPanel statusBarPanelErrors;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ColumnHeader columnHeaderDate;
private System.Windows.Forms.Timer timerMem;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItemFileMatches;
private System.Windows.Forms.MenuItem menuItemOutput;
private System.Windows.Forms.MenuItem menuItemConnections;
private System.Windows.Forms.MenuItem menuItemHelp;
private System.Windows.Forms.ContextMenu contextMenuNavigate;
private System.Windows.Forms.ContextMenu contextMenuSettings;
private System.Windows.Forms.MenuItem menuItemSettingsFileMatches;
private System.Windows.Forms.MenuItem menuItemSettingsOutput;
private System.Windows.Forms.MenuItem menuItemSettingsConnections;
private System.Windows.Forms.MenuItem menuItemCopy;
private System.Windows.Forms.MenuItem menuItemPaste;
private System.Windows.Forms.MenuItem menuItemCut;
private System.Windows.Forms.MenuItem menuItemDelete;
private System.Windows.Forms.MenuItem menuItemSettingsAdvanced;
private System.Windows.Forms.MenuItem menuItemAdvanced;
private System.Windows.Forms.TabPage tabPageRequests;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ListView listViewRequests;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.TextBox textBoxRequest;
private System.Windows.Forms.MenuItem menuItemHttp;
private System.Windows.Forms.StatusBarPanel statusBarPanelCPU;
private System.Windows.Forms.Timer timerConnectionInfo;
private System.Windows.Forms.ImageList imageListPercentage;
private System.Windows.Forms.StatusBarPanel statusBarPanelInfo;
private System.Windows.Forms.StatusBarPanel statusBarPanelURLs;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Timer CountSecondtimer;
private System.Windows.Forms.Label tp_tAlreadyDownNum;
private System.Windows.Forms.Label tp_tSpentAllTime;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label labelErrorNum;
private System.Windows.Forms.Label labelActiveThread;
private System.Windows.Forms.Label labelNetInfo;
private System.Windows.Forms.Label labelStartTime;
private System.Windows.Forms.Label labelEndTime;
#endregion
#region 系统自动生成的初始化控件对象的代码
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CrawlerForm));
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menuItemFile = new System.Windows.Forms.MenuItem();
this.menuItemExit = new System.Windows.Forms.MenuItem();
this.menuItemOptions = new System.Windows.Forms.MenuItem();
this.menuItemSettings = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItemFileMatches = new System.Windows.Forms.MenuItem();
this.menuItemOutput = new System.Windows.Forms.MenuItem();
this.menuItemConnections = new System.Windows.Forms.MenuItem();
this.menuItemAdvanced = new System.Windows.Forms.MenuItem();
this.menuItemHelp = new System.Windows.Forms.MenuItem();
this.menuItemAbout = new System.Windows.Forms.MenuItem();
this.toolBarMain = new System.Windows.Forms.ToolBar();
this.toolBarButtonContinue = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonPause = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonStop = new System.Windows.Forms.ToolBarButton();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonDeleteAll = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonSettings = new System.Windows.Forms.ToolBarButton();
this.contextMenuSettings = new System.Windows.Forms.ContextMenu();
this.menuItemSettingsFileMatches = new System.Windows.Forms.MenuItem();
this.menuItemSettingsOutput = new System.Windows.Forms.MenuItem();
this.menuItemSettingsConnections = new System.Windows.Forms.MenuItem();
this.menuItemSettingsAdvanced = new System.Windows.Forms.MenuItem();
this.imageList2 = new System.Windows.Forms.ImageList(this.components);
this.statusBar = new System.Windows.Forms.StatusBar();
this.statusBarPanelInfo = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelURLs = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelSubURLs = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelByteCount = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelErrors = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelCPU = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelMem = new System.Windows.Forms.StatusBarPanel();
this.contextMenuBrowse = new System.Windows.Forms.ContextMenu();
this.menuItemBrowseHttp = new System.Windows.Forms.MenuItem();
this.menuItemHttp = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.imageList4 = new System.Windows.Forms.ImageList(this.components);
this.tabControlRightView = new System.Windows.Forms.TabControl();
this.tabPageThreads = new System.Windows.Forms.TabPage();
this.listViewThreads = new System.Windows.Forms.ListView();
this.columnHeaderTHreadID = new System.Windows.Forms.ColumnHeader();
this.columnHeaderThreadDepth = new System.Windows.Forms.ColumnHeader();
this.columnHeaderThreadAction = new System.Windows.Forms.ColumnHeader();
this.columnHeaderThreadURL = new System.Windows.Forms.ColumnHeader();
this.columnHeaderThreadBytes = new System.Windows.Forms.ColumnHeader();
this.columnHeaderThreadPersentage = new System.Windows.Forms.ColumnHeader();
this.columnHeaderCountTime = new System.Windows.Forms.ColumnHeader();
this.imageList3 = new System.Windows.Forms.ImageList(this.components);
this.tabPageErrors = new System.Windows.Forms.TabPage();
this.textBoxErrorDescription = new System.Windows.Forms.TextBox();
this.splitter3 = new System.Windows.Forms.Splitter();
this.listViewErrors = new System.Windows.Forms.ListView();
this.columnHeaderErrorID = new System.Windows.Forms.ColumnHeader();
this.columnHeaderDate = new System.Windows.Forms.ColumnHeader();
this.columnHeaderErrorItem = new System.Windows.Forms.ColumnHeader();
this.columnHeaderErrorDescription = new System.Windows.Forms.ColumnHeader();
this.tabPageRequests = new System.Windows.Forms.TabPage();
this.textBoxRequest = new System.Windows.Forms.TextBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.listViewRequests = new System.Windows.Forms.ListView();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tp_tSpentAllTime = new System.Windows.Forms.Label();
this.tp_tAlreadyDownNum = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.labelErrorNum = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.labelActiveThread = new System.Windows.Forms.Label();
this.labelTotaldownloadSizes = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.labelNetInfo = new System.Windows.Forms.Label();
this.labelStartTime = new System.Windows.Forms.Label();
this.labelEndTime = new System.Windows.Forms.Label();
this.contextMenuNavigate = new System.Windows.Forms.ContextMenu();
this.menuItemCut = new System.Windows.Forms.MenuItem();
this.menuItemCopy = new System.Windows.Forms.MenuItem();
this.menuItemPaste = new System.Windows.Forms.MenuItem();
this.menuItemDelete = new System.Windows.Forms.MenuItem();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.timerMem = new System.Windows.Forms.Timer(this.components);
this.imageListPercentage = new System.Windows.Forms.ImageList(this.components);
this.timerConnectionInfo = new System.Windows.Forms.Timer(this.components);
this.CountSecondtimer = new System.Windows.Forms.Timer(this.components);
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.isOvertimer = new System.Windows.Forms.Timer(this.components);
this.countTimetimer = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelInfo)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelURLs)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelSubURLs)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelByteCount)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelErrors)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelCPU)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelMem)).BeginInit();
this.tabControlRightView.SuspendLayout();
this.tabPageThreads.SuspendLayout();
this.tabPageErrors.SuspendLayout();
this.tabPageRequests.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemFile,
this.menuItemOptions,
this.menuItemHelp});
//
// menuItemFile
//
this.menuItemFile.Index = 0;
this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemExit});
this.menuItemFile.Text = "文件";
//
// menuItemExit
//
this.menuItemExit.Index = 0;
this.menuItemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menuItemExit.Text = "退出";
this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
//
// menuItemOptions
//
this.menuItemOptions.Index = 1;
this.menuItemOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemSettings,
this.menuItem1,
this.menuItemFileMatches,
this.menuItemOutput,
this.menuItemConnections,
this.menuItemAdvanced});
this.menuItemOptions.Text = "选项";
//
// menuItemSettings
//
this.menuItemSettings.Index = 0;
this.menuItemSettings.Text = "设置..";
this.menuItemSettings.Click += new System.EventHandler(this.menuItemSettings_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "-";
//
// menuItemFileMatches
//
this.menuItemFileMatches.Index = 2;
this.menuItemFileMatches.Text = "MIME类型设置...";
this.menuItemFileMatches.Click += new System.EventHandler(this.menuItemFileMatches_Click);
//
// menuItemOutput
//
this.menuItemOutput.Index = 3;
this.menuItemOutput.Text = "输出...";
this.menuItemOutput.Click += new System.EventHandler(this.menuItemOutput_Click);
//
// menuItemConnections
//
this.menuItemConnections.Index = 4;
this.menuItemConnections.Text = "连接...";
this.menuItemConnections.Click += new System.EventHandler(this.menuItemConnections_Click);
//
// menuItemAdvanced
//
this.menuItemAdvanced.Index = 5;
this.menuItemAdvanced.Text = "高级...";
this.menuItemAdvanced.Click += new System.EventHandler(this.menuItemAdvanced_Click);
//
// menuItemHelp
//
this.menuItemHelp.Index = 2;
this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemAbout});
this.menuItemHelp.Text = "帮助";
//
// menuItemAbout
//
this.menuItemAbout.Index = 0;
this.menuItemAbout.Text = "关于作者...";
this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
//
// toolBarMain
//
this.toolBarMain.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBarMain.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButtonContinue,
this.toolBarButtonPause,
this.toolBarButtonStop,
this.toolBarButton1,
this.toolBarButtonDeleteAll,
this.toolBarButton2,
this.toolBarButtonSettings});
this.toolBarMain.ButtonSize = new System.Drawing.Size(16, 16);
this.toolBarMain.DropDownArrows = true;
this.toolBarMain.ImageList = this.imageList2;
this.toolBarMain.Location = new System.Drawing.Point(0, 0);
this.toolBarMain.Name = "toolBarMain";
this.toolBarMain.ShowToolTips = true;
this.toolBarMain.Size = new System.Drawing.Size(792, 28);
this.toolBarMain.TabIndex = 0;
this.toolBarMain.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarMain_ButtonClick);
//
// toolBarButtonContinue
//
this.toolBarButtonContinue.ImageIndex = 0;
this.toolBarButtonContinue.ToolTipText = "开始下载";
//
// toolBarButtonPause
//
this.toolBarButtonPause.Enabled = false;
this.toolBarButtonPause.ImageIndex = 1;
this.toolBarButtonPause.ToolTipText = "暂停下载";
//
// toolBarButtonStop
//
this.toolBarButtonStop.Enabled = false;
this.toolBarButtonStop.ImageIndex = 2;
this.toolBarButtonStop.ToolTipText = "停止下载";
//
// toolBarButton1
//
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButtonDeleteAll
//
this.toolBarButtonDeleteAll.ImageIndex = 3;
this.toolBarButtonDeleteAll.ToolTipText = "删除所有结果";
//
// toolBarButton2
//
this.toolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButtonSettings
//
this.toolBarButtonSettings.DropDownMenu = this.contextMenuSettings;
this.toolBarButtonSettings.ImageIndex = 4;
this.toolBarButtonSettings.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
this.toolBarButtonSettings.ToolTipText = "Show settings form";
//
// contextMenuSettings
//
this.contextMenuSettings.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemSettingsFileMatches,
this.menuItemSettingsOutput,
this.menuItemSettingsConnections,
this.menuItemSettingsAdvanced});
//
// menuItemSettingsFileMatches
//
this.menuItemSettingsFileMatches.Index = 0;
this.menuItemSettingsFileMatches.Text = "MIME 类型...";
this.menuItemSettingsFileMatches.Click += new System.EventHandler(this.menuItemSettingsFileMatches_Click);
//
// menuItemSettingsOutput
//
this.menuItemSettingsOutput.Index = 1;
this.menuItemSettingsOutput.Text = "输出...";
this.menuItemSettingsOutput.Click += new System.EventHandler(this.menuItemSettingsOutput_Click);
//
// menuItemSettingsConnections
//
this.menuItemSettingsConnections.Index = 2;
this.menuItemSettingsConnections.Text = "连接...";
this.menuItemSettingsConnections.Click += new System.EventHandler(this.menuItemSettingsConnections_Click);
//
// menuItemSettingsAdvanced
//
this.menuItemSettingsAdvanced.Index = 3;
this.menuItemSettingsAdvanced.Text = "高级...";
this.menuItemSettingsAdvanced.Click += new System.EventHandler(this.menuItemSettingsAdvanced_Click);
//
// imageList2
//
this.imageList2.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageList2.ImageSize = new System.Drawing.Size(16, 16);
this.imageList2.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList2.ImageStream")));
this.imageList2.TransparentColor = System.Drawing.Color.Transparent;
//
// statusBar
//
this.statusBar.Location = new System.Drawing.Point(0, 313);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanelInfo,
this.statusBarPanelURLs,
this.statusBarPanelSubURLs,
this.statusBarPanelByteCount,
this.statusBarPanelErrors,
this.statusBarPanelCPU,
this.statusBarPanelMem});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(792, 24);
this.statusBar.TabIndex = 1;
this.statusBar.Text = "提示信息";
//
// statusBarPanelInfo
//
this.statusBarPanelInfo.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanelInfo.Width = 505;
//
// statusBarPanelURLs
//
this.statusBarPanelURLs.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanelURLs.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanelURLs.ToolTipText = "条主页面";
this.statusBarPanelURLs.Width = 10;
//
// statusBarPanelSubURLs
//
this.statusBarPanelSubURLs.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanelSubURLs.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanelSubURLs.ToolTipText = "条子页面";
this.statusBarPanelSubURLs.Width = 10;
//
// statusBarPanelByteCount
//
this.statusBarPanelByteCount.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanelByteCount.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanelByteCount.ToolTipText = "已下载的字节数";
this.statusBarPanelByteCount.Width = 10;
//
// statusBarPanelErrors
//
this.statusBarPanelErrors.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanelErrors.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanelErrors.Icon = ((System.Drawing.Icon)(resources.GetObject("statusBarPanelErrors.Icon")));
this.statusBarPanelErrors.ToolTipText = "错误条数";
this.statusBarPanelErrors.Width = 31;
//
// statusBarPanelCPU
//
this.statusBarPanelCPU.Icon = ((System.Drawing.Icon)(resources.GetObject("statusBarPanelCPU.Icon")));
this.statusBarPanelCPU.ToolTipText = "CPU 使用率";
this.statusBarPanelCPU.Width = 110;
//
// statusBarPanelMem
//
this.statusBarPanelMem.ToolTipText = "可用的内存";
//
// contextMenuBrowse
//
this.contextMenuBrowse.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemBrowseHttp});
//
// menuItemBrowseHttp
//
this.menuItemBrowseHttp.Index = 0;
this.menuItemBrowseHttp.Text = "";
//
// menuItemHttp
//
this.menuItemHttp.Index = -1;
this.menuItemHttp.Text = "";
//
// menuItem5
//
this.menuItem5.Index = -1;
this.menuItem5.Text = "-";
//
// imageList4
//
this.imageList4.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageList4.ImageSize = new System.Drawing.Size(58, 15);
this.imageList4.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList4.ImageStream")));
this.imageList4.TransparentColor = System.Drawing.Color.Teal;
//
// tabControlRightView
//
this.tabControlRightView.Controls.Add(this.tabPageThreads);
this.tabControlRightView.Controls.Add(this.tabPageErrors);
this.tabControlRightView.Controls.Add(this.tabPageRequests);
this.tabControlRightView.Controls.Add(this.tabPage1);
this.tabControlRightView.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControlRightView.ImageList = this.imageList3;
this.tabControlRightView.Location = new System.Drawing.Point(0, 28);
this.tabControlRightView.Name = "tabControlRightView";
this.tabControlRightView.SelectedIndex = 0;
this.tabControlRightView.ShowToolTips = true;
this.tabControlRightView.Size = new System.Drawing.Size(792, 285);
this.tabControlRightView.TabIndex = 7;
this.tabControlRightView.Tag = "";
//
// tabPageThreads
//
this.tabPageThreads.Controls.Add(this.listViewThreads);
this.tabPageThreads.ImageIndex = 6;
this.tabPageThreads.Location = new System.Drawing.Point(4, 23);
this.tabPageThreads.Name = "tabPageThreads";
this.tabPageThreads.Size = new System.Drawing.Size(784, 258);
this.tabPageThreads.TabIndex = 3;
this.tabPageThreads.Text = "主页面线程";
this.tabPageThreads.ToolTipText = "View working threads status";
//
// listViewThreads
//
this.listViewThreads.BackColor = System.Drawing.Color.WhiteSmoke;
this.listViewThreads.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeaderTHreadID,
this.columnHeaderThreadDepth,
this.columnHeaderThreadAction,
this.columnHeaderThreadURL,
this.columnHeaderThreadBytes,
this.columnHeaderThreadPersentage,
this.columnHeaderCountTime});
this.listViewThreads.Dock = System.Windows.Forms.DockStyle.Fill;
this.listViewThreads.FullRowSelect = true;
this.listViewThreads.GridLines = true;
this.listViewThreads.HideSelection = false;
this.listViewThreads.Location = new System.Drawing.Point(0, 0);
this.listViewThreads.MultiSelect = false;
this.listViewThreads.Name = "listViewThreads";
this.listViewThreads.Size = new System.Drawing.Size(784, 258);
this.listViewThreads.SmallImageList = this.imageList3;
this.listViewThreads.TabIndex = 0;
this.listViewThreads.View = System.Windows.Forms.View.Details;
//
// columnHeaderTHreadID
//
this.columnHeaderTHreadID.Text = "ID";
this.columnHeaderTHreadID.Width = 40;
//
// columnHeaderThreadDepth
//
this.columnHeaderThreadDepth.Text = "深度";
this.columnHeaderThreadDepth.Width = 43;
//
// columnHeaderThreadAction
//
this.columnHeaderThreadAction.Text = "动作";
//
// columnHeaderThreadURL
//
this.columnHeaderThreadURL.Text = "网址";
this.columnHeaderThreadURL.Width = 300;
//
// columnHeaderThreadBytes
//
this.columnHeaderThreadBytes.Text = "字节";
this.columnHeaderThreadBytes.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.columnHeaderThreadBytes.Width = 70;
//
// columnHeaderThreadPersentage
//
this.columnHeaderThreadPersentage.Text = "%";
this.columnHeaderThreadPersentage.Width = 40;
//
// columnHeaderCountTime
//
this.columnHeaderCountTime.Text = "计时";
//
// imageList3
//
this.imageList3.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageList3.ImageSize = new System.Drawing.Size(16, 16);
this.imageList3.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList3.ImageStream")));
this.imageList3.TransparentColor = System.Drawing.Color.Transparent;
//
// tabPageErrors
//
this.tabPageErrors.Controls.Add(this.textBoxErrorDescription);
this.tabPageErrors.Controls.Add(this.splitter3);
this.tabPageErrors.Controls.Add(this.listViewErrors);
this.tabPageErrors.ImageIndex = 7;
this.tabPageErrors.Location = new System.Drawing.Point(4, 23);
this.tabPageErrors.Name = "tabPageErrors";
this.tabPageErrors.Size = new System.Drawing.Size(784, 258);
this.tabPageErrors.TabIndex = 4;
this.tabPageErrors.Text = "错误记录";
this.tabPageErrors.ToolTipText = "View reported errors";
//
// textBoxErrorDescription
//
this.textBoxErrorDescription.BackColor = System.Drawing.Color.WhiteSmoke;
this.textBoxErrorDescription.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxErrorDescription.Location = new System.Drawing.Point(0, 167);
this.textBoxErrorDescription.Multiline = true;
this.textBoxErrorDescription.Name = "textBoxErrorDescription";
this.textBoxErrorDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxErrorDescription.Size = new System.Drawing.Size(784, 91);
this.textBoxErrorDescription.TabIndex = 2;
this.textBoxErrorDescription.Text = "";
this.textBoxErrorDescription.WordWrap = false;
//
// splitter3
//
this.splitter3.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter3.Location = new System.Drawing.Point(0, 164);
this.splitter3.Name = "splitter3";
this.splitter3.Size = new System.Drawing.Size(784, 3);
this.splitter3.TabIndex = 1;
this.splitter3.TabStop = false;
//
// listViewErrors
//
this.listViewErrors.BackColor = System.Drawing.Color.WhiteSmoke;
this.listViewErrors.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeaderErrorID,
this.columnHeaderDate,
this.columnHeaderErrorItem,
this.columnHeaderErrorDescription});
this.listViewErrors.Dock = System.Windows.Forms.DockStyle.Top;
this.listViewErrors.FullRowSelect = true;
this.listViewErrors.GridLines = true;
this.listViewErrors.HideSelection = false;
this.listViewErrors.Location = new System.Drawing.Point(0, 0);
this.listViewErrors.MultiSelect = false;
this.listViewErrors.Name = "listViewErrors";
this.listViewErrors.Size = new System.Drawing.Size(784, 164);
this.listViewErrors.TabIndex = 0;
this.listViewErrors.View = System.Windows.Forms.View.Details;
this.listViewErrors.SelectedIndexChanged += new System.EventHandler(this.listViewErrors_SelectedIndexChanged);
//
// columnHeaderErrorID
//
this.columnHeaderErrorID.Text = "ID";
//
// columnHeaderDate
//
this.columnHeaderDate.Text = "时间";
this.columnHeaderDate.Width = 160;
//
// columnHeaderErrorItem
//
this.columnHeaderErrorItem.Text = "发生错误的网址";
this.columnHeaderErrorItem.Width = 343;
//
// columnHeaderErrorDescription
//
this.columnHeaderErrorDescription.Text = "具体描述";
this.columnHeaderErrorDescription.Width = 0;
//
// tabPageRequests
//
this.tabPageRequests.Controls.Add(this.textBoxRequest);
this.tabPageRequests.Controls.Add(this.splitter1);
this.tabPageRequests.Controls.Add(this.listViewRequests);
this.tabPageRequests.ImageIndex = 8;
this.tabPageRequests.Location = new System.Drawing.Point(4, 23);
this.tabPageRequests.Name = "tabPageRequests";
this.tabPageRequests.Size = new System.Drawing.Size(784, 258);
this.tabPageRequests.TabIndex = 5;
this.tabPageRequests.Text = "请求";
//
// textBoxRequest
//
this.textBoxRequest.BackColor = System.Drawing.Color.WhiteSmoke;
this.textBoxRequest.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxRequest.Location = new System.Drawing.Point(0, 167);
this.textBoxRequest.Multiline = true;
this.textBoxRequest.Name = "textBoxRequest";
this.textBoxRequest.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxRequest.Size = new System.Drawing.Size(784, 91);
this.textBoxRequest.TabIndex = 5;
this.textBoxRequest.Text = "";
this.textBoxRequest.WordWrap = false;
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 164);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(784, 3);
this.splitter1.TabIndex = 4;
this.splitter1.TabStop = false;
//
// listViewRequests
//
this.listViewRequests.BackColor = System.Drawing.Color.WhiteSmoke;
this.listViewRequests.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.listViewRequests.Dock = System.Windows.Forms.DockStyle.Top;
this.listViewRequests.FullRowSelect = true;
this.listViewRequests.GridLines = true;
this.listViewRequests.HideSelection = false;
this.listViewRequests.Location = new System.Drawing.Point(0, 0);
this.listViewRequests.MultiSelect = false;
this.listViewRequests.Name = "listViewRequests";
this.listViewRequests.Size = new System.Drawing.Size(784, 164);
this.listViewRequests.TabIndex = 3;
this.listViewRequests.View = System.Windows.Forms.View.Details;
this.listViewRequests.SelectedIndexChanged += new System.EventHandler(this.listViewRequests_SelectedIndexChanged);
//
// columnHeader2
//
this.columnHeader2.Text = "请求时间";
this.columnHeader2.Width = 140;
//
// columnHeader3
//
this.columnHeader3.Text = "正在请求";
this.columnHeader3.Width = 400;
//
// columnHeader4
//
this.columnHeader4.Text = "描述";
this.columnHeader4.Width = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox3);
this.tabPage1.Location = new System.Drawing.Point(4, 23);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(784, 258);
this.tabPage1.TabIndex = 7;
this.tabPage1.Text = "输出信息";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.tp_tSpentAllTime);
this.groupBox3.Controls.Add(this.tp_tAlreadyDownNum);
this.groupBox3.Controls.Add(this.label16);
this.groupBox3.Controls.Add(this.label14);
this.groupBox3.Controls.Add(this.label9);
this.groupBox3.Controls.Add(this.label11);
this.groupBox3.Controls.Add(this.label12);
this.groupBox3.Controls.Add(this.label13);
this.groupBox3.Controls.Add(this.labelErrorNum);
this.groupBox3.Controls.Add(this.label2);
this.groupBox3.Controls.Add(this.labelActiveThread);
this.groupBox3.Controls.Add(this.labelTotaldownloadSizes);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.labelNetInfo);
this.groupBox3.Controls.Add(this.labelStartTime);
this.groupBox3.Controls.Add(this.labelEndTime);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox3.Location = new System.Drawing.Point(0, 0);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(784, 200);
this.groupBox3.TabIndex = 23;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "输出信息";
//
// tp_tSpentAllTime
//
this.tp_tSpentAllTime.Location = new System.Drawing.Point(136, 66);
this.tp_tSpentAllTime.Name = "tp_tSpentAllTime";
this.tp_tSpentAllTime.Size = new System.Drawing.Size(176, 24);
this.tp_tSpentAllTime.TabIndex = 54;
this.tp_tSpentAllTime.Tag = "已用时(秒)";
//
// tp_tAlreadyDownNum
//
this.tp_tAlreadyDownNum.Location = new System.Drawing.Point(415, 66);
this.tp_tAlreadyDownNum.Name = "tp_tAlreadyDownNum";
this.tp_tAlreadyDownNum.Size = new System.Drawing.Size(96, 24);
this.tp_tAlreadyDownNum.TabIndex = 53;
this.tp_tAlreadyDownNum.Tag = "已下载的条数";
//
// label16
//
this.label16.AutoSize = true;
this.label16.Location = new System.Drawing.Point(330, 106);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(79, 17);
this.label16.TabIndex = 52;
this.label16.Text = "活动线程数:";
//
// label14
//
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(56, 28);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(66, 17);
this.label14.TabIndex = 50;
this.label14.Text = "网络连接:";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(68, 66);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(54, 17);
this.label9.TabIndex = 42;
this.label9.Text = "已用时:";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(56, 150);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(66, 17);
this.label11.TabIndex = 39;
this.label11.Text = "结束时间:";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(56, 108);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(66, 17);
this.label12.TabIndex = 38;
this.label12.Text = "开始时间:";
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(318, 67);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(91, 17);
this.label13.TabIndex = 35;
this.label13.Text = "已下载的条数:";
//
// labelErrorNum
//
this.labelErrorNum.Location = new System.Drawing.Point(602, 63);
this.labelErrorNum.Name = "labelErrorNum";
this.labelErrorNum.Size = new System.Drawing.Size(96, 24);
this.labelErrorNum.TabIndex = 53;
this.labelErrorNum.Tag = "错误条数:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(530, 65);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 17);
this.label2.TabIndex = 35;
this.label2.Text = "错误条数:";
//
// labelActiveThread
//
this.labelActiveThread.Location = new System.Drawing.Point(415, 106);
this.labelActiveThread.Name = "labelActiveThread";
this.labelActiveThread.Size = new System.Drawing.Size(96, 24);
this.labelActiveThread.TabIndex = 53;
this.labelActiveThread.Tag = "活动线程数";
//
// labelTotaldownloadSizes
//
this.labelTotaldownloadSizes.Location = new System.Drawing.Point(415, 146);
this.labelTotaldownloadSizes.Name = "labelTotaldownloadSizes";
this.labelTotaldownloadSizes.Size = new System.Drawing.Size(96, 24);
this.labelTotaldownloadSizes.TabIndex = 53;
this.labelTotaldownloadSizes.Tag = "总线程数";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(343, 150);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(54, 17);
this.label5.TabIndex = 52;
this.label5.Text = "已下载:";
//
// labelNetInfo
//
this.labelNetInfo.Location = new System.Drawing.Point(136, 26);
this.labelNetInfo.Name = "labelNetInfo";
this.labelNetInfo.Size = new System.Drawing.Size(384, 24);
this.labelNetInfo.TabIndex = 54;
this.labelNetInfo.Tag = "网络连接";
//
// labelStartTime
//
this.labelStartTime.Location = new System.Drawing.Point(136, 106);
this.labelStartTime.Name = "labelStartTime";
this.labelStartTime.Size = new System.Drawing.Size(176, 24);
this.labelStartTime.TabIndex = 54;
this.labelStartTime.Tag = "开始时间";
//
// labelEndTime
//
this.labelEndTime.Location = new System.Drawing.Point(136, 146);
this.labelEndTime.Name = "labelEndTime";
this.labelEndTime.Size = new System.Drawing.Size(176, 24);
this.labelEndTime.TabIndex = 54;
this.labelEndTime.Tag = "结束时间";
//
// menuItemCut
//
this.menuItemCut.Index = -1;
this.menuItemCut.Text = "";
//
// menuItemCopy
//
this.menuItemCopy.Index = -1;
this.menuItemCopy.Text = "";
//
// menuItemPaste
//
this.menuItemPaste.Index = -1;
this.menuItemPaste.Text = "";
//
// menuItemDelete
//
this.menuItemDelete.Index = -1;
this.menuItemDelete.Text = "";
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageList1.ImageSize = new System.Drawing.Size(27, 15);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Teal;
//
// timerMem
//
this.timerMem.Interval = 2000;
this.timerMem.Tick += new System.EventHandler(this.timerMem_Tick);
//
// imageListPercentage
//
this.imageListPercentage.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imageListPercentage.ImageSize = new System.Drawing.Size(16, 16);
this.imageListPercentage.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListPercentage.ImageStream")));
this.imageListPercentage.TransparentColor = System.Drawing.Color.Transparent;
//
// timerConnectionInfo
//
this.timerConnectionInfo.Enabled = true;
this.timerConnectionInfo.Interval = 15000;
this.timerConnectionInfo.Tick += new System.EventHandler(this.timerConnectionInfo_Tick);
//
// CountSecondtimer
//
this.CountSecondtimer.Interval = 1000;
this.CountSecondtimer.Tick += new System.EventHandler(this.CountSecondtimer_Tick);
//
// isOvertimer
//
this.isOvertimer.Interval = 30000;
this.isOvertimer.Tick += new System.EventHandler(this.isOvertimer_Tick);
//
// countTimetimer
//
this.countTimetimer.Interval = 1000;
this.countTimetimer.Tick += new System.EventHandler(this.countTimetimer_Tick);
//
// CrawlerForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(792, 337);
this.Controls.Add(this.tabControlRightView);
this.Controls.Add(this.statusBar);
this.Controls.Add(this.toolBarMain);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu;
this.Name = "CrawlerForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "网络蜘蛛";
this.Closing += new System.ComponentModel.CancelEventHandler(this.CrawlerForm_Closing);
this.Load += new System.EventHandler(this.CrawlerForm_Load);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelInfo)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelURLs)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelSubURLs)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelByteCount)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelErrors)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelCPU)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelMem)).EndInit();
this.tabControlRightView.ResumeLayout(false);
this.tabPageThreads.ResumeLayout(false);
this.tabPageErrors.ResumeLayout(false);
this.tabPageRequests.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// 构造函数
///
public CrawlerForm()
{
InitializeComponent();
this.urlStorage = new SortTree();
this.threadsRun = new Thread[100];
this.threadsSubRun = new Thread[100];
this.queueURLS = new Queue();
this.queueSubURLS = new Queue();
this.cpuCounter = new System.Diagnostics.PerformanceCounter();
this.ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
this.cpuCounter.CategoryName = "Processor";
this.cpuCounter.CounterName = "% Processor Time";
this.cpuCounter.InstanceName = "_Total";
this.CountTime = 0;
this.timerMem.Enabled = true;
listViewErrors.Items.Clear();
}
///
/// Clean up any resources being used.
/// 系统退出的清理函数
///
protected override void Dispose( bool disposing )
{
this.StopParsing();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
System.Environment.Exit(0);
}
///
/// The main entry point for the application.
/// 程序的主入口点
///
[STAThread]
static void Main()
{
Application.Run(new CrawlerForm());
}
// 窗口装载时要作的工作
private void CrawlerForm_Load(object sender, System.EventArgs e)
{
//获得初始化的值
Settings.GetValue(this);
//设置初始化的值
InitValues();
//在状态栏中显示提示信息
this.statusBarPanelInfo.Text = " 准备就绪";
}
// 窗口关闭时的工作
private void CrawlerForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// 保存当前的环境设置
Settings.SetValue(this);
// 保存错误信息
SaveErrorInfo();
}
#endregion
}
}