コード例 #1
0
ファイル: Form1.cs プロジェクト: matthewste/Installer
        private void Form1_Load(object sender, EventArgs e)
        {
            System.IO.FileInfo file = new System.IO.FileInfo("install_log.log");
            file.Directory.Create();

            if (machine == "Server")
            {
                string ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3};", "osae", "osaePass", "localhost", "3306");

                connection = new MySqlConnection(ConnectionString);
                try
                {
                    connection.Open();
                    // osae user found and connection succeeded.  Now Check for DB.

                    MySqlCommand     command;
                    MySqlDataAdapter adapter;
                    DataSet          dataset = new DataSet();
                    command = new MySqlCommand("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'osae'", connection);
                    adapter = new MySqlDataAdapter(command);
                    adapter.Fill(dataset);
                    connection.Close();
                    int count = dataset.Tables[0].Rows.Count;

                    if (count == 1)
                    {
                        // DB found.  Need to upgrade.  First find out current version.
                        addToLog("Found OSA database.  Checking to see if we need to upgrade.");
                        dataset          = new DataSet();
                        ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", "osae", "osaePass", "localhost", "3306", "osae");
                        connection       = new MySqlConnection(ConnectionString);
                        connection.Open();
                        command = new MySqlCommand("select property_value from osae_object_property p inner join osae_object_type_property tp on p.object_type_property_id = tp.property_id inner join osae_object o on o.object_id = p.object_id where object_name = 'SYSTEM' and property_name = 'DB Version'", connection);
                        adapter = new MySqlDataAdapter(command);
                        adapter.Fill(dataset);
                        if (dataset.Tables[0].Rows[0][0].ToString() == "")
                        {
                            current = "0.1.0";
                        }
                        else
                        {
                            current = dataset.Tables[0].Rows[0][0].ToString();
                        }
                        if (current == newVersion)
                        {
                            this.Close();
                        }
                        else
                        {
                            lblFoundDB.Text = "Found version " + current + "\nClick button to upgrade to v" + newVersion;
                            btnInstall.Text = "Upgrade";
                        }
                    }
                    else
                    {
                        // DB not found.  Need to install.
                        addToLog("No OSA database found.  We need to install it.");
                        MySqlScript script = new MySqlScript(connection, File.ReadAllText(directory + "\\osae.sql"));
                        script.Execute();
                        connection.Close();
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    // osae user not found.  Must be an existing mySql install without OSA installed.  Need to ask for root password.
                    addToLog("Unable to connect with osae account: " + ex.Message);

                    ServiceController sc = new ServiceController();
                    if (IsServiceInstalled("MySql55"))
                    {
                        sc = new ServiceController("MySql55");
                    }
                    else if (IsServiceInstalled("MySQL55"))
                    {
                        sc = new ServiceController("MySQL55");
                    }
                    else if (IsServiceInstalled("MySql"))
                    {
                        sc = new ServiceController("MySql");
                    }
                    else if (IsServiceInstalled("MySQL"))
                    {
                        sc = new ServiceController("MySQL");
                    }

                    if (sc.Status != ServiceControllerStatus.Running)
                    {
                        addToLog("MySql service is not running!");
                        lblFoundDB.Text = "The MySql service is not running.  \nPlease make sure it is running and run the \nOpen Source Automation installer again.";
                        btnInstall.Text = "Close";
                    }
                    else
                    {
                        btnInstall.Text      = "OK";
                        lbl1.Visible         = true;
                        lbl2.Visible         = true;
                        label1.Visible       = true;
                        txbPassword.Visible  = true;
                        txbUsername.Visible  = true;
                        txbxLocation.Visible = true;
                        btnOpenFile.Visible  = true;
                        lblFoundDB.Text      = "Existing MySql Server found. \nPlease enter your root password and \nspecify location of mysql.exe. Usually \nC:\\Program Files\\MySql\\bin\\mysql";
                    }
                }
            }
            else
            {
                label1.Visible       = false;
                txbxLocation.Visible = false;
                btnOpenFile.Visible  = false;
                lbl1.Visible         = true;
                txbUsername.Text     = "";
                lbl2.Visible         = true;
                txbPassword.Visible  = true;
                txbPassword.UseSystemPasswordChar = false;
                txbUsername.Visible = true;
                lbl1.Text           = "Server:";
                lbl2.Text           = "Port:";

                ModifyRegistry myRegistry = new ModifyRegistry();
                myRegistry.SubKey = "SOFTWARE\\OSAE\\DBSETTINGS";
                txbPassword.Text  = myRegistry.Read("DBPORT");
                txbUsername.Text  = myRegistry.Read("DBCONNECTION");

                lblFoundDB.Text = "Please enter the network name or IP \nof the OSA server and click OK.";
                btnInstall.Text = "OK";
            }
        }
