示例#1
0
        public void SelectNextProxy()
        {
            if (_preventDeadLock == WebProxies.Count + 1)
            {
                Logger.Info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                Logger.Info("Закончились прокси сервера на сегодня. Каждый уже зарегил максимум человек.");
                Logger.Info("Переключаюсь на основной адрес.");
                Logger.Info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                CurrentWebProxy  = null;
                UseProxy         = false;
                _preventDeadLock = 0;
                return;
            }

            WebProxies.Enqueue(WebProxies.Dequeue());
            WebProxy webProxy = WebProxies.Peek();
            RegCount rc       = ProxyRegCounts[webProxy];

            if (rc == null || rc.CountRegistrations < AllowReg)
            {
                CurrentWebProxy = webProxy;
                Logger.Info("SetProxy " + CurrentWebProxy.Address.Host + " " + CurrentWebProxy.Address.Port);
                SaveCurrentProxyList();
                _preventDeadLock = 0;
            }
            else
            {
                _preventDeadLock++;
                SelectNextProxy();
            }
        }
示例#2
0
 private void ParseRegCounts(string str)
 {
     RegCounts = new List <RegCount>();
     if (str != null)
     {
         var list = str.Split(';');
         foreach (string s in list)
         {
             var prox = s.Split('|');
             if (prox.Length == 3)
             {
                 var rc = new RegCount()
                 {
                     CountRegistrations = int.Parse(prox[0]),
                     RegDate            = DateTime.ParseExact(prox[1], Const.DateFormat, CultureInfo.InvariantCulture),
                     Address            = prox[2]
                 };
                 if (rc.RegDate.ToString(Const.DateFormat, CultureInfo.InvariantCulture) == DateTime.Now.ToString(Const.DateFormat, CultureInfo.InvariantCulture))
                 {
                     RegCounts.Add(rc);
                 }
             }
         }
     }
 }
示例#3
0
        private void ParseProxies(string str)
        {
            ProxyUsers = new Dictionary <WebProxy, NetworkCredential>();
            WebProxies = new Queue <WebProxy>();
            var list = str.Split(';');

            foreach (string s in list)
            {
                var prox = s.Split(':');
                if (prox.Length == 4)
                {
                    try
                    {
                        WebProxy proxy = new WebProxy(prox[0], int.Parse(prox[1]));
                        //Set credentials
                        var credentials = new NetworkCredential(prox[2], prox[3]);
                        proxy.Credentials = credentials;
                        ProxyUsers.Add(proxy, credentials);
                        //Set proxy
                        //WebProxy proxy = new WebProxy(proxyURI, true, null, credentials );
                        // WebProxy proxy = new WebProxy(prox[0], int.Parse(prox[1]));
                        WebProxies.Enqueue(proxy);
                        RegCount rcTofind = null;
                        foreach (var rc in RegCounts)
                        {
                            if (rc.Address == proxy.Address.ToString())
                            {
                                rcTofind = rc;
                                break;
                            }
                        }
                        _proxyRegCounts.Add(proxy, rcTofind);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                    }
                }
            }
            if (WebProxies.Count > 0)
            {
                CurrentWebProxy = WebProxies.Peek();
            }
        }