Example #1
0
        private void UpdateCPDWebConfig(string connectionString, string password)
        {
            string strWebConfig;

            // holds just the password
            string strConnecitonStringPassword = "";

            // holds the rest of hte connection string
            string strConnectionStringNoPassword = "";

            // get the connection string and remove the password
            string[] strParts = connectionString.Split(';');
            foreach (string strPart in strParts)
            {
                if (strPart.ToLower().IndexOf("password="******";";
                }
            }

            SecurityHandler objSecurity = new SecurityHandler();

            strConnecitonStringPassword = objSecurity.Encrypt(password);

            // Get the installation diretory
            // its the first parameter off the command line arguments
            string strInstallDirectory = "";

            try
            {
                strInstallDirectory = Environment.GetCommandLineArgs()[1];
            }
            catch (Exception ex)
            {
                MessageBox.Show(" This application requires arguements - first arguement is the install directory, message relating to arguements:" + ex.Message + Environment.NewLine + ex.StackTrace);
            }

            // string strInstallDirectory = Environment.GetCommandLineArgs()[0];
            // Above directory is web directory
            DirectoryInfo dirSaltApplication = new DirectoryInfo(strInstallDirectory);

            // Full path and filename to the web.config file.
            strWebConfig = dirSaltApplication.FullName + "\\Reporting\\CPD\\Web.Config";
            Bdw.Application.Salt.Deployment.DatabaseConfiguration.ConfigureWebConfig.WebConfigConnectionString
                (strWebConfig,
                "logconnectionstring", strConnectionStringNoPassword.Replace("\"", ""),
                "connectionstringpassword", strConnecitonStringPassword.Replace("\"", ""));
        }
Example #2
0
        private void btnEncrypt_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (txtUnencrypted.Text.Length > 0)
                {
                    SecurityHandler objSecurityHandler = new SecurityHandler();

                    this.txtEncrypted.Text = objSecurityHandler.Encrypt(this.txtUnencrypted.Text);
                    //this.txtEncrypted.Enabled=true;
                }
                else
                {
                    MessageBox.Show("Enter the password to encrypt");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Encrypting Text" + Environment.NewLine + ex.Message);
            }
        }
        /// <summary>
        /// Updates the installed web.config file with the new connection string.
        /// </summary>
        /// <param name="connectionString">connectionString to be placed in web.config</param>
        /// <param name="password">password in unencrypted form</param>
        private void UpdateWebConfig(string connectionString, string password)
        {
            string strWebConfig;
            string strEmailRptWebConfig;
            string strAdminRptWebConfig;

            // holds just the password
            string strConnecitonStringPassword = "";

            // holds the rest of hte connection string
            string strConnectionStringNoPassword = "";

            // get the connection string and remove the password
            string[] strParts = connectionString.Split(';');
            foreach (string strPart in strParts)
            {
                if (strPart.ToLower().IndexOf("password="******";";
                }
            }

            SecurityHandler objSecurity = new SecurityHandler();

            strConnecitonStringPassword = objSecurity.Encrypt(password);

            // Get the installation diretory
            // its the first parameter off the command line arguments
            string strInstallDirectory = Environment.GetCommandLineArgs()[1];

            // Above directory is web directory
            DirectoryInfo dirSaltApplication = new DirectoryInfo(strInstallDirectory);

            // Full path and filename to the web.config file.
            strWebConfig = dirSaltApplication.FullName + "\\Web.Config";

            // Load Web.Config
            XmlDocument configXmlDocument = new XmlDocument();

            configXmlDocument.Load(strWebConfig);

            // Loop through all application settings until the correct one is found
            foreach (XmlNode node in configXmlDocument["configuration"]["appSettings"])
            {
                if (node.Name == "add")
                {
                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "rptconnectionstring")
                    {
                        // Change the value of the connection string
                        node.Attributes["value"].Value = strConnectionStringNoPassword.Replace("\"", "");
                        //form.lblSQLServer.Text = strConnectionStringNoPassword.Replace("\"", "");
                    }

                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "rptconnectionstringpassword")
                    {
                        // Change the value of the connection string password
                        node.Attributes["value"].Value = strConnecitonStringPassword.Replace("\"", "");
                    }
                }
            }
            configXmlDocument.Save(strWebConfig);

            // Full path and filename to the BuildEmailReport report  web.config file
            strEmailRptWebConfig = dirSaltApplication.FullName + "\\Reporting\\Email\\Web.Config";

            // Load Web.Config
            XmlDocument EmailConfigXmlDocument = new XmlDocument();

            EmailConfigXmlDocument.Load(strEmailRptWebConfig);

            // Loop through all application settings until the correct one is found
            foreach (XmlNode node in EmailConfigXmlDocument["configuration"]["appSettings"])
            {
                if (node.Name == "add")
                {
                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "connectionstring")
                    {
                        // Change the value of the connection string
                        node.Attributes["value"].Value = strConnectionStringNoPassword.Replace("\"", "");
                    }

                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "connectionstringpassword")
                    {
                        // Change the value of the connection string password
                        node.Attributes["value"].Value = strConnecitonStringPassword.Replace("\"", "");
                    }
                }
            }
            EmailConfigXmlDocument.Save(strEmailRptWebConfig);

            // Full path and filename to the AdministrationReport report web.config file
            strAdminRptWebConfig = dirSaltApplication.FullName + "\\Reporting\\Admin\\Web.Config";

            // Load Admin Web.Config
            XmlDocument AdminConfigXmlDocument = new XmlDocument();

            AdminConfigXmlDocument.Load(strAdminRptWebConfig);

            // Loop through all application settings until the correct one is found
            foreach (XmlNode node in AdminConfigXmlDocument["configuration"]["appSettings"])
            {
                if (node.Name == "add")
                {
                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "connectionstring")
                    {
                        // Change the value of the connection string
                        node.Attributes["value"].Value = strConnectionStringNoPassword.Replace("\"", "");
                    }

                    if (node.Attributes.GetNamedItem("key").Value.ToLower() == "connectionstringpassword")
                    {
                        // Change the value of the connection string password
                        node.Attributes["value"].Value = strConnecitonStringPassword.Replace("\"", "");
                    }
                }
            }
            AdminConfigXmlDocument.Save(strAdminRptWebConfig);
        }