コード例 #2
0
        private void btnInstall_Click(object sender, EventArgs e)
        {
            if (machine == "Server")
            {
                if (btnInstall.Text == "Upgrade")
                {
                    upgrade();
                    this.Close();
                }
                else if (btnInstall.Text == "OK")
                {
                    string mysqlDir = "", iniDir = "";
                    if (txbxLocation.Text != "")
                    {
                        mysqlDir = txbxLocation.Text;
                    }
                    else
                    {
                        mysqlDir = ProgramFilesx86() + "\\MySql\\bin\\mysql";
                    }

                    //iniDir = mysqlDir.Substring(0, mysqlDir.IndexOf("bin")-1);
                    //if (File.Exists(iniDir + "my.ini"))
                    //{
                    //    StreamWriter sw = File.AppendText(iniDir + "my.ini");
                    //    sw.WriteLine("event_scheduler=ON");
                    //    sw.Close();
                    //}

                    string args = " -u" + txbUsername.Text + " -p" + txbPassword.Text + " --execute \"CREATE USER `osae`@`%` IDENTIFIED BY \'osaePass\'\";";
                    Process p = Process.Start(mysqlDir, args);
                    p.WaitForExit();

                    string ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3}", txbUsername.Text, txbPassword.Text, "localhost", "3306");
                    connection = new MySqlConnection(ConnectionString);
                    MySqlCommand command;
                    MySqlDataAdapter adapter;
                    DataSet dataset = new DataSet();
                    command = new MySqlCommand("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'osae'", connection);
                    adapter = new MySqlDataAdapter(command);
                    adapter.Fill(dataset);
                    connection.Close();
                    int count = dataset.Tables[0].Rows.Count;

                    args = " -u" + txbUsername.Text + " -p" + txbPassword.Text + " --execute \"GRANT ALL ON osae.* TO `osae`@`%`\";";
                    p = Process.Start(mysqlDir, args);
                    p.WaitForExit();

                    if (count == 1)
                    {
                        try
                        {
                            ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3};Database={4};allow user variables=true", txbUsername.Text, txbPassword.Text, "localhost", "3306", "osae");
                            connection = new MySqlConnection(ConnectionString);

                            connection.Open();
                            dataset = new DataSet();
                            command = new MySqlCommand("select property_value from osae_object_property p inner join osae_object_type_property tp on p.object_type_property_id = tp.property_id inner join osae_object o on o.object_id = p.object_id where object_name = 'SYSTEM' and property_name = 'DB Version'", connection);
                            adapter = new MySqlDataAdapter(command);
                            adapter.Fill(dataset);
                            if (dataset.Tables[0].Rows[0][0].ToString() == "")
                                current = "0.1.0";
                            else
                                current = dataset.Tables[0].Rows[0][0].ToString();
                            if (current != newVersion)
                            {
                                upgrade();
                            }
                            connection.Close();
                            this.Close();
                        }
                        catch
                        {
                            MessageBox.Show("Connection error.  Please check password.");
                        }
                    }
                    else
                    {

                        MySqlScript script = new MySqlScript(connection, File.ReadAllText(directory + "\\osae.sql"));
                        script.Execute();

                        script = new MySqlScript(connection, "SET GLOBAL event_scheduler=ON;");
                        script.Execute();

                        connection.Close();

                        MessageBox.Show("Database installed successfully.");
                        this.Close();
                    }
                }
                else
                    this.Close();
            }
            else if (btnInstall.Text == "OK")
            {
                ModifyRegistry myRegistry = new ModifyRegistry();
                myRegistry.SubKey = "SOFTWARE\\OSAE\\DBSETTINGS";
                myRegistry.Write("DBCONNECTION", txbUsername.Text);
                myRegistry.Write("DBPORT", txbPassword.Text);
                this.Close();
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: matthewste/Installer
        private void btnInstall_Click(object sender, EventArgs e)
        {
            if (machine == "Server")
            {
                if (btnInstall.Text == "Upgrade")
                {
                    upgrade();
                    this.Close();
                }
                else if (btnInstall.Text == "OK")
                {
                    string mysqlDir = "", iniDir = "";
                    if (txbxLocation.Text != "")
                    {
                        mysqlDir = txbxLocation.Text;
                    }
                    else
                    {
                        mysqlDir = ProgramFilesx86() + "\\MySql\\bin\\mysql";
                    }

                    //iniDir = mysqlDir.Substring(0, mysqlDir.IndexOf("bin")-1);
                    //if (File.Exists(iniDir + "my.ini"))
                    //{
                    //    StreamWriter sw = File.AppendText(iniDir + "my.ini");
                    //    sw.WriteLine("event_scheduler=ON");
                    //    sw.Close();
                    //}

                    string  args = " -u" + txbUsername.Text + " -p" + txbPassword.Text + " --execute \"CREATE USER `osae`@`%` IDENTIFIED BY \'osaePass\'\";";
                    Process p    = Process.Start(mysqlDir, args);
                    p.WaitForExit();


                    string ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3}", txbUsername.Text, txbPassword.Text, "localhost", "3306");
                    connection = new MySqlConnection(ConnectionString);
                    MySqlCommand     command;
                    MySqlDataAdapter adapter;
                    DataSet          dataset = new DataSet();
                    command = new MySqlCommand("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'osae'", connection);
                    adapter = new MySqlDataAdapter(command);
                    adapter.Fill(dataset);
                    connection.Close();
                    int count = dataset.Tables[0].Rows.Count;

                    args = " -u" + txbUsername.Text + " -p" + txbPassword.Text + " --execute \"GRANT ALL ON osae.* TO `osae`@`%`\";";
                    p    = Process.Start(mysqlDir, args);
                    p.WaitForExit();

                    if (count == 1)
                    {
                        try
                        {
                            ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3};Database={4};allow user variables=true", txbUsername.Text, txbPassword.Text, "localhost", "3306", "osae");
                            connection       = new MySqlConnection(ConnectionString);

                            connection.Open();
                            dataset = new DataSet();
                            command = new MySqlCommand("select property_value from osae_object_property p inner join osae_object_type_property tp on p.object_type_property_id = tp.property_id inner join osae_object o on o.object_id = p.object_id where object_name = 'SYSTEM' and property_name = 'DB Version'", connection);
                            adapter = new MySqlDataAdapter(command);
                            adapter.Fill(dataset);
                            if (dataset.Tables[0].Rows[0][0].ToString() == "")
                            {
                                current = "0.1.0";
                            }
                            else
                            {
                                current = dataset.Tables[0].Rows[0][0].ToString();
                            }
                            if (current != newVersion)
                            {
                                upgrade();
                            }
                            connection.Close();
                            this.Close();
                        }
                        catch
                        {
                            MessageBox.Show("Connection error.  Please check password.");
                        }
                    }
                    else
                    {
                        MySqlScript script = new MySqlScript(connection, File.ReadAllText(directory + "\\osae.sql"));
                        script.Execute();

                        script = new MySqlScript(connection, "SET GLOBAL event_scheduler=ON;");
                        script.Execute();

                        connection.Close();


                        MessageBox.Show("Database installed successfully.");
                        this.Close();
                    }
                }
                else
                {
                    this.Close();
                }
            }
            else if (btnInstall.Text == "OK")
            {
                ModifyRegistry myRegistry = new ModifyRegistry();
                myRegistry.SubKey = "SOFTWARE\\OSAE\\DBSETTINGS";
                myRegistry.Write("DBCONNECTION", txbUsername.Text);
                myRegistry.Write("DBPORT", txbPassword.Text);
                this.Close();
            }
        }
