예제 #1
0
 /// <summary>
 /// 从source中获取更新的代理服务器配置
 /// runningcathe静态类中调用该方法,用于推送source中的代理更新
 /// </summary>
 /// <param name="pSrc">代理源</param>
 /// <param name="pServerList">更新的代理服务器清单(可选参数)</param>
 public void refreshProxyServerFromSource(ProxySource pSrc)
 {
     if (poolStatus != 0)
     {
         //缓存满后等待三轮,清空allProxyServerList中的失效代理
         if (noUpdateRound > 3)
         {
             allProxyServerList = activeProxyServerList.Take(activeProxyServerList.Count).ToList();
         }
         List <ProxyServer> ps = pSrc.ProxyServerList.Except(allProxyServerList, new ProxyServerCompare()).ToList();
         if (ps.Count > 0)
         {
             noUpdateRound = 0;
             //从各个source中平均获取新代理
             int toBeAdded = (catheSize - allProxyServerList.Count) / poolSource.Count;
             if (toBeAdded > 0)
             {
                 toBeAdded = toBeAdded > ps.Count ? ps.Count : toBeAdded;
                 ps        = ps.Take(toBeAdded).ToList();
                 lock (refreshSourceLock)
                 {
                     toBeValidProxyServerList.AddRange(ps);
                     allProxyServerList.AddRange(ps);
                 }
             }
             else
             {
                 noUpdateRound = noUpdateRound + 1;
             }
         }
     }
 }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pSrc"></param>
 /// <param name="pServerList"></param>
 public static void refreshPoolProxyFromSource(ProxySource pSrc, List <ProxyServer> pServerList = null)
 {
     foreach (Pool p in AllProxyPool)
     {
         lock (poolProxyListUpdateLock)
         {
             p.refreshProxyServerFromSource(pSrc);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// 针对某一代理源的缓存垃圾回收
 /// 当某一代理源中缓存代理服务器数量超过,该代理源缓存容量时,触发该代理源的缓存垃圾回收事件
 ///
 /// 缓存垃圾是指在所有将其纳入的代理池中均被验证为无效代理的ProxyServer
 /// 即仅存在于allProxyServerList中的ProxyServer(不存在于activeProxyServerList,toBeValidProxyServerList,inactiveProxyServerList中)
 /// </summary>
 public static void catheTrashCollectBySource(ProxySource pSrc)
 {
     foreach (Pool p in AllProxyPool)
     {
         if (p.PoolSource.Contains(pSrc))
         {
             List <ProxyServer> toBeCollected = p.AllProxyServerList.Except(p.ActiveProxyServerList).Except(p.ToBeValidProxyServerList).ToList();
             lock (poolProxyListUpdateLock)
             {
                 pSrc.ProxyServerList = pSrc.ProxyServerList.Except(toBeCollected).ToList();
                 p.AllProxyServerList = p.AllProxyServerList.Except(toBeCollected).ToList();
             }
             toBeCollected = null;
         }
     }
 }
예제 #4
0
 public static void stopRefreshSource(ProxySource pSrc)
 {
     pSrc.stopRefreshThread();
 }
예제 #5
0
        public static void stopRefreshSource(int sourceID)
        {
            ProxySource pSrc = AllProxySource.Find(x => x.Id == sourceID);

            pSrc.stopRefreshThread();
        }