示例#1
0
 void _httper_RequestStringCompleted(object sender, RequestStringCompletedEventArgs e)
 {
     this._CompletedCount++;
     if (e.Error == null)
     {
         System.Text.RegularExpressions.MatchCollection mc = RegexUtility.GetMatchFull(e.ResponseString, ((ProxySourcePageInfo)e.UserState).RegexString);
         if (mc != null)
         {
             foreach (System.Text.RegularExpressions.Match m in mc)
             {
                 ProxyInfo info = new ProxyInfo();
                 info.Name = "";
                 info.Address = m.Groups[1].Value.Split(':')[0];
                 info.Port = Convert.ToInt32(m.Groups[1].Value.Split(':')[1]);
                 SendStatusChanged(string.Format("取得:{0}:{1}", info.Address, info.Port), "");
                 this._ProxyList.Add(info);
             }
         }
     }
     else
     {
     #warning todo error
     }
     if (this._CompletedCount == this._SourcePageInfo.Count)
     {
         if (this.Completed != null)
         {
             this.Completed(this, new Natsuhime.Events.ReturnCompletedEventArgs(this._ProxyList, null, false, "77777"));
         }
     }
 }
示例#2
0
        void _httper_RequestStringCompleted(object sender, RequestStringCompletedEventArgs e)
        {
            this._CompletedCount++;
            if (e.Error == null)
            {
                System.Text.RegularExpressions.MatchCollection mc = RegexUtility.GetMatchFull(e.ResponseString, ((ProxySourcePageInfo)e.UserState).RegexString);
                if (mc != null)
                {
                    foreach (System.Text.RegularExpressions.Match m in mc)
                    {
                        ProxyInfo info = new ProxyInfo();
                        info.Name    = "";
                        info.Address = m.Groups[1].Value.Split(':')[0];
                        info.Port    = Convert.ToInt32(m.Groups[1].Value.Split(':')[1]);
                        SendStatusChanged(string.Format("取得:{0}:{1}", info.Address, info.Port), "");
                        this._ProxyList.Add(info);
                    }
                }
            }
            else
            {
#warning todo error
            }
            if (this._CompletedCount == this._SourcePageInfo.Count)
            {
                if (this.Completed != null)
                {
                    this.Completed(this, new Natsuhime.Events.ReturnCompletedEventArgs(this._ProxyList, null, false, "77777"));
                }
            }
        }
示例#3
0
        private void Validate(string currentIP, AsyncOperation asyncOp)
        {
            if (currentIP == null || currentIP.Trim() == string.Empty)
            {
                throw new ArgumentNullException("currentIP");
            }

            Natsuhime.Events.MessageEventArgs e = null;
            while (true)
            {
                ProxyInfo info = GetProxy();
                if (info == null)
                {
                    break;
                }
                e = new Natsuhime.Events.MessageEventArgs("", string.Format("[校验]{0}:{1}", info.Address, info.Port), "", asyncOp.UserSuppliedState);
                asyncOp.Post(this.onStatusChangeDelegate, e);

                string returnData;
                try
                {
                    returnData = ConnectValidatePage(asyncOp, info);
                }
                catch (Exception ex)
                {
                    returnData = string.Empty;
                }
                if (returnData == string.Empty)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("{0}:{1} - Failed", info.Address, info.Port));

                    e = new Natsuhime.Events.MessageEventArgs("", string.Format("[失败]{0}:{1}", info.Address, info.Port), "", asyncOp.UserSuppliedState);
                    asyncOp.Post(this.onStatusChangeDelegate, e);
                    continue;
                }
                if (currentIP == ProxyUtility.GetCurrentIP_RegexPage(returnData, _ProxyValidateUrlInfo.RegexString))
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("{0}:{1} - Bad", info.Address, info.Port));

                    e = new Natsuhime.Events.MessageEventArgs("", string.Format("[透明]{0}:{1}", info.Address, info.Port), "", asyncOp.UserSuppliedState);
                    asyncOp.Post(this.onStatusChangeDelegate, e);
                    continue;
                }

                Monitor.Enter(_ProxyListOK);
                _ProxyListOK.Add(info);
                Monitor.Exit(_ProxyListOK);
                System.Diagnostics.Debug.WriteLine(string.Format("{0}:{1} - OK", info.Address, info.Port));

                e = new Natsuhime.Events.MessageEventArgs("", string.Format("[成功]{0}:{1}", info.Address, info.Port), "", asyncOp.UserSuppliedState);
                asyncOp.Post(this.onStatusChangeDelegate, e);
            }
        }
示例#4
0
        private string ConnectValidatePage(AsyncOperation asyncOp, ProxyInfo info)
        {
            Natsuhime.Events.MessageEventArgs e = null;
            if (info != null)
            {
                try
                {
                    httper.Proxy = new System.Net.WebProxy(info.Address, info.Port);
                    System.Diagnostics.Debug.WriteLine(string.Format("{0}:{1}", info.Address, info.Port));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write("error uri" + info.Address + "-" + info.Port);
                    e = new Natsuhime.Events.MessageEventArgs("", string.Format("[代理错误:{2}]{0}:{1}", info.Address, info.Port, ex.Message), "", asyncOp.UserSuppliedState);
                    asyncOp.Post(this.onStatusChangeDelegate, e);
                }
            }

            httper.Url     = _ProxyValidateUrlInfo.Url;
            httper.Charset = _ProxyValidateUrlInfo.Charset;
            return(httper.HttpGet());
        }
示例#5
0
        private string ConnectValidatePage(AsyncOperation asyncOp, ProxyInfo info)
        {
            Natsuhime.Events.MessageEventArgs e = null;
            if (info != null)
            {
                try
                {
                    httper.Proxy = new System.Net.WebProxy(info.Address, info.Port);
                    System.Diagnostics.Debug.WriteLine(string.Format("{0}:{1}", info.Address, info.Port));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write("error uri" + info.Address + "-" + info.Port);
                    e = new Natsuhime.Events.MessageEventArgs("", string.Format("[代理错误:{2}]{0}:{1}", info.Address, info.Port, ex.Message), "", asyncOp.UserSuppliedState);
                    asyncOp.Post(this.onStatusChangeDelegate, e);
                }
            }

            httper.Url = _ProxyValidateUrlInfo.Url;
            httper.Charset = _ProxyValidateUrlInfo.Charset;
            return httper.HttpGet();
        }