コード例 #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.IO.FileInfo file = new System.IO.FileInfo("install_log.log");
            file.Directory.Create();

            if (machine == "Server")
            {
                string ConnectionString = string.Format("Uid={0};Password={1};Server={2};Port={3};", "osae", "osaePass", "localhost", "3306");

                connection = new MySqlConnection(ConnectionString);
                try
                {
                    connection.Open();
                    // osae user found and connection succeeded.  Now Check for DB.

                    MySqlCommand command;
                    MySqlDataAdapter adapter;
                    DataSet dataset = new DataSet();
                    command = new MySqlCommand("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'osae'", connection);
                    adapter = new MySqlDataAdapter(command);
                    adapter.Fill(dataset);
                    connection.Close();
                    int count = dataset.Tables[0].Rows.Count;

                    if (count == 1)
                    {
                        // DB found.  Need to upgrade.  First find out current version.
                        addToLog("Found OSA database.  Checking to see if we need to upgrade.");
                        dataset = new DataSet();
                        ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", "osae", "osaePass", "localhost", "3306", "osae");
                        connection = new MySqlConnection(ConnectionString);
                        connection.Open();
                        command = new MySqlCommand("select property_value from osae_object_property p inner join osae_object_type_property tp on p.object_type_property_id = tp.property_id inner join osae_object o on o.object_id = p.object_id where object_name = 'SYSTEM' and property_name = 'DB Version'", connection);
                        adapter = new MySqlDataAdapter(command);
                        adapter.Fill(dataset);
                        if (dataset.Tables[0].Rows[0][0].ToString() == "")
                            current = "0.1.0";
                        else
                            current = dataset.Tables[0].Rows[0][0].ToString();
                        if (current == newVersion)
                        {
                            this.Close();
                        }
                        else
                        {
                            lblFoundDB.Text = "Found version " + current + "\nClick button to upgrade to v" + newVersion;
                            btnInstall.Text = "Upgrade";
                        }

                    }
                    else
                    {
                        // DB not found.  Need to install.
                        addToLog("No OSA database found.  We need to install it.");
                        MySqlScript script = new MySqlScript(connection, File.ReadAllText(directory + "\\osae.sql"));
                        script.Execute();
                        connection.Close();
                        this.Close();

                    }
                }
                catch(Exception ex)
                {
                    // osae user not found.  Must be an existing mySql install without OSA installed.  Need to ask for root password.
                    addToLog("Unable to connect with osae account: " + ex.Message);

                    ServiceController sc = new ServiceController();
                    if(IsServiceInstalled("MySql55"))
                        sc = new ServiceController("MySql55");
                    else if (IsServiceInstalled("MySQL55"))
                        sc = new ServiceController("MySQL55");
                    else if (IsServiceInstalled("MySql"))
                        sc = new ServiceController("MySql");
                    else if (IsServiceInstalled("MySQL"))
                        sc = new ServiceController("MySQL");

                    if (sc.Status != ServiceControllerStatus.Running)
                    {
                        addToLog("MySql service is not running!");
                        lblFoundDB.Text = "The MySql service is not running.  \nPlease make sure it is running and run the \nOpen Source Automation installer again.";
                        btnInstall.Text = "Close";
                    }
                    else
                    {
                        btnInstall.Text = "OK";
                        lbl1.Visible = true;
                        lbl2.Visible = true;
                        label1.Visible = true;
                        txbPassword.Visible = true;
                        txbUsername.Visible = true;
                        txbxLocation.Visible = true;
                        btnOpenFile.Visible = true;
                        lblFoundDB.Text = "Existing MySql Server found. \nPlease enter your root password and \nspecify location of mysql.exe. Usually \nC:\\Program Files\\MySql\\bin\\mysql";
                    }
                }
            }
            else
            {
                label1.Visible = false;
                txbxLocation.Visible = false;
                btnOpenFile.Visible = false;
                lbl1.Visible = true;
                txbUsername.Text = "";
                lbl2.Visible = true;
                txbPassword.Visible = true;
                txbPassword.UseSystemPasswordChar = false;
                txbUsername.Visible = true;
                lbl1.Text = "Server:";
                lbl2.Text = "Port:";

                ModifyRegistry myRegistry = new ModifyRegistry();
                myRegistry.SubKey = "SOFTWARE\\OSAE\\DBSETTINGS";
                txbPassword.Text = myRegistry.Read("DBPORT");
                txbUsername.Text = myRegistry.Read("DBCONNECTION");

                lblFoundDB.Text = "Please enter the network name or IP \nof the OSA server and click OK.";
                btnInstall.Text = "OK";
            }
        }