Ejemplo n.º 1
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            var type    = ProxyTypeComboBox.SelectedIndex;
            var proxy   = ProxyServerTextBox.Text;
            var port    = 0;
            var timeout = 3;

            if (UseProxyCheckBox.Checked)
            {
                try
                {
                    port = int.Parse(ProxyPortTextBox.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(I18N.GetString("Illegal port number format"));
                    ProxyPortTextBox.Clear();
                    return;
                }

                try
                {
                    timeout = int.Parse(ProxyTimeoutTextBox.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(I18N.GetString("Illegal timeout format"));
                    ProxyTimeoutTextBox.Clear();
                    return;
                }

                try
                {
                    Configuration.CheckServer(proxy);
                    Configuration.CheckPort(port);
                    Configuration.CheckTimeout(timeout, ProxyConfig.MaxProxyTimeoutSec);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }

                controller.EnableProxy(type, proxy, port);
            }
            else
            {
                controller.DisableProxy();
            }

            _modifiedConfiguration.useProxy     = UseProxyCheckBox.Checked;
            _modifiedConfiguration.proxyType    = type;
            _modifiedConfiguration.proxyServer  = proxy;
            _modifiedConfiguration.proxyPort    = port;
            _modifiedConfiguration.proxyTimeout = timeout;
            controller.SaveProxyConfig(_modifiedConfiguration);

            this.Close();
        }
Ejemplo n.º 2
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            if (UseProxyCheckBox.Checked)
            {
                try
                {
                    var type  = ProxyTypeComboBox.SelectedIndex;
                    var proxy = ProxyServerTextBox.Text;
                    var port  = int.Parse(ProxyPortTextBox.Text);
                    Configuration.CheckServer(proxy);
                    Configuration.CheckPort(port);

                    controller.EnableProxy(type, proxy, port);
                }
                catch (FormatException)
                {
                    MessageBox.Show(I18N.GetString("Illegal port number format"));
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            else
            {
                controller.DisableProxy();
            }

            _modifiedConfiguration.useProxy    = UseProxyCheckBox.Checked;
            _modifiedConfiguration.proxyType   = ProxyTypeComboBox.SelectedIndex;
            _modifiedConfiguration.proxyServer = ProxyServerTextBox.Text;
            var tmpProxyPort = 0;

            int.TryParse(ProxyPortTextBox.Text, out tmpProxyPort);
            _modifiedConfiguration.proxyPort = tmpProxyPort;
            controller.SaveProxyConfig(_modifiedConfiguration);

            this.Close();
        }