List:Commits« Previous MessageNext Message »
From:Iggy Galarza Date:June 23 2011 8:56pm
Subject:bzr commit into wex-installer-1.0 branch (iggy:519) Bug#61616
View as plain text  
#At file:///C:/src/bzr.mysql/wex/installer/ based on revid:iggy@stripped

  519 Iggy Galarza	2011-06-23
      Bug #61616 - Cleaned up configuration controllers to use common methods and pass along extended error information for failing security setting attempts.

    modified:
      StandardPlugins/Examples/ConfigurationController.cs
      StandardPlugins/Properties/Resources.Designer.cs
      StandardPlugins/Properties/Resources.resx
      StandardPlugins/Server/ConfigurationController.cs
      WexInstaller.Core/ProductConfigurationController.cs
=== modified file 'StandardPlugins/Examples/ConfigurationController.cs'
--- a/StandardPlugins/Examples/ConfigurationController.cs	2011-06-23 19:06:57 +0000
+++ b/StandardPlugins/Examples/ConfigurationController.cs	2011-06-23 20:56:05 +0000
@@ -53,7 +53,7 @@ namespace WexInstaller.Plugins
           CheckForFeaturesToConfigure();
       if (databasesToInstall.Count == 0)
       {
-        ReportStatus(ConfigurationEventType.Success, null, Resources.ConfigSuccessNoFeaturesToConfig, 100);
+        ReportStatus(ConfigurationEventType.Success, Resources.ConfigSuccessNoFeaturesToConfig, 100);
         return;
       }
 
@@ -68,7 +68,7 @@ namespace WexInstaller.Plugins
       connectionString = controller.GetConnectionString(true);
       if (String.IsNullOrEmpty(connectionString))
       {
-        ReportStatus(ConfigurationEventType.Error, "", Resources.ConfigErrorServerBadConnectionString, 100);
+        ReportStatus(ConfigurationEventType.Error, Resources.ConfigErrorServerBadConnectionString, 100);
         return;
       }
 
@@ -123,7 +123,7 @@ namespace WexInstaller.Plugins
       }
       if (runningServers == null || runningServers.Count == 0)
       {
-        ReportStatus(ConfigurationEventType.Error, "", Resources.ConfigErrorServerNotRunning, 100);
+        ReportStatus(ConfigurationEventType.Error, Resources.ConfigErrorServerNotRunning, 100);
         return false;
       }
       return true;
@@ -136,12 +136,12 @@ namespace WexInstaller.Plugins
     {
       databasesToInstall = new List<SampleDatabase>();
 
-      ReportStatus(ConfigurationEventType.Info, null, Resources.ConfigInfoCheckingFeaturesToConfigure, 10);
+      ReportStatus(ConfigurationEventType.Info, Resources.ConfigInfoCheckingFeaturesToConfigure, 10);
 
       string sampleDbLocation = Owner.GetInstalledProductRegistryKey("Sample Databases");
       if (String.IsNullOrEmpty(sampleDbLocation))
       {
-        ReportStatus(ConfigurationEventType.Info, null, Resources.ConfigInfoNoSampleDbsToConfigure, 10);
+        ReportStatus(ConfigurationEventType.Info, Resources.ConfigInfoNoSampleDbsToConfigure, 10);
         return;
       }
 
@@ -176,7 +176,7 @@ namespace WexInstaller.Plugins
         }
         catch
         {
-          ReportError("CONFIGURATION", "Could not open connection to database");
+          ReportError(Properties.Resources.ConfigErrorCouldNotOpenDatabase);
           return;
         }
 
@@ -206,8 +206,7 @@ namespace WexInstaller.Plugins
           }
           catch (Exception e)
           {
-            ReportError("CONFIGURATION", string.Format("Error installing sample database. " + 
-              "The error is:\n\t{0}", e.ToString()));
+            ReportError(string.Format(Properties.Resources.ConfigErrorInstallingSampleDatabase, e.ToString()));
           }
         }
       }

