List:Commits« Previous MessageNext Message »
From:Mike Lischke Date:April 4 2011 9:04am
Subject:bzr commit into wex-installer-1.0 branch (mike.lischke:401)
View as plain text  
#At file:///D:/Work/MySQL/installer/ based on revid:mike.lischke@stripped

  401 Mike Lischke	2011-04-04
      Implemented handling of manifest errors (no file, not loadable, invalid xml, no products or catalogs).

    modified:
      WexInstaller.Core/ProductManager.cs
      WexInstaller.Core/Properties/Resources.Designer.cs
      WexInstaller.Core/Properties/Resources.resx
      WexInstaller/Program.cs
=== modified file 'WexInstaller.Core/ProductManager.cs'
=== modified file 'WexInstaller.Core/ProductManager.cs'
--- a/WexInstaller.Core/ProductManager.cs	2011-03-31 13:58:44 +0000
+++ b/WexInstaller.Core/ProductManager.cs	2011-04-04 09:04:40 +0000
@@ -6,9 +6,13 @@
 using System.Threading;
 using System.Xml.Serialization;
 using System.Collections.Generic;
+using System.Windows.Forms;
+using System.Xml;
 
 using MySQL.Utilities.SysUtils;
 
+using WexInstaller.Core.Properties;
+
 namespace WexInstaller.Core
 {
   public delegate void DownloadManifestProgressHandler(object sender, DownloadProgressChangedEventArgs de);
@@ -61,29 +65,53 @@
 
     private static ProductManifest ObjectifyManifest(string fileName)
     {
-      ProductManifest thisManifest = null;
+      ProductManifest result = null;
 
       if (File.Exists(fileName))
       {
         XmlRootAttribute productCategories = new XmlRootAttribute("ProductManifest");
         XmlSerializer s = new XmlSerializer(typeof(ProductManifest));
         TextReader w = new StreamReader(fileName);
-        thisManifest = (ProductManifest)s.Deserialize(w);
-        w.Close();
+        try
+        {
+          result = (ProductManifest)s.Deserialize(w);
+        }
+        catch (Exception e)
+        {
+          Logger.LogError(string.Format("Error during XML parsing of file {0}. The error was:\n\t{1}", fileName, e.ToString()));
+        }
+        finally
+        {
+          w.Close();
+        }
       }
 
-      return thisManifest;
+      return result;
     }
 
-    public static void Load()
+    public static bool Load()
     {
       Logger.LogTrace("ProductManager.Load()");
 
       LoadManifestWithCheckForTemp();
 
-      //TODO: fix this to handle it better
-      if (manifest == null || manifest.ProductCategories == null || manifest.ProductCatalogs == null)
-        throw new InvalidOperationException("Manifest failed to load properly");
+      if (manifest == null)
+      {
+        // No error to log. That happened already in the loader.
+        MessageBox.Show(Resources.ManifestNotLoadableText, Resources.ManifestNotLoadableCaption, MessageBoxButtons.OK,
+          MessageBoxIcon.Error);
+        return false;
+      }
+
+      if (manifest.ProductCategories == null || manifest.ProductCategories.Count == 0 ||
+        manifest.ProductCatalogs == null || manifest.ProductCatalogs.Count == 0)
+      {
+        Logger.LogError("No product categories or catalogs found in the manifest.");
+        MessageBox.Show(Resources.ManifestInvalidText, Resources.ManifestInvalidCaption, MessageBoxButtons.OK,
+          MessageBoxIcon.Error);
+        return false;
+      }
+
       Manifest = manifest;
 
       foreach (ProductCategory pc in manifest.ProductCategories)
@@ -177,6 +205,8 @@
       }
       else
         Logger.LogError("Could not set a default catalog.");
+
+      return true;
     }
 
     public static bool IsNewSetup()
