[mapguide-commits] r7026 - in trunk/Tools/Maestro: Maestro Maestro.AddIn.Scripting Maestro.AddIn.Scripting/Services Maestro.Base Maestro.Base/Commands/Test Maestro.Base/Editor Maestro.Editors Maestro.Editors/Common

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Sep 18 05:21:25 PDT 2012


Author: jng
Date: 2012-09-18 05:21:25 -0700 (Tue, 18 Sep 2012)
New Revision: 7026

Added:
   trunk/Tools/Maestro/Maestro.Base/Commands/Test/TriggerDbXmlCommand.cs
   trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.cs
   trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.resx
Modified:
   trunk/Tools/Maestro/Maestro.AddIn.Scripting/Maestro.AddIn.Scripting.csproj
   trunk/Tools/Maestro/Maestro.AddIn.Scripting/Services/ScriptingClasses.cs
   trunk/Tools/Maestro/Maestro.Base/Editor/XmlEditor.cs
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
   trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs
   trunk/Tools/Maestro/Maestro/Program.cs
Log:
#2123: Add a new XmlContentErrorDialog class to process and display XML content errors. Add a test command to ensure this dialog is invoked for the correct exceptions.

Modified: trunk/Tools/Maestro/Maestro/Program.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/Program.cs	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro/Program.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -34,6 +34,7 @@
 using Maestro.Shared.UI;
 using OSGeo.MapGuide.MaestroAPI;
 using OSGeo.MapGuide.MaestroAPI.Resource.Validation;
+using Maestro.Editors.Common;
 
 namespace Maestro
 {
@@ -167,7 +168,14 @@
             var ex = e.ExceptionObject as Exception;
             if (ex != null)
             {
-                ErrorDialog.Show(ex);
+                if (XmlContentErrorDialog.IsDbXmlError(ex) && XmlContentErrorDialog.HasOriginalXml(ex))
+                {
+                    XmlContentErrorDialog.Show(ex);
+                }
+                else
+                {
+                    ErrorDialog.Show(ex);
+                }
             }
         }
 
@@ -178,7 +186,15 @@
 
         static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
         {
-            ErrorDialog.Show(e.Exception);
+            var ex = e.Exception;
+            if (XmlContentErrorDialog.IsDbXmlError(ex) && XmlContentErrorDialog.HasOriginalXml(ex))
+            {
+                XmlContentErrorDialog.Show(ex);
+            }
+            else
+            {
+                ErrorDialog.Show(ex);
+            }
         }
     }
 

Modified: trunk/Tools/Maestro/Maestro.AddIn.Scripting/Maestro.AddIn.Scripting.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.AddIn.Scripting/Maestro.AddIn.Scripting.csproj	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.AddIn.Scripting/Maestro.AddIn.Scripting.csproj	2012-09-18 12:21:25 UTC (rev 7026)
@@ -117,6 +117,11 @@
       <Name>Maestro.Base</Name>
       <Private>False</Private>
     </ProjectReference>
+    <ProjectReference Include="..\Maestro.Editors\Maestro.Editors.csproj">
+      <Project>{5ad2cdba-952e-4148-98a1-31d2e0d540d5}</Project>
+      <Name>Maestro.Editors</Name>
+      <Private>False</Private>
+    </ProjectReference>
     <ProjectReference Include="..\Maestro.Shared.UI\Maestro.Shared.UI.csproj">
       <Project>{CFD19053-2172-41D3-8460-0FD2123A1E88}</Project>
       <Name>Maestro.Shared.UI</Name>

Modified: trunk/Tools/Maestro/Maestro.AddIn.Scripting/Services/ScriptingClasses.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.AddIn.Scripting/Services/ScriptingClasses.cs	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.AddIn.Scripting/Services/ScriptingClasses.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -27,6 +27,7 @@
 using Maestro.Base;
 using Maestro.Base.Services;
 using System.IO;
+using Maestro.Editors.Common;
 
 namespace Maestro.AddIn.Scripting.Services
 {
@@ -84,10 +85,17 @@
         /// <param name="xml"></param>
         public void SetResourceXml(IServerConnection conn, string resourceId, string xml)
         {
-            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+            try
             {
-                conn.ResourceService.SetResourceXmlData(resourceId, ms);
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    conn.ResourceService.SetResourceXmlData(resourceId, ms);
+                }
             }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
         }
 
         /// <summary>

