Esempio n. 1
0
        void SwitchProxies(ProxyContainer first, ProxyContainer second)
        {
            ProxyContainer temp = first;

            first  = second;
            second = temp;
        }
Esempio n. 2
0
        public void Release(ProxyContainer proxy, bool success)
        {
            if (success)
            {
                proxy.Rating++;
            }
            else
            {
                lock (proxy)
                {
                    if (proxy.MaxOccupied > 1)
                    {
                        proxy.MaxOccupied--;
                    }
                }
                proxy.Rating--;
            }

            proxy.OccupiedTimes--;
            CorrectPosition(proxy);

            if (!proxy.Busy)
            {
                OnProxyFreed(proxy);
            }
        }
Esempio n. 3
0
 public bool TryGet(out ProxyContainer proxy)
 {
     foreach (var p in _proxies)
     {
         if (!p.Fired && !p.Busy)
         {
             p.OccupiedTimes++;
             proxy = p;
             return(true);
         }
     }
     proxy = null;
     return(false);
 }
Esempio n. 4
0
 public void Fire(ProxyContainer proxy)
 {
     proxy.MaxOccupied = 1;
     if (!(--proxy.Lifes > 0))
     {
         proxy.Fired = true;
         if (_workingCount == 0)//(Interlocked.Decrement(ref _workingCount) <= 0)
         {
             if (OnProxiesResulted != null)
             {
                 OnProxiesResulted(this, EventArgs.Empty);
             }
         }
     }
 }
Esempio n. 5
0
        void FillProxyList(List <RatedProxy> proxies)
        {
            proxies.ForEach((cur_p) =>
            {
                ProxyContainer p_container = new ProxyContainer(cur_p, _maxOccupiedTimes, _prxLifes);

                if (_proxies.Count == 0)
                {
                    _proxies.Add(p_container);
                }
                else
                {
                    bool inserted = false;
                    for (int i = 0; i < _proxies.Count; i++)
                    {
                        ProxyContainer selec_cont = _proxies[i];
                        RatedProxy selected_p     = selec_cont.Proxy;

                        bool speedBetter    = cur_p.AvgSpeed > selected_p.AvgSpeed;
                        bool siteRateBetter = cur_p.SitesRate > selected_p.SitesRate;
                        bool latencyBetter  = (cur_p.AvgLatency != RatedProxy.DefaultVal && cur_p.AvgLatency < selected_p.AvgLatency);
                        bool cur_p_better   = speedBetter || siteRateBetter || latencyBetter;

                        if (cur_p_better)                                                   /* better proxies will be on the top of list */
                        {
                            p_container.Rating = ++selec_cont.Rating;
                            _proxies.Insert(i, p_container);
                            inserted = true;
                            break;
                        }
                    }

                    if (!inserted)
                    {
                        p_container.Rating = _proxies.Last().Rating;
                        _proxies.Add(p_container);
                    }
                }
            });

            if (_useLocalhost)
            {
                ProxyContainer localhost = new ProxyContainer(null, _localhost_occupation, _localhost_lives);
                _proxies.Insert(0, localhost);

                localhost.Rating = 999;
            }
        }
Esempio n. 6
0
        void CorrectPosition(ProxyContainer proxy)
        {
            int indx = _proxies.IndexOf(proxy);
            int prev = indx - 1;
            int next = indx + 1;

            if (prev > 0) /* if proxy not rank 1 */
            {
                ProxyContainer prx_prev = _proxies[prev];
                if (prx_prev.Rating < proxy.Rating)
                {
                    SwitchProxies(prx_prev, proxy);
                }
            }
            else if (next < _proxies.Count)
            {
                ProxyContainer prx_next = _proxies[next];
                if (prx_next.Rating > proxy.Rating)
                {
                    SwitchProxies(prx_next, proxy);
                }
            }
        }
Esempio n. 7
0
 void SwitchProxies(ProxyContainer first, ProxyContainer second)
 {
     ProxyContainer temp = first;
     first = second;
     second = temp;
 }
Esempio n. 8
0
        void FillProxyList(List<RatedProxy> proxies)
        {
            proxies.ForEach((cur_p) =>
            {
                ProxyContainer p_container = new ProxyContainer(cur_p, _maxOccupiedTimes, _prxLifes);

                if (_proxies.Count == 0)
                {
                    _proxies.Add(p_container);
                }
                else
                {
                    bool inserted = false;
                    for (int i = 0; i < _proxies.Count; i++)
                    {
                        ProxyContainer selec_cont = _proxies[i];
                        RatedProxy selected_p = selec_cont.Proxy;

                        bool speedBetter = cur_p.AvgSpeed > selected_p.AvgSpeed;
                        bool siteRateBetter = cur_p.SitesRate > selected_p.SitesRate;
                        bool latencyBetter = (cur_p.AvgLatency != RatedProxy.DefaultVal && cur_p.AvgLatency < selected_p.AvgLatency);
                        bool cur_p_better = speedBetter || siteRateBetter || latencyBetter;

                        if (cur_p_better)                                                   /* better proxies will be on the top of list */
                        {
                            p_container.Rating = ++selec_cont.Rating;
                            _proxies.Insert(i, p_container);
                            inserted = true;
                            break;
                        }
                    }

                    if (!inserted)
                    {
                        p_container.Rating = _proxies.Last().Rating;
                        _proxies.Add(p_container);
                    }
                }
            });

            if (_useLocalhost)
            {
                ProxyContainer localhost = new ProxyContainer(null, _localhost_occupation, _localhost_lives);
                _proxies.Insert(0, localhost);

                localhost.Rating = 999;
            }
        }
Esempio n. 9
0
        void CorrectPosition(ProxyContainer proxy)
        {
            int indx = _proxies.IndexOf(proxy);
            int prev = indx - 1;
            int next = indx + 1;

            if (prev > 0) /* if proxy not rank 1 */
            {
                ProxyContainer prx_prev = _proxies[prev];
                if (prx_prev.Rating < proxy.Rating)
                    SwitchProxies(prx_prev, proxy);
            }
            else if (next < _proxies.Count)
            {
                ProxyContainer prx_next = _proxies[next];
                if (prx_next.Rating > proxy.Rating)
                    SwitchProxies(prx_next, proxy);
            }
        }
Esempio n. 10
0
 public bool TryGet(out ProxyContainer proxy)
 {
     foreach (var p in _proxies)
     {
         if (!p.Fired && !p.Busy)
         {
             p.OccupiedTimes++;
             proxy = p;
             return true;
         }
     }
     proxy = null;
     return false;
 }
Esempio n. 11
0
        public void Release(ProxyContainer proxy, bool success)
        {
            if (success)
            {
                proxy.Rating++;
            }
            else
            {
                lock (proxy)
                {
                    if (proxy.MaxOccupied > 1)
                        proxy.MaxOccupied--;
                }
                proxy.Rating--;
            }

            proxy.OccupiedTimes--;
            CorrectPosition(proxy);

            if (!proxy.Busy)
            {
                OnProxyFreed(proxy);
            }
        }
Esempio n. 12
0
 public void Fire(ProxyContainer proxy)
 {
     proxy.MaxOccupied = 1;
     if (!(--proxy.Lifes > 0))
     {
         proxy.Fired = true;
         if (_workingCount == 0)//(Interlocked.Decrement(ref _workingCount) <= 0)
         {
             if (OnProxiesResulted != null)
                 OnProxiesResulted(this, EventArgs.Empty);
         }
     }
 }