@@ -201,7 +231,9 @@
 
     private static void LoadManifestWithCheckForTemp()
     {
-      // first we need to see if there is any temp manifest file to check
+      Logger.LogInformation("Loading main and temp manifest (if any).");
+
+      // First we need to see if there is any temp manifest file to check.
       ProductManifest tempManifest = ObjectifyManifest(InstallerConfiguration.TempProductsManifest);
       ProductManifest currentManifest = ObjectifyManifest(InstallerConfiguration.ProductsManifest);
 
@@ -313,7 +345,7 @@
 
     private static TimerCallback downloadMonitorCallback = TimedCancel;
 
-    private static Timer downloadMonitor;
+    private static System.Threading.Timer downloadMonitor;
 
     public static void TimedCancel(Object stateInfo)
     {
@@ -339,7 +371,8 @@
       }
 
       wc = new WebClient();
-      downloadMonitor = new Timer(downloadMonitorCallback, null, InstallerConfiguration.UpdateTimeoutMilliseconds, Timeout.Infinite);
+      downloadMonitor = new System.Threading.Timer(downloadMonitorCallback, null,
+        InstallerConfiguration.UpdateTimeoutMilliseconds, Timeout.Infinite);
 
       string updateUrl = InstallerConfiguration.UpdateURLs[UpdateURLIndex].URL;
       Uri updateUri = new Uri(updateUrl);

=== modified file 'WexInstaller.Core/Properties/Resources.Designer.cs'
--- a/WexInstaller.Core/Properties/Resources.Designer.cs	2011-03-25 17:32:28 +0000
+++ b/WexInstaller.Core/Properties/Resources.Designer.cs	2011-04-04 09:04:40 +0000
@@ -130,6 +130,46 @@
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Invalid product manifest.
+        /// </summary>
+        internal static string ManifestInvalidCaption {
+            get {
+                return ResourceManager.GetString("ManifestInvalidCaption", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to The MySQL Installer could not find important product information in the product manifest file. Since this is essential for the work of the application it cannot continue and will close now.
+        ///
+        ///Please contact the MySQL support for help..
+        /// </summary>
+        internal static string ManifestInvalidText {
+            get {
+                return ResourceManager.GetString("ManifestInvalidText", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Could not load the product manifest.
+        /// </summary>
+        internal static string ManifestNotLoadableCaption {
+            get {
+                return ResourceManager.GetString("ManifestNotLoadableCaption", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to The MySQL Installer could not load the product manifest file. This file is essential for the operation of the application, hence it will close now.
+        ///
+        ///Please contact the MySQL support for help..
+        /// </summary>
+        internal static string ManifestNotLoadableText {
+            get {
+                return ResourceManager.GetString("ManifestNotLoadableText", resourceCulture);
+            }
+        }
+        
         internal static System.Drawing.Bitmap Server_Icon {
             get {
                 object obj = ResourceManager.GetObject("Server_Icon", resourceCulture);

=== modified file 'WexInstaller.Core/Properties/Resources.resx'
--- a/WexInstaller.Core/Properties/Resources.resx	2011-03-25 17:32:28 +0000
+++ b/WexInstaller.Core/Properties/Resources.resx	2011-04-04 09:04:40 +0000
@@ -160,8 +160,23 @@
   <data name="Application_Icon24" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\ServerCategoryIcon24.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
-  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <data name="BottomDivider" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\BottomDivider.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
+  <data name="ManifestInvalidCaption" xml:space="preserve">
+    <value>Invalid product manifest</value>
+  </data>
+  <data name="ManifestInvalidText" xml:space="preserve">
+    <value>The MySQL Installer could not find important product information in the product manifest file. Since this is essential for the work of the application it cannot continue and will close now.
+
+Please contact the MySQL support for help.</value>
+  </data>
+  <data name="ManifestNotLoadableCaption" xml:space="preserve">
+    <value>Could not load the product manifest</value>
+  </data>
+  <data name="ManifestNotLoadableText" xml:space="preserve">
+    <value>The MySQL Installer could not load the product manifest file. This file is essential for the operation of the application, hence it will close now.
+
+Please contact the MySQL support for help.</value>
+  </data>
 </root>
\ No newline at end of file

=== modified file 'WexInstaller/Program.cs'
--- a/WexInstaller/Program.cs	2011-03-24 18:44:25 +0000
+++ b/WexInstaller/Program.cs	2011-04-04 09:04:40 +0000
@@ -28,7 +28,11 @@
       }
 
       Logger.LogInformation("Loading product manifest");
-      ProductManager.Load();
+      if (!ProductManager.Load())
+      {
+        Logger.LogError("Product manifest loading failed. Exiting now.");
+        Environment.Exit(-1);
+      }
 
       Application.Run(new MainForm());
 


Attachment: [text/bzr-bundle] bzr/mike.lischke@oracle.com-20110404090440-en70vw6uq0j5d20l.bundle
Thread
bzr commit into wex-installer-1.0 branch (mike.lischke:401) Mike Lischke4 Apr