[mapguide-commits] r6521 - in trunk/Tools/Maestro/Maestro.Base: .
Commands UI Util
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Sat Feb 18 08:30:05 EST 2012
Author: jng
Date: 2012-02-18 05:30:05 -0800 (Sat, 18 Feb 2012)
New Revision: 6521
Added:
trunk/Tools/Maestro/Maestro.Base/Util/
trunk/Tools/Maestro/Maestro.Base/Util/XmlCompareUtil.cs
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
Log:
#1950: Improve the robustness of the XML diff comparison by routing the source and target XML content through XmlDocument objects to ensure whitespacing does not screw up the diff comparison.
Modified: trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs 2012-02-18 12:32:10 UTC (rev 6520)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/ViewXmlChangesCommand.cs 2012-02-18 13:30:05 UTC (rev 6521)
@@ -27,6 +27,8 @@
using Maestro.Editors.Diff;
using Maestro.Shared.UI;
using OSGeo.MapGuide.MaestroAPI.Resource.Comparison;
+using System.Xml;
+using Maestro.Base.Util;
namespace Maestro.Base.Commands
{
@@ -42,20 +44,18 @@
TextFileDiffList sLF = null;
TextFileDiffList dLF = null;
- string sourceFile = Path.GetTempFileName();
- string targetFile = Path.GetTempFileName();
+ string sourceFile = null;
+ string targetFile = null;
try
{
edSvc.SyncSessionCopy();
- using (var source = new StreamReader(edSvc.ResourceService.GetResourceXmlData(edSvc.ResourceID)))
- using (var target = new StreamReader(edSvc.ResourceService.GetResourceXmlData(edSvc.EditedResourceID)))
- {
- File.WriteAllText(sourceFile, source.ReadToEnd());
- File.WriteAllText(targetFile, target.ReadToEnd());
-
- sLF = new TextFileDiffList(sourceFile);
- dLF = new TextFileDiffList(targetFile);
- }
+ XmlCompareUtil.PrepareForComparison(edSvc.ResourceService,
+ edSvc.ResourceID,
+ edSvc.EditedResourceID,
+ out sourceFile,
+ out targetFile);
+ sLF = new TextFileDiffList(sourceFile);
+ dLF = new TextFileDiffList(targetFile);
}
catch (Exception ex)
{
Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj 2012-02-18 12:32:10 UTC (rev 6520)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj 2012-02-18 13:30:05 UTC (rev 6521)
@@ -418,6 +418,7 @@
<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 2012-02-18 12:32:10 UTC (rev 6520)
+++ trunk/Tools/Maestro/Maestro.Base/UI/DirtyStateConfirmationDialog.cs 2012-02-18 13:30:05 UTC (rev 6521)
@@ -31,6 +31,7 @@
using Maestro.Editors.Diff;
using Maestro.Shared.UI;
using System.IO;
+using Maestro.Base.Util;
namespace Maestro.Base.UI
{
@@ -64,20 +65,18 @@
{
TextFileDiffList sLF = null;
TextFileDiffList dLF = null;
- string sourceFile = Path.GetTempFileName();
- string targetFile = Path.GetTempFileName();
+ string sourceFile = null;
+ string targetFile = null;
try
{
_edSvc.SyncSessionCopy();
- using (var source = new StreamReader(_edSvc.ResourceService.GetResourceXmlData(_edSvc.ResourceID)))
- using (var target = new StreamReader(_edSvc.ResourceService.GetResourceXmlData(_edSvc.EditedResourceID)))
- {
- File.WriteAllText(sourceFile, source.ReadToEnd());
- File.WriteAllText(targetFile, target.ReadToEnd());
-
- sLF = new TextFileDiffList(sourceFile);
- dLF = new TextFileDiffList(targetFile);
- }
+ XmlCompareUtil.PrepareForComparison(_edSvc.ResourceService,
+ _edSvc.ResourceID,
+ _edSvc.EditedResourceID,
+ out sourceFile,
+ out targetFile);
+ sLF = new TextFileDiffList(sourceFile);
+ dLF = new TextFileDiffList(targetFile);
}
catch (Exception ex)
{
Added: trunk/Tools/Maestro/Maestro.Base/Util/XmlCompareUtil.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Util/XmlCompareUtil.cs (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Util/XmlCompareUtil.cs 2012-02-18 13:30:05 UTC (rev 6521)
@@ -0,0 +1,65 @@
+#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 System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using System.Xml;
+using System.IO;
+
+namespace Maestro.Base.Util
+{
+ 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>
+ /// <param name="sourceFile"></param>
+ /// <param name="targetFile"></param>
+ public static void PrepareForComparison(IResourceService resSvc, string sourceId, string targetId, out string sourceFile, out string targetFile)
+ {
+ //Route both source and target XML content through
+ //XmlDocument objects to ensure issues like whitespacing do
+ //not throw us off
+ sourceFile = Path.GetTempFileName();
+ 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);
+ }
+ }
+ }
+ }
+}
More information about the mapguide-commits
mailing list