Added: trunk/Tools/Maestro/Maestro.Base/Commands/Test/TriggerDbXmlCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/Test/TriggerDbXmlCommand.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/Test/TriggerDbXmlCommand.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -0,0 +1,58 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using ICSharpCode.Core;
+using Maestro.Base.Services;
+using Maestro.Editors.Common;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Maestro.Base.Commands.Test
+{
+    public class TriggerDbXmlCommand : AbstractMenuCommand
+    {
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            var exp = wb.ActiveSiteExplorer;
+            var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+            var conn = mgr.GetConnection(exp.ConnectionName);
+
+            string xml = 
+                "<FeatureSource xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:noNamespaceSchemaLocation=\"FeatureSource-1.0.0.xsd\">\n" + 
+                "<Foo />\n" +
+                "</FeatureSource>";
+            try
+            {
+                string resId = "Session:" + conn.SessionID + "//Dummy.FeatureSource";
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    conn.ResourceService.SetResourceXmlData(resId, ms);
+                }
+            }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Base/Editor/XmlEditor.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Editor/XmlEditor.cs	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.Base/Editor/XmlEditor.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -36,6 +36,7 @@
 using System.Xml.Schema;
 using Maestro.Base.UI.Preferences;
 using Maestro.Base.Services;
+using Maestro.Editors.Common;
 
 namespace Maestro.Base.Editor
 {
@@ -141,7 +142,18 @@
         {
             //Save the current resource to another session copy
             string resId = "Session:" + this.EditorService.SessionID + "//" + Guid.NewGuid() + "." + this.Resource.ResourceType.ToString(); //NOXLATE
-            this.EditorService.ResourceService.SetResourceXmlData(resId, new MemoryStream(Encoding.UTF8.GetBytes(this.XmlContent)));
+            string xml = this.XmlContent;
+            try
+            {
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    this.EditorService.ResourceService.SetResourceXmlData(resId, ms);
+                }
+            }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
 
             //Copy any resource data
             var previewCopy = this.EditorService.ResourceService.GetResource(resId);
@@ -156,7 +168,18 @@
         public override void SyncSessionCopy()
         {
             //Write our XML changes back into the edited resource copy and re-read
-            _edSvc.ResourceService.SetResourceXmlData(_edSvc.EditedResourceID, new MemoryStream(Encoding.UTF8.GetBytes(this.XmlContent)));
+            string xml = this.XmlContent;
+            try
+            {
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    _edSvc.ResourceService.SetResourceXmlData(_edSvc.EditedResourceID, ms);
+                }
+            }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
             //base.SyncSessionCopy();
         }
 

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2012-09-18 12:21:25 UTC (rev 7026)
@@ -168,6 +168,9 @@
                 <MenuItem id="Menu_Test_SaveResource"
                           label="Save Resource"
                           class="Maestro.Base.Commands.Test.SaveResourceCommand" />
+                <MenuItem id="Menu_Test_TriggerDbXml"
+                          label="Trigger MgDbXmlException"
+                          class="Maestro.Base.Commands.Test.TriggerDbXmlCommand" />
                 <MenuItem id="Menu_Test_SaveResourceWithFilter"
                           label="Save Resource (with filter)"
                           class="Maestro.Base.Commands.Test.SaveResourceWithFilterCommand" />

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2012-09-18 12:21:25 UTC (rev 7026)
@@ -138,6 +138,7 @@
     <Compile Include="Commands\Test\OpenUnmanagedResourceCommand.cs" />
     <Compile Include="Commands\Test\SelectFdoProviderCommand.cs" />
     <Compile Include="Commands\Test\TestCommands.cs" />
+    <Compile Include="Commands\Test\TriggerDbXmlCommand.cs" />
     <Compile Include="Commands\TipOfTheDayCommand.cs" />
     <Compile Include="Commands\TranslateLayoutCommand.cs" />
     <Compile Include="Commands\UserGuideCommand.cs" />

Added: trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.Designer.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.Designer.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -0,0 +1,116 @@
+namespace Maestro.Editors.Common
+{
+    partial class XmlContentErrorDialog
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(XmlContentErrorDialog));
+            this.label1 = new System.Windows.Forms.Label();
+            this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.txtErrorDetails = new System.Windows.Forms.TextBox();
+            this.groupBox2 = new System.Windows.Forms.GroupBox();
+            this.txtXmlContent = new ICSharpCode.TextEditor.TextEditorControl();
+            this.btnSave = new System.Windows.Forms.Button();
+            this.btnClose = new System.Windows.Forms.Button();
+            this.groupBox1.SuspendLayout();
+            this.groupBox2.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // label1
+            // 
+            resources.ApplyResources(this.label1, "label1");
+            this.label1.Name = "label1";
+            // 
+            // groupBox1
+            // 
+            this.groupBox1.Controls.Add(this.txtErrorDetails);
+            resources.ApplyResources(this.groupBox1, "groupBox1");
+            this.groupBox1.Name = "groupBox1";
+            this.groupBox1.TabStop = false;
+            // 
+            // txtErrorDetails
+            // 
+            resources.ApplyResources(this.txtErrorDetails, "txtErrorDetails");
+            this.txtErrorDetails.Name = "txtErrorDetails";
+            this.txtErrorDetails.ReadOnly = true;
+            // 
+            // groupBox2
+            // 
+            this.groupBox2.Controls.Add(this.txtXmlContent);
+            resources.ApplyResources(this.groupBox2, "groupBox2");
+            this.groupBox2.Name = "groupBox2";
+            this.groupBox2.TabStop = false;
+            // 
+            // txtXmlContent
+            // 
+            resources.ApplyResources(this.txtXmlContent, "txtXmlContent");
+            this.txtXmlContent.IsReadOnly = false;
+            this.txtXmlContent.Name = "txtXmlContent";
+            // 
+            // btnSave
+            // 
+            resources.ApplyResources(this.btnSave, "btnSave");
+            this.btnSave.Name = "btnSave";
+            this.btnSave.UseVisualStyleBackColor = true;
+            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
+            // 
+            // btnClose
+            // 
+            resources.ApplyResources(this.btnClose, "btnClose");
+            this.btnClose.Name = "btnClose";
+            this.btnClose.UseVisualStyleBackColor = true;
+            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
+            // 
+            // XmlContentErrorDialog
+            // 
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
+            resources.ApplyResources(this, "$this");
+            this.Controls.Add(this.btnClose);
+            this.Controls.Add(this.btnSave);
+            this.Controls.Add(this.groupBox2);
+            this.Controls.Add(this.groupBox1);
+            this.Controls.Add(this.label1);
+            this.Name = "XmlContentErrorDialog";
+            this.groupBox1.ResumeLayout(false);
+            this.groupBox1.PerformLayout();
+            this.groupBox2.ResumeLayout(false);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.GroupBox groupBox1;
+        private System.Windows.Forms.GroupBox groupBox2;
+        private ICSharpCode.TextEditor.TextEditorControl txtXmlContent;
+        private System.Windows.Forms.Button btnSave;
+        private System.Windows.Forms.Button btnClose;
+        private System.Windows.Forms.TextBox txtErrorDetails;
+    }
+}
\ No newline at end of file

