[mapguide-commits] r8078 - in trunk/Tools/Maestro: Maestro.Base Maestro.Base/Commands Maestro.Base/UI Maestro.Editors Maestro.Editors/Diff OSGeo.MapGuide.MaestroAPI/Resource/Comparison

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Apr 27 07:56:36 PDT 2014


Author: jng
Date: 2014-04-27 07:56:35 -0700 (Sun, 27 Apr 2014)
New Revision: 8078

Added:
   trunk/Tools/Maestro/Maestro.Editors/Diff/XmlCompareUtil.cs
Removed:
   trunk/Tools/Maestro/Maestro.Base/Util/
Modified:
   trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs
   trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/Comparison/TextFile.cs
Log:
Refactor the XML content comparison preparation code

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs	2014-04-27 14:23:32 UTC (rev 8077)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs	2014-04-27 14:56:35 UTC (rev 8078)
@@ -28,7 +28,6 @@
 using Maestro.Shared.UI;
 using OSGeo.MapGuide.MaestroAPI.Resource.Comparison;
 using System.Xml;
-using Maestro.Base.Util;
 
 namespace Maestro.Base.Commands
 {
@@ -49,13 +48,11 @@
             try
             {
                 edSvc.SyncSessionCopy();
-                XmlCompareUtil.PrepareForComparison(edSvc.ResourceService,
-                                                    edSvc.ResourceID,
-                                                    edSvc.EditedResourceID,
-                                                    out sourceFile,
-                                                    out targetFile);
-                sLF = new TextFileDiffList(sourceFile);
-                dLF = new TextFileDiffList(targetFile);
+                var set = XmlCompareUtil.PrepareForComparison(edSvc.ResourceService,
+                                                              edSvc.ResourceID,
+                                                              edSvc.EditedResourceID);
+                sLF = set.Source;
+                dLF = set.Target;
             }
             catch (Exception ex)
             {

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2014-04-27 14:23:32 UTC (rev 8077)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2014-04-27 14:56:35 UTC (rev 8078)
@@ -441,7 +441,6 @@
       <DependentUpon>ValidationResultsDialog.cs</DependentUpon>
     </Compile>
     <Compile Include="MaestroPaths.cs" />
-    <Compile Include="Util\XmlCompareUtil.cs" />
     <Compile Include="Workbench.cs">
       <SubType>Form</SubType>
     </Compile>

Modified: trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs	2014-04-27 14:23:32 UTC (rev 8077)
+++ trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs	2014-04-27 14:56:35 UTC (rev 8078)
@@ -31,7 +31,6 @@
 using Maestro.Editors.Diff;
 using Maestro.Shared.UI;
 using System.IO;
-using Maestro.Base.Util;
 
 namespace Maestro.Base.UI
 {
@@ -70,13 +69,11 @@
             try
             {
                 _edSvc.SyncSessionCopy();
-                XmlCompareUtil.PrepareForComparison(_edSvc.ResourceService,
-                                                    _edSvc.ResourceID,
-                                                    _edSvc.EditedResourceID,
-                                                    out sourceFile,
-                                                    out targetFile);
-                sLF = new TextFileDiffList(sourceFile);
-                dLF = new TextFileDiffList(targetFile);
+                var set = XmlCompareUtil.PrepareForComparison(_edSvc.ResourceService,
+                                                              _edSvc.ResourceID,
+                                                              _edSvc.EditedResourceID);
+                sLF = set.Source;
+                dLF = set.Target;
             }
             catch (Exception ex)
             {

Added: trunk/Tools/Maestro/Maestro.Editors/Diff/XmlCompareUtil.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Diff/XmlCompareUtil.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Diff/XmlCompareUtil.cs	2014-04-27 14:56:35 UTC (rev 8078)
@@ -0,0 +1,81 @@
+#region Disclaimer / License
+// Copyright (C) 2014, 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 OSGeo.MapGuide.MaestroAPI.Resource.Comparison;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Xml;
+
+namespace Maestro.Editors.Diff
+{
+    public class XmlComparisonSet
+    {
+        internal XmlComparisonSet(TextFileDiffList source, TextFileDiffList target)
+        {
+            this.Source = source;
+            this.Target = target;
+        }
+
+        public TextFileDiffList Source { get; private set; }
+
+        public TextFileDiffList Target { get; private set; }
+    }
+
+    public class XmlCompareUtil
+    {
+        /// <summary>
+        /// Prepares the source and target resource content for XML comparison
+        /// </summary>
+        /// <param name="resSvc"></param>
+        /// <param name="sourceId"></param>
+        /// <param name="targetId"></param>
+        public static XmlComparisonSet PrepareForComparison(IResourceService resSvc, string sourceId, string targetId)
+        {
+            //Route both source and target XML content through
+            //XmlDocument objects to ensure issues like whitespacing do
+            //not throw us off
+            var sourceFile = Path.GetTempFileName();
+            var targetFile = Path.GetTempFileName();
+            using (var sourceStream = resSvc.GetResourceXmlData(sourceId))
+            using (var targetStream = resSvc.GetResourceXmlData(targetId))
+            {
+                var sourceDoc = new XmlDocument();
+                var targetDoc = new XmlDocument();
+
+                sourceDoc.Load(sourceStream);
+                targetDoc.Load(targetStream);
+
+                using (var fs = File.OpenWrite(sourceFile))
+                using (var ft = File.OpenWrite(targetFile))
+                {
+                    sourceDoc.Save(fs);
+                    targetDoc.Save(ft);
+                }
+
+                return new XmlComparisonSet(
+                    new TextFileDiffList(sourceFile, true),
+                    new TextFileDiffList(targetFile, true));
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2014-04-27 14:23:32 UTC (rev 8077)
+++ trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2014-04-27 14:56:35 UTC (rev 8078)
@@ -214,6 +214,7 @@
     <Compile Include="Diff\TextDiffView.Designer.cs">
       <DependentUpon>TextDiffView.cs</DependentUpon>
     </Compile>
+    <Compile Include="Diff\XmlCompareUtil.cs" />
     <Compile Include="DrawingSource\DrawingSourceEditorCtrl.cs">
       <SubType>UserControl</SubType>
     </Compile>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/Comparison/TextFile.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/Comparison/TextFile.cs	2014-04-27 14:23:32 UTC (rev 8077)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Resource/Comparison/TextFile.cs	2014-04-27 14:56:35 UTC (rev 8078)
@@ -74,7 +74,17 @@
         /// </summary>
         /// <param name="fileName"></param>
         public TextFileDiffList(string fileName)
+            : this(fileName, false)
         {
+        }
+
+        /// <summary>
+        /// Creates a new instance
+        /// </summary>
+        /// <param name="fileName"></param>
+        /// <param name="deleteFile"></param>
+        public TextFileDiffList(string fileName, bool deleteFile)
+        {
             _lines = new List<TextLine>();
             using (StreamReader sr = new StreamReader(fileName))
             {
@@ -86,6 +96,14 @@
                     _lines.Add(new TextLine(line));
                 }
             }
+            if (deleteFile)
+            {
+                try
+                {
+                    File.Delete(fileName);
+                }
+                catch { }
+            }
         }
         #region IDiffList Members
         /// <summary>



More information about the mapguide-commits mailing list