Exemplo n.º 1
0
 public void EnqueuePendingProxy(ProxyInfo proxyInfo)
 {
     lock (pendingProxies)
     {
         pendingProxies.Enqueue(proxyInfo);
     }
 }
Exemplo n.º 2
0
 public void EnqueueGoodProxy(ProxyInfo proxyInfo)
 {
     lock (goodProxiesQueue)
     {
         goodProxiesQueue.Enqueue(proxyInfo.RTT, proxyInfo);
     }
 }
Exemplo n.º 3
0
 public void DeleteProxy(ProxyInfo proxyInfo)
 {
     if (OnProxyRemoved != null)
     {
         OnProxyRemoved(this, new ProxyRemovedEventHandlerArgs
         {
             ProxyInfo = proxyInfo
         });
     }
 }
Exemplo n.º 4
0
        private ProxyInfo DequeuePendingProxy()
        {
            ProxyInfo pi = null;

            lock (pendingProxies)
            {
                if (pendingProxies.Count > 0)
                {
                    pi = pendingProxies.Dequeue();
                }
            }
            return(pi);
        }
Exemplo n.º 5
0
 public void DeleteProxy(ProxyInfo proxyInfo)
 {
     lock (proxies)
     {
         proxies.Remove(proxyInfo.ProxyAddress);
     }
     if (OnProxyRemoved != null)
     {
         OnProxyRemoved(this, new ProxyRemovedEventHandlerArgs
         {
             ProxyInfo = proxyInfo
         });
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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
                });
            }
        }
Exemplo n.º 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);
        }