Added: trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -0,0 +1,132 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Maestro.Editors.Common
+{
+    /// <summary>
+    /// A specialized error dialog for XML content errors
+    /// </summary>
+    public partial class XmlContentErrorDialog : Form
+    {
+        const string EXCEPTION_KEY = "XmlError"; //NOXLATE
+
+        private XmlContentErrorDialog()
+        {
+            InitializeComponent();
+            txtXmlContent.SetHighlighting("XML"); //NOXLATE
+        }
+
+        /// <summary>
+        /// Checks if the given exception is XML related and if so will either
+        /// display the error dialog, or attach the 
+        /// </summary>
+        /// <param name="ex"></param>
+        /// <param name="bDisplay"></param>
+        public static void CheckAndHandle(Exception ex, string origXml, bool bDisplay)
+        {
+            if (IsDbXmlError(ex))
+            {
+                ex.Data[EXCEPTION_KEY] = origXml;
+                if (bDisplay)
+                    Show(ex);
+                else
+                    throw ex;
+            }
+            else
+            {
+                throw ex;
+            }
+        }
+
+        /// <summary>
+        /// Gets whether the thrown exception is related to DBXML
+        /// </summary>
+        /// <param name="ex"></param>
+        /// <returns></returns>
+        public static bool IsDbXmlError(Exception ex)
+        {
+            return ex.Message.Contains("MgDbXmlException") || ex.Message.Contains("MgXmlParserException"); //NOXLATE
+        }
+
+        /// <summary>
+        /// Gets whether the given exception has original xml content attached
+        /// </summary>
+        /// <param name="ex"></param>
+        /// <returns></returns>
+        public static bool HasOriginalXml(Exception ex)
+        {
+            return ex.Data[EXCEPTION_KEY] != null;
+        }
+
+        private Exception _ex;
+
+        /// <summary>
+        /// Displays this dialog
+        /// </summary>
+        /// <param name="ex"></param>
+        /// <param name="origXmlContent"></param>
+        public static void Show(Exception ex)
+        {
+            Check.NotNull(ex, "ex"); //NOXLATE
+            Check.NotNull(ex.Data[EXCEPTION_KEY], "ex.Data[EXCEPTION_KEY]"); //NOXLATE
+            string origXmlContent = ex.Data[EXCEPTION_KEY].ToString();
+            var diag = new XmlContentErrorDialog();
+            diag._ex = ex;
+            diag.txtErrorDetails.Text = ex.ToString();
+            diag.txtXmlContent.Text = origXmlContent;
+            diag.txtXmlContent.IsReadOnly = true;
+            diag.ShowDialog();
+        }
+
+        private void btnClose_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+
+        private void btnSave_Click(object sender, EventArgs e)
+        {
+            using (var diag = DialogFactory.SaveFile())
+            {
+                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    using (var sw = new StreamWriter(diag.FileName, false))
+                    {
+                        sw.WriteLine("========== ERROR DETAILS =========\n"); //NOXLATE
+                        sw.WriteLine(_ex.ToString());
+                        sw.WriteLine("\n========== XML CONTENT ==========\n\n"); //NOXLATE
+                        sw.WriteLine(txtXmlContent.Text);
+                        sw.Close();
+                    }
+                }
+            }
+        }
+    }
+}

