iControl.Dialogs.ConnectionDialog.OKLinkLabel_LinkClicked C# (CSharp) Method

OKLinkLabel_LinkClicked() private method

private OKLinkLabel_LinkClicked ( object sender, System e ) : void
sender object
e System
return void
        private void OKLinkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            if (0 == HostnameComboBox.Text.Length)
            {
                MessageBox.Show("Please enter a hostname.", "Missing information");
                HostnameComboBox.Focus();
            }
            else if (0 == PortTextBox.Text.Length)
            {
                MessageBox.Show("Please enter a port.", "Missing information");
                PortTextBox.Text = "443";
                PortTextBox.Focus();
            }
            else if (0 == EndpointTextBox.Text.Length)
            {
                MessageBox.Show("Please enter a endpoint (default of /iControl/iControlPortal.cgi).", "Missing information");
                EndpointTextBox.Text = "/iControl/iControlPortal.cgi";
                EndpointTextBox.Focus();
            }
            else if (0 == UsernameTextBox.Text.Length)
            {
                MessageBox.Show("Please enter a username.", "Missing information");
                UsernameTextBox.Focus();
            }
            else if (0 == PasswordTextBox.Text.Length)
            {
                MessageBox.Show("Please enter a password.", "Missing information");
                PasswordTextBox.Focus();
            }
            else if (UseProxyCheckBox.Checked && (ProxyAddressTextBox.Text.Length == 0))
            {
                MessageBox.Show("If you are using a proxy server, please specify the address");
                ProxyAddressTextBox.Focus();
            }
            else if (UseProxyCheckBox.Checked && (ProxyPortTextBox.Text.Length == 0))
            {
                MessageBox.Show("If you are using a proxy server, please specify the port");
                ProxyPortTextBox.Focus();
            }
            else
            {
                bool bInitialized = false;
                Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                m_ci.setEndpoint(HostnameComboBox.Text, Convert.ToInt32(PortTextBox.Text), EndpointTextBox.Text);
                m_ci.setCredentials(UsernameTextBox.Text, PasswordTextBox.Text);

                // Now verify if we can connect to the host
                if (null == m_interfaces)
                {
                    m_interfaces = new iControl.Interfaces();
                }

                if (UseProxyCheckBox.Checked)
                {
                    bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text, ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text);
                }
                else
                {
                    bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text);
                }

                if (bInitialized)
                {
                    try
                    {
                        //sysInfo.Url = m_ci.buildURL();
                        iControl.SystemProductInformation prodInfo = m_interfaces.SystemSystemInfo.get_product_information();
                        if (null != prodInfo.product_code)
                        {
                            m_ci.setHostType(prodInfo.product_code);
                        }

                        // Check for GTM Support
                        bool bGTMLicensed = false;
                        for (int i = 0; i < prodInfo.product_features.Length; i++)
                        {
                            if (prodInfo.product_features[i].Equals("GTM Rules"))
                            {
                                bGTMLicensed = true;
                                break;
                            }
                        }
                        m_ci.setGTMLicensed(bGTMLicensed);

                        //sysInfo.Dispose();
                        Cursor.Current = System.Windows.Forms.Cursors.Default;
                        this.DialogResult = DialogResult.OK;

                        // Update proxy info in connection info class
                        if (UseProxyCheckBox.Checked)
                        {
                            m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text),
                                ProxyUserTextBox.Text, ProxyPortTextBox.Text);
                        }

                        if (SaveConfigCheckBox.Checked)
                        {
                            m_ci.saveToRegistry(HostnameComboBox.Text);
                        }

                        if (UseProxyCheckBox.Checked)
                        {
                            m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text);
                        }

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    catch (System.Net.WebException)
                    {
                        MessageBox.Show(this, "Connection could not be established to specified host", "Error");
                    }
                    catch (System.UriFormatException)
                    {
                        MessageBox.Show(this, "Connection could not be established to specified host", "Error");
                    }
                }
                else
                {
                    MessageBox.Show(this, "Invalid Connection Information...", "Error");
                }

                //sysInfo.Dispose();
                Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
        }