예제 #1
0
        public void SetStatus(string ip, bool connected)
        {
            ProxyRepository <ProxyServer> xmlWriter       = new ProxyRepository <ProxyServer>();
            List <ProxyServer>            proxyCollection = xmlWriter.GetAll();
            ProxyServer proxy = proxyCollection.Where(x => x.Ip == ip).FirstOrDefault();

            try
            {
                if (connected)
                {
                    if (proxy.Priority != 0)
                    {
                        proxy.Priority = 0;
                        proxy.Status   = "Stable";
                    }
                    else
                    {
                        if (proxy.Status == "New")
                        {
                            proxy.Status = "Stable";
                        }
                    }
                }
                else
                {
                    switch (proxy.Priority)
                    {
                    case 0:
                    {
                        proxy.Priority++;
                        proxy.Status = "Unstable";
                        break;
                    }

                    case 1:
                    {
                        proxy.Priority++;
                        proxy.Status = "Bad";
                        break;
                    }

                    case 2:
                    {
                        proxy.Priority++;
                        proxy.Status = "Eliminated";
                        break;
                    }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            proxy.LastUsed = DateTime.Now;
            xmlWriter.Modify(proxy);
        }
예제 #2
0
 public void UpdateElimination()
 {
     lock (connectionLocker)
     {
         try
         {
             ProxyRepository <ProxyServer> xmlWriter            = new ProxyRepository <ProxyServer>();
             List <ProxyServer>            eliminatedCollection = xmlWriter.GetAll().Where(x => x.Status == ProxyStatus.PS_Eliminated).ToList();
             foreach (ProxyServer proxy in eliminatedCollection)
             {
                 proxy.Status = ProxyStatus.PS_Bad;
                 proxy.Priority--;
             }
             xmlWriter.Modify(eliminatedCollection);
         }
         catch (Exception ex)
         {
             Log.Error(ex);
         }
     }
 }