Пример #1
0
 public void EnqueuePendingProxy(ProxyInfo proxyInfo)
 {
     lock (pendingProxies)
     {
         pendingProxies.Enqueue(proxyInfo);
     }
 }
Пример #2
0
 public void EnqueueGoodProxy(ProxyInfo proxyInfo)
 {
     lock (goodProxiesQueue)
     {
         goodProxiesQueue.Enqueue(proxyInfo.RTT, proxyInfo);
     }
 }
Пример #3
0
 public void DeleteProxy(ProxyInfo proxyInfo)
 {
     if (OnProxyRemoved != null)
     {
         OnProxyRemoved(this, new ProxyRemovedEventHandlerArgs
         {
             ProxyInfo = proxyInfo
         });
     }
 }
Пример #4
0
        private ProxyInfo DequeuePendingProxy()
        {
            ProxyInfo pi = null;

            lock (pendingProxies)
            {
                if (pendingProxies.Count > 0)
                {
                    pi = pendingProxies.Dequeue();
                }
            }
            return(pi);
        }
Пример #5
0
 public void DeleteProxy(ProxyInfo proxyInfo)
 {
     lock (proxies)
     {
         proxies.Remove(proxyInfo.ProxyAddress);
     }
     if (OnProxyRemoved != null)
     {
         OnProxyRemoved(this, new ProxyRemovedEventHandlerArgs
         {
             ProxyInfo = proxyInfo
         });
     }
 }
Пример #6
0
        public ProxyInfo DequeueFastestProxy(bool autoRedownload)
        {
            ProxyInfo pi = null;

            lock (goodProxiesQueue)
            {
                if (goodProxiesQueue.Count != 0)
                {
                    pi = goodProxiesQueue.Dequeue();
                }
                if (autoRedownload && goodProxiesQueue.Count <= 5)
                {
                    StartDownloadProxies(true);
                }
            }
            return(pi);
        }
Пример #7
0
        public void EnqueueGoodProxy(ProxyInfo proxyInfo)
        {
            bool notice = false;

            lock (proxies)
            {
                if (!proxies.Contains(proxyInfo.ProxyAddress))
                {
                    goodProxiesQueue.Produce(proxyInfo.RTT, proxyInfo);
                    proxies.Add(proxyInfo.ProxyAddress);
                    notice = true;
                }
            }
            if (notice && OnUsableProxyFound != null)
            {
                OnUsableProxyFound(this, new UsableProxyFoundEventArgs
                {
                    ProxyInfo = proxyInfo
                });
            }
        }
Пример #8
0
        public bool ValidateProxy(ProxyInfo pi)
        {
            int  round     = ValidateConditions.Count;
            long totalTime = 0;

            foreach (ProxyValidateCondition c in ValidateConditions)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(c.Url);
                request.Proxy   = pi.HttpProxy;
                request.Timeout = 20000;
                long            start = System.Environment.TickCount;
                HttpWebResponse resp  = null;
                try
                {
                    resp = (HttpWebResponse)request.GetResponse();
                    long end = System.Environment.TickCount;
                    totalTime += end - start;
                }
                catch (WebException)
                {
//					lock (locker)
//					File.AppendAllText("debug.txt", pi.ProxyAddress + " " + e.Message + "\n");
                    pi.RTT = -1;
                    return(false);
                }
                if (resp.StatusCode != HttpStatusCode.OK)
                {
//					lock (locker)
//					File.AppendAllText("debug.txt", pi.ProxyAddress + " NOT OK\n");
                    pi.RTT = -1;
                    return(false);
                }

                string html;
                bool   success = HtmlHelper.GetHtml(resp, out html);
                resp.Close();
                if (!success)
                {
                    pi.RTT = -1;
//					lock (locker)
//					File.AppendAllText("debug.txt", pi.ProxyAddress + " HTML\n");
                    return(false);
                }
//				lock (locker)
//				File.AppendAllText("debug.txt", pi.ProxyAddress + html + "\n");
                foreach (string s in c.Keywords)
                {
                    if (!html.Contains(s))
                    {
//						lock (locker)
//						File.AppendAllText("debug.txt", pi.ProxyAddress + "NOT CONTAIN " + s+ "\n");
                        pi.RTT = -1;
                        return(false);
                    }
                }
                foreach (string s in c.ForbiddenKeywords)
                {
                    if (html.Contains(s))
                    {
//						lock (locker)
//						File.AppendAllText("debug.txt", pi.ProxyAddress + "CONTAIN " + s + "\n");
                        pi.RTT = -1;
                        return(false);
                    }
                }
            }
            pi.RTT = (int)totalTime / round;
            return(true);
        }