List:Commits« Previous MessageNext Message »
From:Iggy Galarza Date:February 3 2011 9:22pm
Subject:bzr commit into wex-installer-1.0 branch (iggy:297)
View as plain text  
#At file:///C:/src/bzr.mysql/wex/installer/ based on revid:iggy@stripped

  297 Iggy Galarza	2011-02-03
      Refactored configuration.

    modified:
      WexInstaller/Panels/ProductConfigurationController.cs
=== modified file 'WexInstaller/Panels/ProductConfigurationController.cs'
--- a/WexInstaller/Panels/ProductConfigurationController.cs	2011-02-03 17:34:36 +0000
+++ b/WexInstaller/Panels/ProductConfigurationController.cs	2011-02-03 21:22:49 +0000
@@ -81,6 +81,10 @@ namespace WexInstaller.Panels
     {
         private BackgroundWorker bgw;
         private UserControl[] pages;
+        private bool processedTemplate;
+        private bool processedService;
+        private bool processedSecuritySettings;
+
         public IniTemplate it { get; set; }
         public MySQLServiceControlManager mysql_scm { get; set; }
 
@@ -101,6 +105,10 @@ namespace WexInstaller.Panels
             CurrentState = ConfigState.ConfigurationRequired;
             Logger.LogInformation("Product configuration controller created.");
             Initalize();
+
+            processedTemplate = false;
+            processedService = false;
+            processedSecuritySettings = false;
         }
 
         public override UserControl[] Pages
@@ -130,13 +138,8 @@ namespace WexInstaller.Panels
             bgw.RunWorkerAsync();
         }
 
-        private void bgw_DoConfigure(object sender, DoWorkEventArgs e)
+        private bool ProcessTemplate()
         {
-            if (it == null)
-                Initalize();
-
-            Logger.LogInformation("Beginning product configuration.");
-
             OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "VALID_TEMPLATE"));
             if (it.IsValid)
             {
@@ -173,78 +176,115 @@ namespace WexInstaller.Panels
                 OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "PROCESS_TEMPLATE"));
                 it.ProcessTemplate();
                 OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "PROCESS_TEMPLATE"));
+                processedTemplate = true;
             }
             else
             {
                 // Bad Template.  Error.
                 OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Error, "VALID_TEMPLATE"));
+
+                processedTemplate = false;
             }
 
-            if (this.CreateService == true)
+            return processedTemplate;
+        }
+
+        private bool ProcessService()
+        {
+            try
             {
-                try
-                {
-                    string thisServiceName = mysql_scm.FindServiceName(it.BaseDir);
+                string thisServiceName = mysql_scm.FindServiceName(it.BaseDir);
 
-                    if (thisServiceName.Length > 0)
-                    //if (it.Reconfiguring)
-                    {
-                        // Make sure the existing server uses the new configuration file, then 
-                        // start it.
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "CONFIGURE_SERVICE"));
-                        mysql_scm.Update(thisServiceName,
-                                         String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}",
-                                         it.BaseDir, it.ConfigurationFile, thisServiceName));
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "CONFIGURE_SERVICE"));
-
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "START_SERVICE"));
-                        mysql_scm.Restart(thisServiceName);
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "START_SERVICE"));
-                    }
-                    else
-                    {
-                        // Add and Start the service. 
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "CONFIGURE_SERVICE"));
-                        mysql_scm.Add(ServiceName, ServiceName,
-                                        String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}", it.BaseDir, it.ConfigurationFile, ServiceName));
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "CONFIGURE_SERVICE"));
-
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "START_SERVICE"));
-                        mysql_scm.Start(ServiceName);
-                        OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "START_SERVICE"));
-                    }
+                if (thisServiceName.Length > 0)
+                //if (it.Reconfiguring)
+                {
+                    // Make sure the existing server uses the new configuration file, then 
+                    // start it.
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "CONFIGURE_SERVICE"));
+                    mysql_scm.Update(thisServiceName,
+                                        String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}",
+                                        it.BaseDir, it.ConfigurationFile, thisServiceName));
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "CONFIGURE_SERVICE"));
+
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "START_SERVICE"));
+                    mysql_scm.Restart(thisServiceName);
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "START_SERVICE"));
                 }