=== modified file 'StandardPlugins/Properties/Resources.Designer.cs'
--- a/StandardPlugins/Properties/Resources.Designer.cs	2011-04-07 18:04:48 +0000
+++ b/StandardPlugins/Properties/Resources.Designer.cs	2011-06-23 20:56:05 +0000
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.1
+//     Runtime Version:4.0.30319.235
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -117,6 +117,24 @@ namespace WexInstaller.Plugins.Propertie
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Could not open connection to database.
+        /// </summary>
+        internal static string ConfigErrorCouldNotOpenDatabase {
+            get {
+                return ResourceManager.GetString("ConfigErrorCouldNotOpenDatabase", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Error installing sample database. The error is:\n\t{0}.
+        /// </summary>
+        internal static string ConfigErrorInstallingSampleDatabase {
+            get {
+                return ResourceManager.GetString("ConfigErrorInstallingSampleDatabase", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Unable to configure as the connection string returns is null or empty.
         /// </summary>
         internal static string ConfigErrorServerBadConnectionString {
@@ -335,7 +353,7 @@ namespace WexInstaller.Plugins.Propertie
         }
         
         /// <summary>
-        ///   Looks up a localized string similar to Unable to update security settings..
+        ///   Looks up a localized string similar to Unable to update security settings. {0}.
         /// </summary>
         internal static string ServerConfigEventSecuritySettingsError {
             get {

=== modified file 'StandardPlugins/Properties/Resources.resx'
--- a/StandardPlugins/Properties/Resources.resx	2011-04-07 18:04:48 +0000
+++ b/StandardPlugins/Properties/Resources.resx	2011-06-23 20:56:05 +0000
@@ -215,7 +215,7 @@
     <value>Processed template.</value>
   </data>
   <data name="ServerConfigEventSecuritySettingsError" xml:space="preserve">
-    <value>Unable to update security settings.</value>
+    <value>Unable to update security settings. {0}</value>
   </data>
   <data name="ServerConfigEventSecuritySettingsInfo" xml:space="preserve">
     <value>Attempting to update security settings.</value>
@@ -274,4 +274,10 @@
   <data name="ServerConfigFirewallSettingSucceeded" xml:space="preserve">
     <value>Adding firewall rule was successful.</value>
   </data>
+  <data name="ConfigErrorCouldNotOpenDatabase" xml:space="preserve">
+    <value>Could not open connection to database</value>
+  </data>
+  <data name="ConfigErrorInstallingSampleDatabase" xml:space="preserve">
+    <value>Error installing sample database. The error is:\n\t{0}</value>
+  </data>
 </root>
\ No newline at end of file

=== modified file 'StandardPlugins/Server/ConfigurationController.cs'
--- a/StandardPlugins/Server/ConfigurationController.cs	2011-06-02 22:41:33 +0000
+++ b/StandardPlugins/Server/ConfigurationController.cs	2011-06-23 20:56:05 +0000
@@ -212,134 +212,25 @@ namespace WexInstaller.Plugins
       Initialize(true);
     }
 
-    protected override void ReportConfigStatus(ConfigurationEventArgs e)
-    {
-      string message = String.Empty;
-      int percent = 100 / 11;
-
-      switch (e.Type)
-      {
-        case (ConfigurationEventType.Info):
-          switch (e.Action)
-          {
-            // TODO: use enum instead strings.
-            case "VALID_TEMPLATE":
-              message = Properties.Resources.ServerConfigEventValidTemplateInfo;
-              percent *= 1;
-              break;
-            case "PROCESS_TEMPLATE":
-              percent *= 3;
-              message = Properties.Resources.ServerConfigEventProcessTemplateInfo;
-              break;
-            case "CONFIGURE_SERVICE":
-              percent *= 5;
-              message = Properties.Resources.ServerConfigEventConfigureServiceInfo;
-              break;
-            case "START_SERVICE":
-              percent *= 7;
-              message = Properties.Resources.ServerConfigEventStartServiceInfo;
-              break;
-            case "SECURITY_SETTING":
-              percent *= 9;
-              message = Properties.Resources.ServerConfigEventSecuritySettingsInfo;
-              break;
-            case "FIREWALL_RULE":
-              percent *= 10;
-              message = string.Format(Properties.Resources.ServerConfigFirewallSettingInfo, ServiceName, Port);
-              break;
-          }
-          Logger.LogInformation(message);
-          break;
-
-        case ConfigurationEventType.Success:
-          switch (e.Action)
-          {
-            case "VALID_TEMPLATE":
-              percent *= 2;
-              message = Properties.Resources.ServerConfigEventValidTemplateSuccess;
-              break;
-            case "PROCESS_TEMPLATE":
-              percent *= 4;
-              message = Properties.Resources.ServerConfigEventProcessTemplateSuccess;
-              break;
-            case "CONFIGURE_SERVICE":
-              percent *= 6;
-              message = Properties.Resources.ServerConfigEventConfigureServiceSuccess;
-              break;
-            case "START_SERVICE":
-              percent *= 8;
-              message = Properties.Resources.ServerConfigEventStartServiceSuccess;
-              break;
-            case "SECURITY_SETTING":
-              percent *= 10;
-              message = Properties.Resources.ServerConfigEventSecuritySettingsSuccess;
-              break;
-            case "FIREWALL_RULE":
-              percent *= 11;
-              message = Properties.Resources.ServerConfigFirewallSettingSucceeded;
-              break;
-          }
-          Logger.LogInformation(message);
-          break;
-
-        case ConfigurationEventType.Error:
-          switch (e.Action)
-          {
-            case "VALID_TEMPLATE":
-              message = Properties.Resources.ServerConfigEventValidTemplateError;
-              break;
-            case "PROCESS_TEMPLATE":
-              message = Properties.Resources.ServerConfigEventProcessTemplateError;
-              break;
-            case "CONFIGURE_SERVICE":
-              message = Properties.Resources.ServerConfigEventConfigureServiceError;
-              break;
-            case "START_SERVICE":
-              message = Properties.Resources.ServerConfigEventStartServiceError;
-              break;
-            case "SECURITY_SETTING":
-              message = Properties.Resources.ServerConfigEventSecuritySettingsError;
-              break;
-            case "FIREWALL_RULE":
-              message = Properties.Resources.ServerConfigFirewallSettingFailed;
-              break;
-          }
-          percent *= 11;
-          CurrentState = ConfigState.ConfigurationError;
-          Logger.LogError(message);
-          break;
-
-        case (ConfigurationEventType.Finished):
-          message = Properties.Resources.ServerConfigEventFinished;
-          percent *= 11;
-          CurrentState = ConfigState.ConfigurationComplete;
-          Logger.LogInformation(message);
-          break;
-      };
-      e.Details = message;
-      e.PercentComplete = percent;
-
-      ReportProgress(percent, e);
-    }
-
     private bool ProcessTemplate()
     {
-      ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "VALID_TEMPLATE"));
+      ReportStatus(ConfigurationEventType.Info, Properties.Resources.ServerConfigEventValidTemplateInfo, 9);
+
       if (Template.IsValid)
       {
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Success, "VALID_TEMPLATE"));
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigEventValidTemplateSuccess, 18);
 
         switch (ServerInstallType)
         {
           case ServerInstallationType.Dedicated:
-              Template.ServerType = IniServerType.Dedicated;
-              break;
+            Template.ServerType = IniServerType.Dedicated;
+            break;
           case ServerInstallationType.Developer:
-              Template.ServerType = IniServerType.Developer;
-              break;
+            Template.ServerType = IniServerType.Developer;
+            break;
           case ServerInstallationType.Server:
-              Template.ServerType = IniServerType.Server;
-              break;
+            Template.ServerType = IniServerType.Server;
+            break;
         }
 
         // Set reasonable defaults.
@@ -355,15 +246,15 @@ namespace WexInstaller.Plugins
         if (EnableTCPIP)
           Template.Port = Port.ToString();
 
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "PROCESS_TEMPLATE"));
+        ReportStatus(ConfigurationEventType.Info, Properties.Resources.ServerConfigEventProcessTemplateInfo, 27);
         Template.ProcessTemplate();
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Success, "PROCESS_TEMPLATE"));
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigEventProcessTemplateSuccess, 36);
         processedTemplate = true;
       }
       else
       {
         // Bad Template.  Error.
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Error, "VALID_TEMPLATE"));
+        ReportError(Properties.Resources.ServerConfigEventProcessTemplateError);
 
         processedTemplate = false;
       }
