public ProxyHttper(ProxyItem proxyItem) : base(null) { if (null == proxyItem || string.IsNullOrEmpty(proxyItem.IP) || proxyItem.Port <= 0) { throw new ArgumentNullException("proxyItem"); } Proxy = proxyItem; }
protected override void SetProxy(HttpWebRequest httpRequest) { if (null != httpRequest) { ProxyItem proxy = this.DetectionParamsItem.GetAvaiableProxy(); if (proxy != null) { httpRequest.Proxy = new WebProxy(proxy.IP, proxy.Port); } else { httpRequest.Proxy = WebProxy.GetDefaultProxy(); } } }
public void Start() { SoundPlayer.PlayAlter(); proxyEnumerator = ProxyList.GetEnumerator(); isRunnig = true; LogManager.InfoWithCallback(string.Format("开始对:{0} 文件进行代理测速 ", ProxyFile, this.Server.Header)); for (int i = 0; i < threadCount; i++) { ThreadPool.QueueUserWorkItem(delegate { while (true) { ProxyItem proxy = GetCurrentProxy(); if (null == proxy || this.isDisposing || !isRunnig) { if (Interlocked.Increment(ref finishCount) == threadCount) { SaveChunk(true); //SaveSpeedProxy(); } return; } using (ProxyHttper httper = new ProxyHttper(proxy)) { httper.GetHttpTime(this.Server.LoginPostActionUrl); } lock (resultObj) { sortedProxyList.Add(proxy.AccessTime, proxy); if (proxy.AccessTime > 0 & !proxy.IsNeedCaptcha) { sortedSucceedProxyList.Add(proxy.AccessTime, proxy); } if (sortedProxyList.Count >= chunkCount) { SaveChunk(false); } } LogManager.InfoWithCallback(string.Format("{0}、 代理:{1} 访问时间:{2:f2} 秒,{3} {4} ", proxy.ID, proxy.IP, proxy.AccessTime, proxy.IsNeedCaptcha ? " ,需要验证码" : "", proxy.AccessTime < 0 ? " ,代理无法访问" : "")); } }); } }