-                catch
+                else
                 {
-                    // Failed to add or start the server
-                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Error, "CONFIGURE_SERVICE"));
+                    // Add and Start the service. 
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "CONFIGURE_SERVICE"));
+                    mysql_scm.Add(ServiceName, ServiceName,
+                                    String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}", it.BaseDir, it.ConfigurationFile, ServiceName));
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "CONFIGURE_SERVICE"));
+
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "START_SERVICE"));
+                    mysql_scm.Start(ServiceName);
+                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "START_SERVICE"));
+
+                    processedService = false;
                 }
 
-                try
+                processedService = true;
+            }
+            catch
+            {
+                // Failed to add or start the server
+                OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Error, "CONFIGURE_SERVICE"));
+            }
+
+            return processedService;
+        }
+
+        private bool ProcessSecuritySettings()
+        {
+            try
+            {
+                OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "SECURITY_SETTING"));
+
+                // Set root password.
+                MySqlCommand cmd = new MySqlCommand();
+                string connectionString = String.Format("server=localhost;user id=root;port={0};database=mysql;", it.Port);
+
+                if (String.IsNullOrEmpty(ExistingRootPassword) == false)
                 {
-                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Info, "SECURITY_SETTING"));
+                    connectionString += String.Format("password={0}", ExistingRootPassword);
+                }
+                cmd.Connection = new MySqlConnection(connectionString);
+                cmd.Connection.Open();
+                cmd.CommandText = String.Format("UPDATE mysql.user SET Password=Password('{0}') WHERE User='root'", RootPassword);
+                cmd.ExecuteNonQuery();
+                cmd.CommandText = "FLUSH PRIVILEGES";
+                cmd.ExecuteNonQuery();
+                cmd.Connection.Close();
+                OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "SECURITY_SETTING"));
+
+                processedSecuritySettings = true;
+            }
+            catch (MySqlException)
+            {
+                // Failed to set root password.
+                OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Error, "SECURITY_SETTING"));
+                processedSecuritySettings = false;
+            }
 
-                    // Set root password.
-                    MySqlCommand cmd = new MySqlCommand();
-                    string connectionString = String.Format("server=localhost;user id=root;port={0};database=mysql;", it.Port);
+            return processedSecuritySettings;
+        }
+
+        private void bgw_DoConfigure(object sender, DoWorkEventArgs e)
+        {
+            if (it == null)
+                Initalize();
 
-                    if (String.IsNullOrEmpty(ExistingRootPassword) == false)
+            Logger.LogInformation("Beginning product configuration.");
+            if (ProcessTemplate())
+            {
+                if (this.CreateService == true)
+                {
+                    if (ProcessService())
                     {
-                        connectionString += String.Format("password={0}", ExistingRootPassword);
+                        ProcessSecuritySettings();
                     }
-                    cmd.Connection = new MySqlConnection(connectionString);
-                    cmd.Connection.Open();
-                    cmd.CommandText = String.Format("UPDATE mysql.user SET Password=Password('{0}') WHERE User='root'", RootPassword);
-                    cmd.ExecuteNonQuery();
-                    cmd.CommandText = "FLUSH PRIVILEGES";
-                    cmd.ExecuteNonQuery();
-                    cmd.Connection.Close();
-                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Success, "SECURITY_SETTING"));
-                }
-                catch (MySqlException)
-                {
-                    // Failed to set root password.
-                    OnConfigured(new ConfigurationEventArgs(ConfigurationEventType.Error, "SECURITY_SETTING"));
                 }
             }
         }


Attachment: [text/bzr-bundle] bzr/iggy@mysql.com-20110203212249-hnigx28ipuvj3kzv.bundle
Thread
bzr commit into wex-installer-1.0 branch (iggy:297) Iggy Galarza3 Feb