Exemplo n.º 1
0
        /// <summary>
        /// Creates a new configuration handler and adds it to the section handler collection.
        /// </summary>
        /// <param name="parent">The configuration settings in a corresponding parent configuration section. </param>
        /// <param name="configContext">The virtual path for which the configuration section handler computes configuration values. Normally this parameter is reserved and is a null reference </param>
        /// <param name="section">The XmlNode that contains the configuration information to be handled. Provides direct access to the XML contents of the configuration section. </param>
        /// <returns></returns>
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            MigrationSettings settings = new MigrationSettings();
            string            ID;
            VersionSetting    setting;


            foreach (XmlNode version in section.ChildNodes)
            {
                if (version.Name == "CurrentVersion")
                {
                    ID = version.Attributes["ID"].Value.Trim();
                    if (ID == "")
                    {
                        throw new ApplicationException("CurrentVersion ID can not be empty");
                    }

                    setting = new VersionSetting(ID);

                    foreach (XmlNode step in version.ChildNodes)
                    {
                        if (step.Name == "Step")
                        {
                            setting.AddStep(step.Attributes["Description"].Value, step.Attributes["Script"].Value);
                        }
                    }
                    settings.AddVersion(ID, setting);
                }
            }
            return(settings);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Installs the database
        /// </summary>
        public void InstallDatabase()
        {
            string connectionString;
            string sql;
            string webUserName;
            string newVersion;
            string containsRptSQLJob;

            containsRptSQLJob = "yes";
            connectionString  = "";
            webUserName       = "";
            try
            {
                if (ApplicationState.RptWebUsername != null)
                {
                    if (ApplicationState.RptWebUserType.Equals(SqlUserType.IntegratedUser))
                    {
                        webUserName = ApplicationState.RptWebNTUsername;
                    }
                }

                if ((webUserName == "") || (webUserName == null))
                {
                    webUserName = ApplicationState.RptWebUsername;
                }
            }
            catch
            {
                DialogResult r = MessageBox.Show("ApplicationState.Exception trying to read UserName", "info", MessageBoxButtons.OK);
            }

            try
            {
                containsRptSQLJob = ConfigurationSettings.AppSettings["ContainsRptSQLJob"];
            }
            catch
            {
                DialogResult r = MessageBox.Show("ConfigurationSettings.AppSettings.Exception trying to read ContainsRptSQLJob", "info", MessageBoxButtons.OK);
            }

            try
            {
                try
                {
                    connectionString = SqlTool.GetConnectionString(ApplicationState.RptServerName, ApplicationState.RptDatabaseName, ApplicationState.RptDboUserType, ApplicationState.RptDboUsername, ApplicationState.RptDboPassword);
                }
                catch
                {
                    DialogResult r = MessageBox.Show("ConfigurationSettings.AppSettings.Exception trying to build connectionstring", "info", MessageBoxButtons.OK);
                }
                //DialogResult r2 = MessageBox.Show("connectionString=" + connectionString, "info", MessageBoxButtons.YesNo);

                //1. Install schema
                String ErrorNum = "0";
                if (ApplicationState.RptInstallVersion != "")
                {
                    try
                    {
                        MigrationSettings settingsa = (MigrationSettings)ConfigurationSettings.GetConfig("MigrationSettings");
                        ErrorNum = "1";
                    }
                    catch
                    {
                        DialogResult r = MessageBox.Show("ConfigurationSettings.GetConfig.Exception trying to read MigrationSettings", "info", MessageBoxButtons.OK);
                    }

                    try
                    {
                        MigrationSettings settingsb       = (MigrationSettings)ConfigurationSettings.GetConfig("MigrationSettings");
                        VersionSetting    versionSettingb = settingsb.GetVersion(ApplicationState.RptInstallVersion);
                        ErrorNum = "2";
                    }
                    catch
                    {
                        DialogResult r = MessageBox.Show("settings.GetVersion.Exception trying to read RptInstallVersion", "info", MessageBoxButtons.OK);
                    }
                    try
                    {
                        MigrationSettings   settingsc       = (MigrationSettings)ConfigurationSettings.GetConfig("MigrationSettings");
                        VersionSetting      versionSettingc = settingsc.GetVersion(ApplicationState.RptInstallVersion);
                        NameValueCollection stepsc          = versionSettingc.Steps;
                        ErrorNum = "3";
                    }
                    catch
                    {
                        DialogResult r = MessageBox.Show("NameValueCollection.Exception trying to read versionSettingc.Steps", "info", MessageBoxButtons.OK);
                    }

                    MigrationSettings settings = (MigrationSettings)ConfigurationSettings.GetConfig("MigrationSettings");

                    VersionSetting      versionSetting = settings.GetVersion(ApplicationState.RptInstallVersion);
                    NameValueCollection steps          = versionSetting.Steps;
                    ErrorNum = "4";

                    int stepsCount, step;
                    step       = 0;
                    stepsCount = steps.Count;

                    foreach (string description in steps.AllKeys)
                    {
                        try
                        {
                            step++;
                            if (this.cancel)
                            {
                                System.Windows.Forms.Application.Exit();
                            }
                            sql      = "";
                            ErrorNum = "5";
                            try
                            {
                                sql = SqlTool.ReadScript(steps[description]);
                            }
                            catch
                            {
                                DialogResult r = MessageBox.Show("Null NAME in NAME-VALUE collection", "info", MessageBoxButtons.OK);
                            }

                            /*
                             * -- Parameters:
                             * -- This values will be set in the deployment process
                             * -- {0} Databasename
                             * -- {1} WEB SQL Login
                             * -- {2} Salt Administrator username
                             * -- {3} Salt Administrator password
                             */

                            //-- We don't want language translation {0} type place holders to be replaced.
                            if (description == "Optimising Reports" || description == "Creating SQL server Job")
                            {
                                sql = String.Format(sql,
                                                    ApplicationState.RptDatabaseName.Replace("'", "''"),
                                                    webUserName.Replace("'", "''"),
                                                    ApplicationState.RptAdminUsername.Replace("'", "''"),
                                                    ApplicationState.RptAdminPassword.Replace("'", "''")
                                                    );
                            }
                            ErrorNum = "6";

                            if (this.cancel)
                            {
                                System.Windows.Forms.Application.Exit();
                            }
                            this.lblStatus.Text = description + "...";

                            SqlTool.Execute(connectionString, sql);

                            this.prgStatus.Value = Convert.ToInt16((step * 1.0 / stepsCount) * 90.00);
                        }
                        catch (Exception ex)
                        {
                            this.lblError.Text += ex.Message + "\n";
                            MessageBox.Show(" Error " + ErrorNum + ex.Message + Environment.NewLine + ex.StackTrace);
                            Thread.Sleep(1000);
                        }
                    }

                    //Update Version
                    try
                    {
                        this.lblStatus.Text = "Set Application Version" + "...";

                        sql        = ConfigurationSettings.AppSettings["SetVersionScript"];
                        newVersion = ConfigurationSettings.AppSettings["NewVersionID"];

                        sql = String.Format(sql, newVersion.Replace("'", "''"));

                        SqlTool.Execute(connectionString, sql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 77 " + ex.Message + Environment.NewLine + ex.StackTrace);
                        Thread.Sleep(1000);
                    }
                }


                //2. Grant Web SQL Login access permission
                try
                {
                    if (ApplicationState.RptWebGrantPermission)
                    {
                        this.lblStatus.Text = "Grant Web SQL Login access permission" + "...";

                        sql = ConfigurationSettings.AppSettings["GrantPermissionScript"];
                        DialogResult r = MessageBox.Show("Are you sure you wish to Grant permissions to " + webUserName, "Confirm", MessageBoxButtons.YesNo);

                        bool ok = (r == DialogResult.Yes);
                        if (ok)
                        {
                            sql = String.Format(sql, webUserName.Replace("'", "''"));
                            SqlTool.Execute(connectionString, sql);
                        }


                        //sql = String.Format(sql, webUserName.Replace("'", "''"));


                        this.prgStatus.Value = 90;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(" The stored procedure that Grants Web SQL Login access permission failed with error:" + ex.Message + Environment.NewLine + ex.StackTrace);

                    Thread.Sleep(1000);
                    this.prgStatus.Value = 90;
                }


                //3. Set database connection
                try
                {
                    String      strRptServer      = "";
                    String      strRptDatabase    = "";
                    SqlUserType strRptWebUserType = SqlUserType.IntegratedUser;
                    String      strRptWebUserName = "";
                    String      strPassword       = "";

                    this.lblStatus.Text = "Set database connection" + "...";
                    try
                    {
                        strRptServer = ApplicationState.RptServerName;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: ApplicationState.RptServerName is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    if (strRptServer == null)
                    {
                        MessageBox.Show(" Error 81: ApplicationState.RptServerName is null");
                    }
                    try
                    {
                        strRptDatabase = ApplicationState.RptDatabaseName;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: ApplicationState.RptDatabaseName is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    if (strRptDatabase == null)
                    {
                        MessageBox.Show(" Error 81: ApplicationState.RptDatabaseName is null");
                    }
                    try
                    {
                        strRptWebUserType = ApplicationState.RptWebUserType;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: ApplicationState.RptWebUserType is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    if (strRptWebUserType == null)
                    {
                        MessageBox.Show(" Error 81: ApplicationState.RptWebUserType is null");
                    }
                    try
                    {
                        strRptWebUserName = ApplicationState.RptWebUsername;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: ApplicationState.RptWebUsername is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    if (strRptWebUserName == null)
                    {
                        MessageBox.Show(" Error 81: ApplicationState.RptWebUsername is null");
                    }
                    try
                    {
                        strPassword = ApplicationState.RptWebPassword;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: ApplicationState.RptWebPassword is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    if (strPassword == null)
                    {
                        MessageBox.Show(" Error 81: ApplicationState.RptWebPassword is null");
                    }
                    string strWebConnectionString = "";
                    try
                    {
                        strWebConnectionString = SqlTool.GetConnectionString(
                            strRptServer,
                            strRptDatabase,
                            strRptWebUserType,
                            strRptWebUserName,
                            strPassword);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Error 80: strWebConnectionString is null" + ex.Message + Environment.NewLine + ex.StackTrace);
                    }

                    this.UpdateWebConfig(strWebConnectionString, ApplicationState.RptWebPassword);
                    this.prgStatus.Value = 100;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(" Error 80 " + ex.Message + Environment.NewLine + ex.StackTrace);
                    Thread.Sleep(1000);
                    this.prgStatus.Value = 100;
                }


                Thread.Sleep(1000);

                this.Hide();

                if (containsRptSQLJob.ToLower() == "yes")
                {
                    MessageBox.Show("Please notify the database administrator that SQL Server Agent must be running in order to do background processing");
                }



                FrmRptComplete.Form.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 78:" + ex.Message + Environment.NewLine + ex.StackTrace);
                Thread.Sleep(1000);
                System.Windows.Forms.Application.Exit();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Installs the database
        /// </summary>
        public void InstallDatabase()
        {
            string connectionString;
            string sql;
            string webUserName;
            string newVersion;
            string containsSQLJob;

            if (ApplicationState.WebUserType == SqlUserType.IntegratedUser)
            {
                webUserName = ApplicationState.WebNTUsername;
            }
            else
            {
                webUserName = ApplicationState.WebUsername;
            }

            containsSQLJob = ConfigurationSettings.AppSettings["ContainsSQLJob"];

            try
            {
                connectionString = SqlTool.GetConnectionString(ApplicationState.ServerName, ApplicationState.DatabaseName, ApplicationState.DboUserType, ApplicationState.DboUsername, ApplicationState.DboPassword);

                //1. Install schema
                if (ApplicationState.InstallVersion != "")
                {
                    MigrationSettings   settings       = (MigrationSettings)ConfigurationSettings.GetConfig("MigrationSettings");
                    VersionSetting      versionSetting = settings.GetVersion(ApplicationState.InstallVersion);
                    NameValueCollection steps          = versionSetting.Steps;

                    int stepsCount, step;
                    step       = 0;
                    stepsCount = steps.Count;

                    foreach (string description in steps.AllKeys)
                    {
                        step++;
                        if (!description.Equals("Optimising Reports"))
                        {
                            try
                            {
                                if (this.cancel)
                                {
                                    System.Windows.Forms.Application.Exit();
                                }
                                // Skip the OptimizedScripts

                                this.lblStatus.Text = description + "...";

                                sql = SqlTool.ReadScript(steps[description]);

                                /*
                                 * -- Parameters:
                                 * -- This values will be set in the deployment process
                                 * -- {0} Databasename
                                 * -- {1} WEB SQL Login
                                 * -- {2} Salt Administrator username
                                 * -- {3} Salt Administrator password
                                 */

                                //-- We don't want language translation {0} type place holders to be replaced.
                                if (description == "Optimising Reports" || description == "Creating SQL server Job" || description == "Load Data")
                                {
                                    sql = String.Format(sql,
                                                        ApplicationState.DatabaseName.Replace("'", "''"),
                                                        webUserName.Replace("'", "''"),
                                                        ApplicationState.AdminUsername.Replace("'", "''"),
                                                        ApplicationState.AdminPassword.Replace("'", "''")
                                                        );
                                }
                                else if (description == "Set DB Server Time Zone")
                                {
                                    sql = sql.Replace("@@@VVV@@@", ApplicationState.DBServerTZ);
                                }


                                sql = sql.Replace("{databaseUser}", webUserName.Replace("'", "''"));
                                sql = sql.Replace("{database}", ApplicationState.DatabaseName.Replace("'", "''"));
                                if (this.cancel)
                                {
                                    System.Windows.Forms.Application.Exit();
                                }


                                SqlTool.Execute(connectionString, sql);

                                this.prgStatus.Value = Convert.ToInt16((step * 1.0 / stepsCount) * 90.00);
                            }
                            catch (Exception ex)
                            {
                                this.lblError.Text += ex.Message + "\n";
                                MessageBox.Show("Error:" + ex.Message + Environment.NewLine + ex.StackTrace);
                            }
                        }
                    }

                    //Update Version
                    this.lblStatus.Text = "Set Application Version" + "...";

                    sql        = ConfigurationSettings.AppSettings["SetVersionScript"];
                    newVersion = ConfigurationSettings.AppSettings["NewVersionID"];

                    sql = String.Format(sql, newVersion.Replace("'", "''"));

                    SqlTool.Execute(connectionString, sql);
                }


                //2. Grant Web SQL Login access permission
                if (ApplicationState.WebGrantPermission)
                {
                    this.lblStatus.Text = "Grant Web SQL Login access permission" + "...";

                    sql = ConfigurationSettings.AppSettings["GrantPermissionScript"];


                    sql = String.Format(sql, webUserName.Replace("'", "''"));

                    SqlTool.Execute(connectionString, sql);

                    this.prgStatus.Value = 90;
                }

                //3. Set database connection
                this.lblStatus.Text = "Set database connection" + "...";
                string strWebConnectionString = SqlTool.GetConnectionString(
                    ApplicationState.ServerName,
                    ApplicationState.DatabaseName,
                    ApplicationState.WebUserType,
                    ApplicationState.WebUsername,
                    ApplicationState.WebPassword);

                this.UpdateWebConfig(strWebConnectionString, ApplicationState.WebPassword);
                //this.UpdateCPDWebConfig(strWebConnectionString, ApplicationState.WebPassword);
                this.prgStatus.Value = 100;

                Thread.Sleep(1000);

                this.Hide();

                if (containsSQLJob.ToLower() == "yes")
                {
                    MessageBox.Show("Please notify the database administrator that SQL Server Agent must be running in order to do background processing");
                }

                //Thread.CurrentThread.Abort();
                FrmComplete.Form.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message + Environment.NewLine + ex.StackTrace);
                System.Windows.Forms.Application.Exit();
            }
        }