@@ -379,28 +270,28 @@ namespace WexInstaller.Plugins
         bool doUpdate = ScManager.ServiceExists(ServiceName);
 
         // Make sure an existing server uses the new configuration file, then restart it.
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "CONFIGURE_SERVICE"));
+        ReportStatus(ConfigurationEventType.Info, Properties.Resources.ServerConfigEventConfigureServiceInfo, 45);
         if (doUpdate)
           ScManager.Update(ServiceName, String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}",
             Template.BaseDir, Template.ConfigurationFile, ServiceName));
         else
           ScManager.Add(ServiceName, ServiceName,
             String.Format("\"{0}bin\\mysqld\" --defaults-file=\"{1}\" {2}", Template.BaseDir, Template.ConfigurationFile, ServiceName));
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Success, "CONFIGURE_SERVICE"));
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigEventConfigureServiceSuccess, 54);
 
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "START_SERVICE"));
+        ReportStatus(ConfigurationEventType.Info, Properties.Resources.ServerConfigEventStartServiceInfo, 63);
         if (doUpdate)
           ScManager.Restart(ServiceName);
         else
           ScManager.Start(ServiceName);
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Success, "START_SERVICE"));
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigEventStartServiceSuccess, 72);
 
         processedService = true;
       }
       catch
       {
         // Failed to add or start the server
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Error, "CONFIGURE_SERVICE"));
+        ReportError(Properties.Resources.ServerConfigEventConfigureServiceError);
       }
 
       return processedService;
@@ -410,7 +301,7 @@ namespace WexInstaller.Plugins
     {
       try
       {
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "SECURITY_SETTING"));
+        ReportStatus(ConfigurationEventType.Info, Properties.Resources.ServerConfigEventSecuritySettingsInfo, 99);
 
         // Set root password.
         MySqlCommand cmd = new MySqlCommand();
