/// <summary> /// 更新云服务器信息 /// </summary> private void UpdateCloudProxyList() { TimeSpan ts = DateTime.Now - Config.LateUpdateProxyListTime; if (_isUpdated && ts.TotalSeconds > 30) { _isUpdated = false; var cloudHelper = new CloudHelper(); var list = (from p in ProxyData.ProxyList where p.status == 0 select p).ToList(); var updateList = new List <ProxyServer>(); foreach (var item in from item in list let cloudModel = CloudProxyData.Get(item.proxy, item.port) where null != cloudModel where updateList.FirstOrDefault(p => p.proxy == item.proxy && p.port == item.port) == null select item) { updateList.Add(item); //云端存在且无法连接的数据 } updateList = (from p in ProxyData.ProxyList where p.status == 1 select p).Union(updateList).Distinct().ToList(); cloudHelper.UploadProxyList(updateList); Config.MainForm.ConnectCloud(); _isUpdated = true; } }
/// <summary> /// 获取代理列表 /// </summary> /// <param name="url"></param> /// <returns></returns> public static void Downloading(DownloadThread downloader) { try { var httpHelper = new HttpHelper(); httpHelper.IsUseDefaultProxy = false; if (Config.LocalSetting.HttpOption != null) { httpHelper.HttpOption = Config.LocalSetting.HttpOption; } else { httpHelper.HttpOption.Timeout = 60 * 1000; } string result = ""; if (Config.LocalSetting.IsUseSystemProxy) { result = httpHelper.GetHtml(downloader.Url); } else { result = httpHelper.GetHtml(downloader.Url); } string line = result; var regex = new Regex(Config.RegexProxy); MatchCollection matches = regex.Matches(line); downloader.Description = "The downloading thread " + downloader.thread.ManagedThreadId + " is downloading.Proxies count:" + matches.Count; Config.ConsoleEx.Debug(downloader.Description); for (int i = 0; i < matches.Count; i++) { var model = new ProxyServer(); model.proxy = matches[i].Groups["Proxy"].Value; model.port = int.Parse(matches[i].Groups["Port"].Value); ProxyServer cloudProxy = CloudProxyData.Get(model.proxy, model.port); if (null != cloudProxy) { ProxyDataAddRow(cloudProxy); } else { ProxyDataAddRow(model); } } downloader.Description = "The downloading thread " + downloader.thread.ManagedThreadId + " download completed."; Config.ConsoleEx.Debug(downloader.Description); } catch (WebException webEx) { Config.ConsoleEx.Debug(webEx); } catch (Exception ex) { Config.ConsoleEx.Debug(ex); } finally { } }