示例#1
0
        public bool UpdateProxy()
        {
            if (!Configuration.Proxy.Enabled)
            {
                return(false);
            }

            Logger.Trace("Updating proxy...");

            lock (_CurrentProxySync)
            {
                Logger.Trace($"{_CurrentProxy} was locked...");

                var proxies = ((DgvProxyList.DataSource as IEnumerable <Models.ProxyItem>) ?? new Models.ProxyItem[0]).ToList();
                if (_CurrentProxy != null)
                {
                    Logger.Trace($"Trying to find index of {_CurrentProxy} ({_CurrentProxy.Host}:{_CurrentProxy.Port})...");
                    var currentIndex = proxies.FindIndex(_base =>
                    {
                        if (_base == null)
                        {
                            return(false);
                        }

                        if (_base.ProxyType != _CurrentProxy.ProxyType &&
                            _base.Host != _CurrentProxy.Host &&
                            _base.Port != _CurrentProxy.Port)
                        {
                            return(false);
                        }

                        return(true);
                    });
                    Logger.Trace($"Index of {_CurrentProxy} is {currentIndex}");
                    if (currentIndex > -1)
                    {
                        Logger.Trace($"Disabling {_CurrentProxy} and mark it as broken.");
                        proxies[currentIndex].Enabled = false;
                        proxies[currentIndex].Status  = Enums.ProxyStatus.Broken;

                        Invoke(new Action(() => { DgvProxyList.DataSource = proxies; }));
                    }
                }

                Logger.Trace("Looking for proxy...");
                var working = proxies.Where(p => p.Enabled && p.Status != Enums.ProxyStatus.Broken);
                _CurrentProxy = working?.FirstOrDefault();
                if (_CurrentProxy == null)
                {
                    Logger.Trace("No proxies...");
                }
                else
                {
                    Logger.Trace($"Proxy is found. {_CurrentProxy.Host}:{_CurrentProxy.Port}");
                }
            }
            Logger.Trace($"{_CurrentProxy} was unlocked...");

            return(_CurrentProxy != null);
        }
示例#2
0
        public ReCaptchaDialog(Models.Configuration configuration, Models.ProxyItem proxy)
        {
            Configuration = configuration;
            Solution      = new CaptchaSolution(false, Solution.Message, configuration.Captcha);
            InitializeComponent();

            if ((proxy?.Enabled ?? false))
            {
                GeckoPreferences.Default["network.proxy.type"] = 1;

                // clear proxies
                GeckoSetProxy(Enums.ProxyType.Http, "", 0);
                GeckoSetProxy(Enums.ProxyType.Socks4, "", 0);

                GeckoSetProxy(proxy.ProxyType, proxy.Host, proxy.Port);
            }
            else
            {
                GeckoPreferences.Default["network.proxy.type"] = 0;
            }
        }
        public bool GetNew()
        {
            Logger.Trace("New proxy required...");
            if (!Enabled)
            {
                Current = null;
                return(true);
            }

            var success = false;

            lock (Sync)
            {
                Logger.Debug("Proxies locked...");
                if (_Current == null)
                {
                    var enabledProxies = Proxies.Where(x => x?.Enabled ?? false);
                    if (enabledProxies.Count() > 0)
                    {
                        _Current = enabledProxies.First();
                        Logger.Trace($"New proxy is ({_Current.ProxyType.ToString()}) {_Current.Host}:{_Current.Port}");
                        success = true;
                    }
                    else
                    {
                        Logger.Warn("No working proxies using old!");
                    }
                }
                else
                {
                    var enabledProxies = new List <Models.ProxyItem>();
                    var oldProxyIndex  = -1;
                    for (int i = 0; i < Proxies.Count(); i++)
                    {
                        var proxy = Proxies.ElementAtOrDefault(i);
                        if (proxy == null)
                        {
                            continue;
                        }

                        if (proxy == _Current)
                        {
                            oldProxyIndex = i;
                        }
                    }

                    if (oldProxyIndex > -1)
                    {
                        var _proxies = Proxies.ToList();
                        _proxies[oldProxyIndex].Enabled   = false;
                        MainForm.Configuration.Proxy.List = _proxies;
                        Logger.Info($"Proxy ({_Current.ProxyType.ToString()}) {_Current.Host}:{_Current.Port} was disabled in list.");
                    }

                    if (enabledProxies.Count() > 0)
                    {
                        _Current = enabledProxies.First();
                        Logger.Trace($"New proxy is ({_Current.ProxyType.ToString()}) {_Current.Host}:{_Current.Port}");
                        success = true;
                    }
                    else
                    {
                        Logger.Warn("No working proxies using old!");
                    }
                }
                Logger.Debug($"Unlocking proxies...");
            }
            return(success);
        }
 public MailHandler(Models.ProxyItem proxy, bool isCustomDomain)
 {
     Proxy          = proxy;
     IsCustomDomain = isCustomDomain;
 }