@@ -425,14 +316,14 @@ namespace WexInstaller.Plugins
         cmd.CommandText = "FLUSH PRIVILEGES";
         cmd.ExecuteNonQuery();
         cmd.Connection.Close();
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Success, "SECURITY_SETTING"));
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigEventSecuritySettingsSuccess, 100);
 
         processedSecuritySettings = true;
       }
-      catch (MySqlException)
+      catch (MySqlException e)
       {
         // Failed to set root password.
-        ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Error, "SECURITY_SETTING"));
+        ReportError(string.Format(Properties.Resources.ServerConfigEventSecuritySettingsError, e.Message));
         processedSecuritySettings = false;
       }
 
@@ -504,13 +395,12 @@ namespace WexInstaller.Plugins
       }
       ReportConfigStatus(new ConfigurationEventArgs(eventType, "FIREWALL_RULE"));
       */
-      ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "FIREWALL_RULE"));
+      ReportStatus(ConfigurationEventType.Info, string.Format(Properties.Resources.ServerConfigFirewallSettingInfo, ServiceName, Port), 81);
 
-      ConfigurationEventType eventType = ConfigurationEventType.Error;
-      if ( RunNetShellProcess("add", Port.ToString(), ServiceName))
-        eventType = ConfigurationEventType.Success;
-
-      ReportConfigStatus(new ConfigurationEventArgs(eventType, "FIREWALL_RULE"));
+      if (RunNetShellProcess("add", Port.ToString(), ServiceName))
+        ReportStatus(ConfigurationEventType.Success, Properties.Resources.ServerConfigFirewallSettingSucceeded, 90);
+      else
+        ReportError(Properties.Resources.ServerConfigFirewallSettingSucceeded);
     }
 
     private void RemoveFirewallRule()

=== modified file 'WexInstaller.Core/ProductConfigurationController.cs'
--- a/WexInstaller.Core/ProductConfigurationController.cs	2011-06-23 19:06:57 +0000
+++ b/WexInstaller.Core/ProductConfigurationController.cs	2011-06-23 20:56:05 +0000
@@ -59,7 +59,7 @@ namespace WexInstaller.Core
       if (CurrentState != ConfigState.ConfigurationError)
         CurrentState = ConfigState.ConfigurationComplete;
 
-      ConfigurationEventArgs ce = new ConfigurationEventArgs(ConfigurationEventType.Finished, "CONFIGURE_COMPLETE");
+      ConfigurationEventArgs ce = new ConfigurationEventArgs(ConfigurationEventType.Finished);
       ce.PercentComplete = 100;
       ce.Details = "Product configuration controller finished configuration.";
       OnConfigured(ce);
@@ -68,20 +68,20 @@ namespace WexInstaller.Core
     public virtual void Initialize(bool afterInstallation) { }
     public virtual void PreAction() { }
     public virtual void PostAction() { }
-    protected virtual void ReportConfigStatus(ConfigurationEventArgs args) { }
 
-    protected void ReportStatus(ConfigurationEventType type, string action, string details, int progress)
+    protected void ReportStatus(ConfigurationEventType type, string details, int progress)
     {
-      ConfigurationEventArgs args = new ConfigurationEventArgs(type, action);
+      ConfigurationEventArgs args = new ConfigurationEventArgs(type);
       args.Details = details;
       args.PercentComplete = progress;
-      bgw.ReportProgress(progress, args);
+      if (bgw != null)
+        bgw.ReportProgress(progress, args);
     }
 
-    protected void ReportError(string action, string details)
+    protected void ReportError(string details)
     {
       CurrentState = ConfigState.ConfigurationError;
-      ReportStatus(ConfigurationEventType.Error, action, details, 100);
+      ReportStatus(ConfigurationEventType.Error, details, 100);
     }
 
     public event ConfigurationEventHandler Configured;
@@ -114,16 +114,14 @@ namespace WexInstaller.Core
 
   public class ConfigurationEventArgs : EventArgs
   {
-    public ConfigurationEventArgs(ConfigurationEventType type, string action)
+    public ConfigurationEventArgs(ConfigurationEventType type)
     {
       Type = type;
-      Action = action;
       Details = String.Empty;
       PercentComplete = 0;
     }
 
     public ConfigurationEventType Type { get; set; }
-    public string Action { get; set; }
     public string Details { get; set; }
     public int PercentComplete { get; set; }
   }

Attachment: [text/bzr-bundle] bzr/iggy@mysql.com-20110623205605-y4nmgco2ga4frumc.bundle
Thread
bzr commit into wex-installer-1.0 branch (iggy:519) Bug#61616Iggy Galarza24 Jun