/*
         * [Parameter(Position = 0,
         *  Mandatory = false,
         *  ValueFromPipelineByPropertyName = true,
         *  HelpMessage = "Help Text")]
         * [ValidateNotNullOrEmpty]
         * public string Name
         * {
         *
         * }
         */
        #endregion

        protected override void ProcessRecord()
        {
            if (isInitialized())
            {
                iControl.SystemProductInformation prodInfo =
                    GetiControl().SystemSystemInfo.get_product_information();
                ProductInformation pi = new ProductInformation();
                pi.PackageEdition  = prodInfo.package_edition;
                pi.PackageVersion  = prodInfo.package_version;
                pi.ProductCode     = prodInfo.product_code;
                pi.ProductFeatures = prodInfo.product_features;
                pi.ProductVersion  = prodInfo.product_version;

                WriteObject(pi);
            }
            else
            {
                handleNotInitialized();
            }
        }
        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, m_ci.useHttps);
                }
                else
                {
                    bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text, m_ci.useHttps);
                }

                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;
            }
        }
        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
            {
                Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

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

                // Now verify if we can connect to the host
                iControl.SystemSystemInfo sysInfo = new iControl.SystemSystemInfo();
                sysInfo.Credentials     = Clients.ConnectionInfo.creds;
                sysInfo.PreAuthenticate = true;

                try
                {
                    sysInfo.Url = Clients.ConnectionInfo.buildURL();
                    iControl.SystemProductInformation prodInfo = sysInfo.get_product_information();
                    if (null != prodInfo.product_code)
                    {
                        Clients.ConnectionInfo.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;
                        }
                    }
                    Clients.ConnectionInfo.setGTMLicensed(bGTMLicensed);

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

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

                    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");
                }

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