Ejemplo n.º 1
0
        private void InstallWizard_Load(object sender, System.EventArgs args)
        {
            this.TopMost = true;
            this.Activate();
            this.TopMost = false;

            welcomeBox.Rtf = Helper.ToRtf(installer.package["/Welcome.rtf"].GetContents());
            welcomeBox.Hide();

            // Initialize the step list

            steps = new WizardStepList(this);
            steps.Add(this);

            serverAdminStep = new ServerAdminStep(this);
            AddStep(serverAdminStep);

            selectDatabaseStep = new SelectDatabaseStep(this);
            AddStep(selectDatabaseStep);

            appAccountStep = new ServiceAccountStep(this);
            AddStep(appAccountStep);

            actionRequestStep = new ActionRequestStep(this);
            AddStep(actionRequestStep);

            installStep = new InstallStep(this);
            AddStep(installStep);

            steps.StepTo(steps.FirstStep, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the step is activated.
        /// </summary>
        /// <param name="steps">The step list.</param>
        public void OnStepIn(WizardStepList steps)
        {
            wizard.SetButtonMode(InstallWizard.ButtonMode.DisableAll);
            this.Show();
            this.Update();

            DoInstall();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the step is activated.
        /// </summary>
        /// <param name="steps">The step list.</param>
        public void OnStepIn(WizardStepList steps)
        {
            this.Show();

            if (serverName.Text.Trim() == string.Empty)
            {
                serverName.Focus();
                serverName.SelectAll();
            }
            else
            {
                adminAccount.Focus();
                adminAccount.SelectAll();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called whenever the current step has changed.
        /// </summary>
        /// <param name="steps">The step list.</param>
        /// <param name="step">The new current step.</param>
        public void OnStep(WizardStepList steps, IWizardStep step)
        {
            switch (buttonMode)
            {
            case ButtonMode.Normal:

                cancelButton.Enabled = true;
                backButton.Enabled   = step != steps.FirstStep;
                nextButton.Enabled   = true;
                break;

            case ButtonMode.DisableAll:

                cancelButton.Enabled = false;
                backButton.Enabled   = false;
                nextButton.Enabled   = false;
                break;

            case ButtonMode.FinishOnly:

                cancelButton.Enabled = false;
                backButton.Enabled   = false;
                nextButton.Enabled   = true;
                break;

            case ButtonMode.NoFinish:

                cancelButton.Enabled = true;
                backButton.Enabled   = step != steps.FirstStep;
                nextButton.Enabled   = false;
                break;
            }

            if (step != steps.LastStep)
            {
                nextButton.Text = "Next >";
            }
            else
            {
                nextButton.Text = "Finish";
            }

            this.Text = installer.setupTitle + ": " + step.Title;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when the step is deactivated.
        /// </summary>
        /// <param name="steps">The step list.</param>
        /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
        /// <returns><c>true</c> if the transition can proceed.</returns>
        public bool OnStepOut(WizardStepList steps, bool forward)
        {
            if (!forward)
            {
                return(true);
            }

            var account = (string)accountList.SelectedItem;

            if (account == null)
            {
                MessageBox.Show("Select an account from the list or click Create\r\nto create a new one.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (account.ToUpper() == "SA")
            {
                MessageBox.Show("The SA account cannot be used.  Please select another account.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (account.ToUpper() != wizard.SetupState["account"].ToUpper())
            {
                wizard.SetupState["account"]  = account;
                wizard.SetupState["password"] = string.Empty;
            }

            // Prompt for the account password.

            var form = new PasswordForm(wizard, (string)wizard.SetupState["account"], (string)wizard.SetupState["password"]);

            if (form.ShowDialog(wizard) == DialogResult.Cancel)
            {
                return(false);
            }

            wizard.SetupState["password"] = form.Password;

            this.Hide();
            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Called when the step is deactivated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
 /// <returns><c>true</c> if the transition can proceed.</returns>
 public bool OnStepOut(WizardStepList steps, bool forward)
 {
     this.Hide();
     wizard.SetButtonMode(InstallWizard.ButtonMode.Normal);
     return(true);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Called when the step is deactivated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
 /// <returns><c>true</c> if the transition can proceed.</returns>
 public bool OnStepOut(WizardStepList steps, bool forward)
 {
     this.Hide();
     return(true);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Called when the step is activated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 public void OnStepIn(WizardStepList steps)
 {
     this.Show();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Called when the step is deactivated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
 /// <returns><c>true</c> if the transition can proceed.</returns>
 public bool OnStepOut(WizardStepList steps, bool forward)
 {
     welcomeBox.Hide();
     return(true);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Called when the step is activated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 public void OnStepIn(WizardStepList steps)
 {
     welcomeBox.Show();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Called when the step is deactivated.
        /// </summary>
        /// <param name="steps">The step list.</param>
        /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
        /// <returns><c>true</c> if the transition can proceed.</returns>
        public bool OnStepOut(WizardStepList steps, bool forward)
        {
            if (!forward)
            {
                return(true);
            }

            string database;

            database = (string)databaseList.SelectedItem;
            if (database == null)
            {
                MessageBox.Show("Select a database from the list or click Create\r\nto create a new one.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else if (database.ToUpper() == "MASTER")
            {
                MessageBox.Show("Cannot install into the MASTER database.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // Take a look at the database and ensure that it is either empty
            // or is already associated with this product ID and database type.

            SqlContext ctx;
            SqlCommand cmd;
            DataTable  dt;
            WaitForm   waitForm;
            string     cs;

            wizard.Enabled = false;
            this.Update();

            waitForm          = new WaitForm(string.Format("Examining database [{0}]...", database));
            waitForm.TopLevel = true;
            waitForm.Show();
            waitForm.Update();
            Thread.Sleep(2000);

            cs = string.Format("server={0};database={1};uid={2};pwd={3}",
                               wizard.SetupState["server"],
                               database,
                               wizard.SetupState["adminAccount"],
                               wizard.SetupState["adminPassword"]);

            ctx = new SqlContext(cs);
            try
            {
                ctx.Open();

                // I'm going to determine whether the database is empty or
                // not by looking at the sysobjects table.  We'll consider
                // it to be not empty if any these conditions are true:
                //
                //      1. Any user tables are present whose names
                //         don't begin with "dt".
                //
                //      2. Any stored procedures or functions are present
                //         whose names don't begin with "dt".


                cmd = ctx.CreateCommand("select 1 from sysobjects where (xtype='U' or xtype='P' or xtype='FN') and name not like 'dt%'");
                dt  = ctx.ExecuteTable(cmd);

                if (dt.Rows.Count == 0)
                {
                    // The database appears to be empty.

                    wizard.SetupState["Action"] = "Install";
                }
                else
                {
                    // The database appears to be not empty.  Try calling the
                    // GetProductInfo procedure.  If this fails then assume that
                    // the database belongs to some other application.  If it
                    // succeeds then check the productID and database type against
                    // the setup settings.

                    try
                    {
                        cmd = ctx.CreateSPCall("GetProductInfo");
                        dt  = ctx.ExecuteTable(cmd);

                        // Compare the database's product ID and database type to
                        // the setup settings.

                        if (SqlHelper.AsString(dt.Rows[0]["ProductID"]) != wizard.SetupState["productID"] ||
                            SqlHelper.AsString(dt.Rows[0]["DatabaseType"]) != wizard.SetupState["databaseType"])
                        {
                            wizard.Enabled = true;
                            waitForm.Close();
                            MessageBox.Show(string.Format("Database [{0}] is configured for use by [{1}:{2}].\r\n\r\nPlease select a different database.",
                                                          database,
                                                          SqlHelper.AsString(dt.Rows[0]["ProductName"]),
                                                          SqlHelper.AsString(dt.Rows[0]["DatabaseType"])),
                                            wizard.SetupTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(false);
                        }

                        // The database looks like can accept the installation.

                        wizard.SetupState["Action"]           = "Upgrade";
                        wizard.SetupState["CurSchemaVersion"] = SqlHelper.AsString(dt.Rows[0]["SchemaVersion"]);
                    }
                    catch
                    {
                        wizard.Enabled = true;
                        waitForm.Close();
                        MessageBox.Show(string.Format("Database [{0}] is not empty and appears to in use by another application.\r\n\r\nPlease select a different database.", database),
                                        wizard.SetupTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                wizard.Enabled = true;
                waitForm.Close();
                MessageBox.Show("Setup could not connect to the database. Please check\r\nthe server name and account settings.\r\n\r\n" + e.Message,
                                wizard.SetupTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                ctx.Close();
            }

            wizard.Enabled = true;
            waitForm.Close();

            // Success!

            wizard.SetupState["database"]         = database;
            wizard.SetupState["connectionString"] = string.Format("server={0};database={1};uid={2};pwd={3}",
                                                                  wizard.SetupState["server"],
                                                                  wizard.SetupState["database"],
                                                                  wizard.SetupState["adminAccount"],
                                                                  wizard.SetupState["adminPassword"]);
            this.Hide();
            return(true);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Called when the step is activated.
 /// </summary>
 /// <param name="steps">The step list.</param>
 public void OnStepIn(WizardStepList steps)
 {
     this.Show();
     databaseList.Focus();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Called when the step is deactivated.
        /// </summary>
        /// <param name="steps">The step list.</param>
        /// <param name="forward"><c>true</c> if we're stepping forward in the wizard.</param>
        /// <returns><c>true</c> if the transition can proceed.</returns>
        public bool OnStepOut(WizardStepList steps, bool forward)
        {
            if (!forward)
            {
                return(true);
            }

            string server;
            string account;
            string password;

            // Validate the dialog entries.

            server   = serverName.Text.Trim();
            account  = adminAccount.Text.Trim();
            password = adminPassword.Text.Trim();

            if (server == string.Empty)
            {
                MessageBox.Show("Please enter the database server name or IP address.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                serverName.Focus();
                serverName.SelectAll();
                return(false);
            }

            if (account == string.Empty)
            {
                MessageBox.Show("Please enter the database administrator account.", wizard.SetupTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                adminAccount.Focus();
                adminAccount.SelectAll();
                return(false);
            }

            // Verify that the database server exists and that the account information
            // is valid by connecting to the database executing sp_helpsrvrolemember
            // and verifying that the account is returned as one of the accounts having
            // the sysadmin role.
            //
            // Note that sp_helpsrvrolemember does not exist on SQL Azure, so we're going
            // to first determine whether we're running on Azure and then skip this call
            // if we are.

            string     conString;
            SqlContext ctx;
            SqlCommand cmd;
            DataTable  dt;
            bool       found;
            WaitForm   waitForm;

            conString = string.Format("server={0};database={1};uid={2};pwd={3}",
                                      server, "master", account, password);

            wizard.Enabled = false;
            this.Update();

            waitForm          = new WaitForm("Verifying administrator credentials...");
            waitForm.TopLevel = true;
            waitForm.Show();
            waitForm.Update();
            Thread.Sleep(2000);

            ctx = new SqlContext(conString);
            try
            {
                ctx.Open();

                // SQL Azure detection

                wizard.IsSqlAzure = ctx.IsSqlAzure;

                // Verify that the account is an admin

                if (!wizard.IsSqlAzure)
                {
                    cmd = ctx.CreateSPCall("sp_helpsrvrolemember");
                    cmd.Parameters.Add("@srvrolename", SqlDbType.NVarChar).Value = "sysadmin";

                    dt    = ctx.ExecuteTable(cmd);
                    found = false;
                    foreach (DataRow row in dt.Rows)
                    {
                        if (String.Compare(account, SqlHelper.AsString(row["MemberName"]), true) == 0)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        wizard.Enabled = true;
                        waitForm.Close();

                        MessageBox.Show(string.Format("Account [{0}] is not a system administrator.", account.ToUpper()),
                                        wizard.SetupTitle,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);

                        adminAccount.Focus();
                        adminAccount.SelectAll();
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                wizard.Enabled = true;
                waitForm.Close();
                MessageBox.Show("Setup could not connect to the database. Please check\r\nthe server name and account settings.\r\n\r\n" + e.Message,
                                wizard.SetupTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally
            {
                ctx.Close();
            }

            wizard.Enabled = true;
            waitForm.Close();

            wizard.SetupState["connectionString"] = conString;
            wizard.SetupState["server"]           = server;
            wizard.SetupState["adminAccount"]     = account;
            wizard.SetupState["adminPassword"]    = password;

            this.Hide();
            return(true);
        }