Added: trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.resx	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Common/XmlContentErrorDialog.resx	2012-09-18 12:21:25 UTC (rev 7026)
@@ -0,0 +1,366 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="label1.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="label1.Location" type="System.Drawing.Point, System.Drawing">
+    <value>12, 9</value>
+  </data>
+  <data name="label1.Size" type="System.Drawing.Size, System.Drawing">
+    <value>217, 13</value>
+  </data>
+  <data name="label1.TabIndex" type="System.Int32, mscorlib">
+    <value>0</value>
+  </data>
+  <data name="label1.Text" xml:space="preserve">
+    <value>An error relating to XML processing occurred</value>
+  </data>
+  <data name=">>label1.Name" xml:space="preserve">
+    <value>label1</value>
+  </data>
+  <data name=">>label1.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>label1.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>label1.ZOrder" xml:space="preserve">
+    <value>4</value>
+  </data>
+  <data name=">>txtErrorDetails.Name" xml:space="preserve">
+    <value>txtErrorDetails</value>
+  </data>
+  <data name=">>txtErrorDetails.Type" xml:space="preserve">
+    <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>txtErrorDetails.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>txtErrorDetails.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing">
+    <value>15, 35</value>
+  </data>
+  <data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
+    <value>536, 112</value>
+  </data>
+  <data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
+    <value>1</value>
+  </data>
+  <data name="groupBox1.Text" xml:space="preserve">
+    <value>Error Details</value>
+  </data>
+  <data name=">>groupBox1.Name" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>groupBox1.Type" xml:space="preserve">
+    <value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>groupBox1.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>groupBox1.ZOrder" xml:space="preserve">
+    <value>3</value>
+  </data>
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="txtErrorDetails.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
+    <value>Fill</value>
+  </data>
+  <data name="txtErrorDetails.Location" type="System.Drawing.Point, System.Drawing">
+    <value>3, 16</value>
+  </data>
+  <data name="txtErrorDetails.Multiline" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <data name="txtErrorDetails.ScrollBars" type="System.Windows.Forms.ScrollBars, System.Windows.Forms">
+    <value>Both</value>
+  </data>
+  <data name="txtErrorDetails.Size" type="System.Drawing.Size, System.Drawing">
+    <value>530, 93</value>
+  </data>
+  <data name="txtErrorDetails.TabIndex" type="System.Int32, mscorlib">
+    <value>0</value>
+  </data>
+  <data name=">>txtErrorDetails.Name" xml:space="preserve">
+    <value>txtErrorDetails</value>
+  </data>
+  <data name=">>txtErrorDetails.Type" xml:space="preserve">
+    <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>txtErrorDetails.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>txtErrorDetails.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <data name=">>txtXmlContent.Name" xml:space="preserve">
+    <value>txtXmlContent</value>
+  </data>
+  <data name=">>txtXmlContent.Type" xml:space="preserve">
+    <value>ICSharpCode.TextEditor.TextEditorControl, ICSharpCode.TextEditor, Version=4.2.0.8783, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a</value>
+  </data>
+  <data name=">>txtXmlContent.Parent" xml:space="preserve">
+    <value>groupBox2</value>
+  </data>
+  <data name=">>txtXmlContent.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <data name="groupBox2.Location" type="System.Drawing.Point, System.Drawing">
+    <value>15, 154</value>
+  </data>
+  <data name="groupBox2.Size" type="System.Drawing.Size, System.Drawing">
+    <value>536, 258</value>
+  </data>
+  <data name="groupBox2.TabIndex" type="System.Int32, mscorlib">
+    <value>2</value>
+  </data>
+  <data name="groupBox2.Text" xml:space="preserve">
+    <value>XML Content</value>
+  </data>
+  <data name=">>groupBox2.Name" xml:space="preserve">
+    <value>groupBox2</value>
+  </data>
+  <data name=">>groupBox2.Type" xml:space="preserve">
+    <value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>groupBox2.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>groupBox2.ZOrder" xml:space="preserve">
+    <value>2</value>
+  </data>
+  <data name="txtXmlContent.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
+    <value>Fill</value>
+  </data>
+  <data name="txtXmlContent.Location" type="System.Drawing.Point, System.Drawing">
+    <value>3, 16</value>
+  </data>
+  <data name="txtXmlContent.Size" type="System.Drawing.Size, System.Drawing">
+    <value>530, 239</value>
+  </data>
+  <data name="txtXmlContent.TabIndex" type="System.Int32, mscorlib">
+    <value>0</value>
+  </data>
+  <data name=">>txtXmlContent.Name" xml:space="preserve">
+    <value>txtXmlContent</value>
+  </data>
+  <data name=">>txtXmlContent.Type" xml:space="preserve">
+    <value>ICSharpCode.TextEditor.TextEditorControl, ICSharpCode.TextEditor, Version=4.2.0.8783, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a</value>
+  </data>
+  <data name=">>txtXmlContent.Parent" xml:space="preserve">
+    <value>groupBox2</value>
+  </data>
+  <data name=">>txtXmlContent.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <data name="btnSave.Location" type="System.Drawing.Point, System.Drawing">
+    <value>15, 422</value>
+  </data>
+  <data name="btnSave.Size" type="System.Drawing.Size, System.Drawing">
+    <value>75, 23</value>
+  </data>
+  <data name="btnSave.TabIndex" type="System.Int32, mscorlib">
+    <value>3</value>
+  </data>
+  <data name="btnSave.Text" xml:space="preserve">
+    <value>Save to File</value>
+  </data>
+  <data name=">>btnSave.Name" xml:space="preserve">
+    <value>btnSave</value>
+  </data>
+  <data name=">>btnSave.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnSave.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnSave.ZOrder" xml:space="preserve">
+    <value>1</value>
+  </data>
+  <data name="btnClose.Location" type="System.Drawing.Point, System.Drawing">
+    <value>473, 422</value>
+  </data>
+  <data name="btnClose.Size" type="System.Drawing.Size, System.Drawing">
+    <value>75, 23</value>
+  </data>
+  <data name="btnClose.TabIndex" type="System.Int32, mscorlib">
+    <value>4</value>
+  </data>
+  <data name="btnClose.Text" xml:space="preserve">
+    <value>Close</value>
+  </data>
+  <data name=">>btnClose.Name" xml:space="preserve">
+    <value>btnClose</value>
+  </data>
+  <data name=">>btnClose.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnClose.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnClose.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
+    <value>563, 457</value>
+  </data>
+  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        AAABAAEAEBAAAAAAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAA
+        AAD///8BAAAAAwAAAA0AAAAXAAAAGwAAABsAAAAbAAAAGwAAABsAAAAbAAAAGwAAABsAAAAXAAAADQAA
+        AAP///8B////AQAAAAUAAAAXAAAAKwAAGkMAAESBAABaqwAAXcUAAF3FAABaqwAARIEAABpDAAAALQAA
+        ABkAAAAF////Af///wH///8B////AQAAU00CAnS/CAid4w4OxPUREdT9ERHU/Q4OxPUICJ3jAgJ0vwAA
+        U03///8B////Af///wH///8B////AQAAf00EBIjNEhLE9xIStv8REdH/ERHR/xER0f8REdH/ERG2/w8P
+        wvcDA4jNAAB/Tf///wH///8B////AQAAhRsDA4q/GBjB9xISsv/c3Nz/ERGy/xERyP8REcj/ERGy/+7u
+        7v8REbL/Dw+89wICib8AAIUb////Af///wEAAIltFhaq4xYWwf/R0dH/1tbW/9zc3P8REa3/ERGt/+rq
+        6v/u7u7/7u7u/xERvv8JCaHjAACJbf///wH///8BAACNpy4uwPUSErT/ERG0/9HR0f/W1tb/3Nzc/+Li
+        4v/m5ub/6urq/xERtP8REbT/EhKv9QAAjaf///8B////AQAAksVERM39Jia1/xQUq/8REar/0dHR/9bW
+        1v/c3Nz/4uLi/xERqv8REar/ERGq/xgYr/0AAJLF////Af///wEAAJbFSUnR/TMzu/8uLrj/ExOf/87O
+        zv/R0dH/1tbW/9zc3P8REZ7/ERGh/xERof8dHaz9AACWxf///wH///8BAACap0dH0/U3N7//IyOr////
+        ///39/f/6Ojo/97e3v/b29v/3d3d/xERm/8WFqD/Jye09QAAmqf///8B////AQAAnm0yMsbjSUnR////
+        /////////////0JCyv9CQsr/////////////////R0fP/yoqveMAAJ5t////Af///wEAAKEbCAiov1ZW
+        4vdRUdn//////09P1/9PT9f/T0/X/09P1///////UFDY/09P3PcHB6e/AAChG////wH///8B////AQAA
+        pU0QELHNW1vo919f5/9bW+P/W1vj/1tb4/9bW+P/X1/n/1hY5PcPD7DNAAClTf///wH///8B////Af//
+        /wH///8BAACoTQkJrr83N9DjXFzq9Wpq8/1pafL9W1vp9TY2z+MJCa6/AACoTf///wH///8B////Af//
+        /wH///8B////Af///wEAAKkbAACqbQAAqqcAAKrFAACqxQAAqqcAAKptAACpG////wH///8B////Af//
+        /wH///8B////Af///wH///8B////Af///wH///8B////Af///wH///8B////Af///wH///8B////Af//
+        /wH///8BAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA
+        //8AAP//AAD//w==
+</value>
+  </data>
+  <data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
+    <value>CenterParent</value>
+  </data>
+  <data name="$this.Text" xml:space="preserve">
+    <value>XML Content Error</value>
+  </data>
+  <data name=">>$this.Name" xml:space="preserve">
+    <value>XmlContentErrorDialog</value>
+  </data>
+  <data name=">>$this.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+</root>
\ No newline at end of file

