/// <summary>
        /// Handler for click of edit button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, EventArgs e)
        {
            //Note: when you click button it is sure that it is during edit only na dnot during installation
            frmGSAParams GSAParamForm = new frmGSAParams();

            //LoadConfigurationFromFileToForm(webConfigpath, GSAParamForm);
            GSAParamForm.LoadConfigurationFromFileToForm(WebConfigPath);

            DialogResult result = GSAParamForm.ShowDialog(); //show the dialog

            //if OK save it to file
            if (result == DialogResult.OK)
            {
                GSAConfiguration gc = GSAParamForm.PopulateGSAConfiguration(null);
                gc.SaveConfigurationsToFile(webConfigpath, false);//do not save the location of custom stylesheet
            }

            GSAParamForm.Dispose();//dispose off the form
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (isInstaller == true)
            {
                this.Visible = false; //hide the form
                                      //retain the form as it contains the information about all web applications

                frmGSAParams GSAParamForm = new frmGSAParams();
                DialogResult result       = GSAParamForm.ShowDialog();

                //check if OK was clicked
                if (result == DialogResult.OK)
                {
                    GSAConfiguration gc = GSAParamForm.PopulateGSAConfiguration(myBasePath);
                    SaveAllWebAppConfigurationsToFile(gc);//save the form
                }
            }

            this.DialogResult = DialogResult.OK; //indicates that OK is clicked
            this.Close();                        //close the form
        }
        public void SaveAllWebAppConfigurationsToFile(GSAConfiguration gc)
        {
            string webConfigFilePath = null;

            foreach (Control c in flowLayoutPanel1.Controls)
            {
                TableLayoutPanel tlb = c as TableLayoutPanel;
                if (tlb != null)
                {
                    foreach (Control child1 in tlb.Controls)
                    {
                        #region update all checked web applications
                        Label PathLabel = child1 as Label;

                        //In case multiple labels are added
                        if ((PathLabel != null) && (PathLabel.Name.Equals(PATH)))
                        {
                            if (!PathLabel.Text.EndsWith(SLASH))
                            {
                                webConfigFilePath = PathLabel.Text + SLASH + WEB_CONFIG_FILE;
                            }
                            else
                            {
                                webConfigFilePath = PathLabel.Text + WEB_CONFIG_FILE;
                            }

                            //SaveConfigurationsToFile(gc, webConfigFilePath);
                            gc.SaveConfigurationsToFile(webConfigFilePath, true); //change the settings of the web application as per the "GSA Settings panel"
                                                                                  //This will always be called during installation
                        }
                        #endregion update all checked web applications
                    }//end: foreach#1
                }
            }

            this.Close();//close the form
        }
        public void SaveAllWebAppConfigurationsToFile(GSAConfiguration gc)
        {
            string webConfigFilePath = null;
            foreach (Control c in flowLayoutPanel1.Controls)
            {
                TableLayoutPanel tlb = c as TableLayoutPanel;
                if (tlb != null)
                {
                    foreach (Control child1 in tlb.Controls)
                    {
                        #region update all checked web applications
                        Label PathLabel = child1 as Label;

                        //In case multiple labels are added
                        if ((PathLabel != null) && (PathLabel.Name.Equals(PATH)))
                        {
                            if (!PathLabel.Text.EndsWith(SLASH))
                            {
                                webConfigFilePath = PathLabel.Text + SLASH + WEB_CONFIG_FILE;
                            }
                            else
                            {
                                webConfigFilePath = PathLabel.Text + WEB_CONFIG_FILE;
                            }

                            //SaveConfigurationsToFile(gc, webConfigFilePath);
                            gc.SaveConfigurationsToFile(webConfigFilePath, true); //change the settings of the web application as per the "GSA Settings panel"
                                                                                    //This will always be called during installation

                        }
                        #endregion update all checked web applications

                    }//end: foreach#1
                }

            }

            this.Close();//close the form
        }
        /// <summary>
        /// Map user parameters in configuration form to the values to store in web.config file.
        /// </summary>
        /// <returns></returns>
        public GSAConfiguration PopulateGSAConfiguration(string ApplicationBasePath)
        {
            GSAConfiguration gc = new GSAConfiguration();

            if (tbGSALocation.Text != null)
            {
                //remove the trailing slash if present
                if (tbGSALocation.Text.EndsWith("/"))
                {
                    int length = tbGSALocation.Text.Length;
                    if (length > 2)
                    {
                        gc.ApplianceLocation = tbGSALocation.Text.Substring(0, length - 1);
                    }
                }
                else
                {
                    gc.ApplianceLocation = tbGSALocation.Text;
                }
            }
            else
            {
                gc.ApplianceLocation = "";
            }

            gc.SiteCollection = tbSiteCollection.Text;
            gc.EnableLogging  = cbEnableLogging.Checked.ToString();
            gc.FrontEnd       = tbFrontEnd.Text;

            //additonal parameters
            if (null != ApplicationBasePath)
            {
                gc.GsaToSpStyle    = ApplicationBasePath + XSLGSA2SP;
                gc.SpToResultStyle = ApplicationBasePath + XSLSP2RESULT;

                //for logging
                gc.LogLocation = ApplicationBasePath + LOGGING_PATH;
            }
            if (rbCustomStylesheet.Checked == true)
            {
                gc.UseGsaStyling = "false";
            }
            else if (rbGSAFrontEnd.Checked == true)
            {
                gc.UseGsaStyling = "true";
            }
            gc.EnableEmbeddedMode = rbGSAFrontEnd.Checked;

            if (rbPublic.Checked == true)
            {
                gc.AccessLevel = "p";
            }
            else if (rbPublicAndSecure.Checked == true)
            {
                gc.AccessLevel = "a";
            }

            if (rbPublicAndSecureDefaultSearchType.Checked == true)
            {
                gc.DefaultSearchType = "publicAndSecure";
            }
            else if (rbPublicDefaultSearchType.Checked == true)
            {
                gc.DefaultSearchType = "public";
            }

            gc.CertificateName  = txtCertName.Text.Trim();
            gc.UseSamlPost      = chkUseSAMLPost.Checked;
            gc.ArtifactConsumer = txtArtifactConsumerURL.Text.Trim();
            gc.IDPEntityID      = txtIDPEntityID.Text.Trim();

            int  trustDuration;
            bool isNum = int.TryParse(txtTrustDuration.Text.Trim(), out trustDuration);

            if (isNum && (trustDuration > 0))
            {
                gc.TrustDuration = Convert.ToInt32(txtTrustDuration.Text.Trim());
            }
            else
            {
                gc.TrustDuration = TRUSTDURATIONDEFAULT; //set to default
            }

            return(gc);
        }
        /// <summary>
        /// Map user parameters in configuration form to the values to store in web.config file.
        /// </summary>
        /// <returns></returns>
        public GSAConfiguration PopulateGSAConfiguration(string ApplicationBasePath)
        {
            GSAConfiguration gc = new GSAConfiguration();
            if (tbGSALocation.Text != null)
            {
                //remove the trailing slash if present
                if (tbGSALocation.Text.EndsWith("/"))
                {
                    int length = tbGSALocation.Text.Length;
                    if (length > 2)
                    {
                        gc.ApplianceLocation = tbGSALocation.Text.Substring(0, length - 1);
                    }
                }
                else
                {
                    gc.ApplianceLocation = tbGSALocation.Text;
                }
            }
            else
            {
                gc.ApplianceLocation = "";
            }

            gc.SiteCollection = tbSiteCollection.Text;
            gc.EnableLogging = cbEnableLogging.Checked.ToString();
            gc.FrontEnd = tbFrontEnd.Text;

            //additonal parameters
            if (null != ApplicationBasePath)
            {
                gc.GsaToSpStyle = ApplicationBasePath +  XSLGSA2SP;
                gc.SpToResultStyle = ApplicationBasePath + XSLSP2RESULT;

                //for logging
                gc.LogLocation = ApplicationBasePath + LOGGING_PATH;
            }
            if (rbCustomStylesheet.Checked == true)
            {
                gc.UseGsaStyling = "false";
            }
            else if (rbGSAFrontEnd.Checked == true)
            {
                gc.UseGsaStyling = "true";
            }
            gc.EnableEmbeddedMode = rbGSAFrontEnd.Checked;

            if (rbPublic.Checked == true)
            {
                gc.AccessLevel = "p";
            }
            else if (rbPublicAndSecure.Checked == true)
            {
                gc.AccessLevel = "a";
            }

            if (rbPublicAndSecureDefaultSearchType.Checked == true)
            {
                gc.DefaultSearchType = "publicAndSecure";
            }
            else if (rbPublicDefaultSearchType.Checked == true)
            {
                gc.DefaultSearchType = "public";
            }

            gc.CertificateName = txtCertName.Text.Trim();
            gc.UseSamlPost = chkUseSAMLPost.Checked;
            gc.ArtifactConsumer = txtArtifactConsumerURL.Text.Trim();
            gc.IDPEntityID = txtIDPEntityID.Text.Trim();

            int trustDuration;
            bool isNum = int.TryParse(txtTrustDuration.Text.Trim(), out trustDuration);
            if (isNum && (trustDuration > 0))
            {
                gc.TrustDuration = Convert.ToInt32(txtTrustDuration.Text.Trim());
            }
            else
            {
                gc.TrustDuration = TRUSTDURATIONDEFAULT; //set to default
            }

            return gc;
        }