Modified: trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2012-09-18 12:21:25 UTC (rev 7026)
@@ -158,6 +158,12 @@
     <Compile Include="Common\UnmanagedFileBrowser.Designer.cs">
       <DependentUpon>UnmanagedFileBrowser.cs</DependentUpon>
     </Compile>
+    <Compile Include="Common\XmlContentErrorDialog.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Common\XmlContentErrorDialog.Designer.cs">
+      <DependentUpon>XmlContentErrorDialog.cs</DependentUpon>
+    </Compile>
     <Compile Include="Diagnostics\FdoCacheViewer.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -1338,6 +1344,9 @@
       <DependentUpon>UnmanagedFileBrowser.cs</DependentUpon>
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="Common\XmlContentErrorDialog.resx">
+      <DependentUpon>XmlContentErrorDialog.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Diagnostics\FdoCacheViewer.resx">
       <DependentUpon>FdoCacheViewer.cs</DependentUpon>
     </EmbeddedResource>

Modified: trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs	2012-09-18 11:17:13 UTC (rev 7025)
+++ trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs	2012-09-18 12:21:25 UTC (rev 7026)
@@ -293,10 +293,17 @@
         /// <param name="xml"></param>
         public void UpdateResourceContent(string xml)
         {
-            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+            try
             {
-                _conn.ResourceService.SetResourceXmlData(this.EditedResourceID, ms);
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    _conn.ResourceService.SetResourceXmlData(this.EditedResourceID, ms);
+                }
             }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
         }
 
         /// <summary>
@@ -428,7 +435,18 @@
         /// </summary>
         public void SyncSessionCopy()
         {
-            this.ResourceService.SetResourceXmlData(_editCopy.ResourceID, _editCopy.SerializeToStream());
+            string xml = _editCopy.Serialize();
+            try
+            {
+                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+                {
+                    this.ResourceService.SetResourceXmlData(_editCopy.ResourceID, ms);
+                }
+            }
+            catch (Exception ex)
+            {
+                XmlContentErrorDialog.CheckAndHandle(ex, xml, false);
+            }
         }
 
         /// <summary>



More information about the mapguide-commits mailing list