[mapguide-commits] r5200 - in sandbox/maestro-3.0: Maestro.ResourceValidation Maestro.ResourceValidation/Properties MaestroAPITests OSGeo.MapGuide.MaestroAPI/ObjectModels OSGeo.MapGuide.MaestroAPI/Resource

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Sep 28 06:03:39 EDT 2010


Author: jng
Date: 2010-09-28 10:03:39 +0000 (Tue, 28 Sep 2010)
New Revision: 5200

Added:
   sandbox/maestro-3.0/Maestro.ResourceValidation/LoadProcedureValidator.cs
Modified:
   sandbox/maestro-3.0/Maestro.ResourceValidation/Maestro.ResourceValidation.csproj
   sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.Designer.cs
   sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.resx
   sandbox/maestro-3.0/Maestro.ResourceValidation/ResourceValidatorLoader.cs
   sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj
   sandbox/maestro-3.0/MaestroAPITests/ValidationTests.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ValidationResultSet.cs
Log:
Add a load procedure validator with unit tests for verification

Added: sandbox/maestro-3.0/Maestro.ResourceValidation/LoadProcedureValidator.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.ResourceValidation/LoadProcedureValidator.cs	                        (rev 0)
+++ sandbox/maestro-3.0/Maestro.ResourceValidation/LoadProcedureValidator.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -0,0 +1,88 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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.Text;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using OSGeo.MapGuide.ObjectModels.LoadProcedure;
+
+namespace Maestro.ResourceValidation
+{
+    public class LoadProcedureValidator : IResourceValidator
+    {
+        public ResourceTypeDescriptor SupportedResourceAndVersion
+        {
+            get { return new ResourceTypeDescriptor(OSGeo.MapGuide.MaestroAPI.ResourceTypes.LoadProcedure, "1.0.0"); }
+        }
+
+        public ValidationIssue[] Validate(IResource resource, bool recurse)
+        {
+            if (resource.ResourceType != OSGeo.MapGuide.MaestroAPI.ResourceTypes.LoadProcedure)
+                return null;
+
+            if (resource.ResourceVersion != new Version(1, 0, 0))
+                return null;
+
+            var set = new ValidationResultSet();
+
+            var loadProc = (resource as LoadProcedure).Item;
+
+            if (typeof(DwgLoadProcedureType).IsAssignableFrom(loadProc.GetType()))
+            {
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_DWGNotSupported));
+                return set.GetAllIssues(); //all she wrote
+            }
+
+            if (typeof(RasterLoadProcedureType).IsAssignableFrom(loadProc.GetType()))
+            {
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_RasterNotSupported));
+                return set.GetAllIssues(); //all she wrote
+            }
+
+            if (typeof(DwfLoadProcedureType).IsAssignableFrom(loadProc.GetType()))
+            {
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_DWFNotSupported));
+                return set.GetAllIssues(); //all she wrote
+            }
+
+            if (typeof(SdfLoadProcedureType).IsAssignableFrom(loadProc.GetType()))
+            {
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_Sdf2OptionsNotSupported));
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_GeneralizationNotSupported));
+            }
+
+            if (typeof(ShpLoadProcedureType).IsAssignableFrom(loadProc.GetType()))
+            {
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_ConvertToSdf3NotSupported));
+                set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, Properties.Resources.LPROC_GeneralizationNotSupported));
+            }
+
+            foreach (var fn in loadProc.SourceFile)
+            {
+                if (!System.IO.File.Exists(fn))
+                {
+                    set.AddIssue(new ValidationIssue(resource, ValidationStatus.Warning, string.Format(Properties.Resources.LPROC_SourceFileNotFound, fn)));
+                }
+            }
+
+            return set.GetAllIssues();
+        }
+    }
+}

Modified: sandbox/maestro-3.0/Maestro.ResourceValidation/Maestro.ResourceValidation.csproj
===================================================================
--- sandbox/maestro-3.0/Maestro.ResourceValidation/Maestro.ResourceValidation.csproj	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/Maestro.ResourceValidation/Maestro.ResourceValidation.csproj	2010-09-28 10:03:39 UTC (rev 5200)
@@ -39,6 +39,7 @@
     <Compile Include="ApplicationDefinitionValidator.cs" />
     <Compile Include="FeatureSourceValidator.cs" />
     <Compile Include="LayerDefinitionValidator.cs" />
+    <Compile Include="LoadProcedureValidator.cs" />
     <Compile Include="MapDefinitionValidator.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\Resources.Designer.cs">

Modified: sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.Designer.cs	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.Designer.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:2.0.50727.4927
+//     Runtime Version:2.0.50727.4952
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -313,6 +313,69 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Convert to SDF option is not supported by Maestro.
+        /// </summary>
+        internal static string LPROC_ConvertToSdf3NotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_ConvertToSdf3NotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to DWF Load Procedures cannot be executed by Maestro.
+        /// </summary>
+        internal static string LPROC_DWFNotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_DWFNotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to DWG Load Procedures cannot be executed by Maestro.
+        /// </summary>
+        internal static string LPROC_DWGNotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_DWGNotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Generalization of source data is not supported by Maestro.
+        /// </summary>
+        internal static string LPROC_GeneralizationNotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_GeneralizationNotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Raster Load Procedures cannot be executed by Maestro.
+        /// </summary>
+        internal static string LPROC_RasterNotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_RasterNotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to SDF 2 Migration options are not supported by Maestro. Ensure your source files are SDF3 files..
+        /// </summary>
+        internal static string LPROC_Sdf2OptionsNotSupported {
+            get {
+                return ResourceManager.GetString("LPROC_Sdf2OptionsNotSupported", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Source file not found: {0}.
+        /// </summary>
+        internal static string LPROC_SourceFileNotFound {
+            get {
+                return ResourceManager.GetString("LPROC_SourceFileNotFound", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Data from {0} is not visible in the map&apos;s start extent.
         /// </summary>
         internal static string MDF_DataOutsideMapWarning {

Modified: sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.resx	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/Maestro.ResourceValidation/Properties/Resources.resx	2010-09-28 10:03:39 UTC (rev 5200)
@@ -229,6 +229,34 @@
     <value>The layer has no type, or the type is unsupported by Maestro</value>
     <comment>A  warning message that is displayed if the layer type is unknown</comment>
   </data>
+  <data name="LPROC_ConvertToSdf3NotSupported" xml:space="preserve">
+    <value>Convert to SDF option is not supported by Maestro</value>
+    <comment>A warning message about the lack of SDF conversion support</comment>
+  </data>
+  <data name="LPROC_DWFNotSupported" xml:space="preserve">
+    <value>DWF Load Procedures cannot be executed by Maestro</value>
+    <comment>A warning message indicating the lack of DWF support in Maestro</comment>
+  </data>
+  <data name="LPROC_DWGNotSupported" xml:space="preserve">
+    <value>DWG Load Procedures cannot be executed by Maestro</value>
+    <comment>A warning message indicating the lack of DWG support in Maestro</comment>
+  </data>
+  <data name="LPROC_GeneralizationNotSupported" xml:space="preserve">
+    <value>Generalization of source data is not supported by Maestro</value>
+    <comment>A warning message about the lack of Generalization support</comment>
+  </data>
+  <data name="LPROC_RasterNotSupported" xml:space="preserve">
+    <value>Raster Load Procedures cannot be executed by Maestro</value>
+    <comment>A warning message about the lack of Raster support</comment>
+  </data>
+  <data name="LPROC_Sdf2OptionsNotSupported" xml:space="preserve">
+    <value>SDF 2 Migration options are not supported by Maestro. Ensure your source files are SDF3 files.</value>
+    <comment>A warning message about the lack of SDF2 support</comment>
+  </data>
+  <data name="LPROC_SourceFileNotFound" xml:space="preserve">
+    <value>Source file not found: {0}</value>
+    <comment>An error message indicating that a source file in the load procedure does not exist</comment>
+  </data>
   <data name="MDF_DataOutsideMapWarning" xml:space="preserve">
     <value>Data from {0} is not visible in the map's start extent</value>
     <comment>A warning message that is displayed if a layer reports an extent that is outside the map's extent</comment>

Modified: sandbox/maestro-3.0/Maestro.ResourceValidation/ResourceValidatorLoader.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.ResourceValidation/ResourceValidatorLoader.cs	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/Maestro.ResourceValidation/ResourceValidatorLoader.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -41,6 +41,7 @@
             ResourceValidatorSet.RegisterValidator(new MapDefinitionValidator());
             ResourceValidatorSet.RegisterValidator(new WebLayoutValidator());
             ResourceValidatorSet.RegisterValidator(new ApplicationDefinitionValidator());
+            ResourceValidatorSet.RegisterValidator(new LoadProcedureValidator());
 
             m_initialized = true;
         }

Modified: sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj	2010-09-28 10:03:39 UTC (rev 5200)
@@ -60,6 +60,10 @@
     <Compile Include="ValidationTests.cs" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\Maestro.ResourceValidation\Maestro.ResourceValidation.csproj">
+      <Project>{3B29C138-666C-46D0-A55D-824E5192C091}</Project>
+      <Name>Maestro.ResourceValidation</Name>
+    </ProjectReference>
     <ProjectReference Include="..\OSGeo.MapGuide.MaestroAPI.Http\OSGeo.MapGuide.MaestroAPI.Http.csproj">
       <Project>{6EF1E775-444B-4E5F-87FB-D687C43A68D7}</Project>
       <Name>OSGeo.MapGuide.MaestroAPI.Http</Name>

Modified: sandbox/maestro-3.0/MaestroAPITests/ValidationTests.cs
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/ValidationTests.cs	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/MaestroAPITests/ValidationTests.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -24,11 +24,22 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using NMock2;
 
+using LoadProc = OSGeo.MapGuide.ObjectModels.LoadProcedure;
+using OSGeo.MapGuide.MaestroAPI.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI;
+using Maestro.ResourceValidation;
+
 namespace MaestroAPITests
 {
     [TestFixture]
     public class ValidationTests
     {
+        [TestFixtureSetUp]
+        public void FixtureSetup()
+        {
+            ResourceValidatorLoader.LoadStockValidators();
+        }
+
         [Test]
         public void TestUniqueIssues()
         {
@@ -78,5 +89,71 @@
             Assert.AreEqual(totalIssues.Length, 2);
             Assert.AreEqual(set.ResourceIDs.Length, 1);
         }
+
+        [Test]
+        public void TestLoadProcedureValidation()
+        {
+            var id = "Library://Test.LoadProcedure";
+            var mock = new Mockery();
+            var conn = mock.NewMock<IServerConnection>();
+            var lp = ObjectFactory.CreateSdfLoadProcedure(conn, new string[] 
+            {
+                "C:\\foo.sdf",
+                "C:\\bar.sdf"
+            });
+            lp.ResourceID = id;
+
+            var set = new ValidationResultSet();
+            set.AddIssues(ResourceValidatorSet.Validate(lp, false));
+
+            //SDF2, generalization and 2 missing files
+            Assert.AreEqual(4, set.GetAllIssues().Length);
+
+            lp = ObjectFactory.CreateShpLoadProcedure(conn, new string[] 
+            {
+                "C:\\foo.shp",
+                "C:\\bar.shp"
+            });
+            lp.ResourceID = id;
+
+            set = new ValidationResultSet();
+            set.AddIssues(ResourceValidatorSet.Validate(lp, false));
+
+            //SDF3 conversion, generalization and 2 missing files
+            Assert.AreEqual(4, set.GetAllIssues().Length);
+
+            lp = new OSGeo.MapGuide.ObjectModels.LoadProcedure.LoadProcedure()
+            {
+                Item = new OSGeo.MapGuide.ObjectModels.LoadProcedure.DwfLoadProcedureType()
+            };
+            lp.ResourceID = id;
+            set = new ValidationResultSet();
+            set.AddIssues(ResourceValidatorSet.Validate(lp, false));
+
+            //Not supported
+            Assert.AreEqual(1, set.GetAllIssues().Length);
+
+            lp = new OSGeo.MapGuide.ObjectModels.LoadProcedure.LoadProcedure()
+            {
+                Item = new OSGeo.MapGuide.ObjectModels.LoadProcedure.DwgLoadProcedureType()
+            };
+            lp.ResourceID = id;
+            set = new ValidationResultSet();
+            set.AddIssues(ResourceValidatorSet.Validate(lp, false));
+
+            //Not supported
+            Assert.AreEqual(1, set.GetAllIssues().Length);
+
+            lp = new OSGeo.MapGuide.ObjectModels.LoadProcedure.LoadProcedure()
+            {
+                Item = new OSGeo.MapGuide.ObjectModels.LoadProcedure.RasterLoadProcedureType()
+            };
+            lp.ResourceID = id;
+            set = new ValidationResultSet();
+            set.AddIssues(ResourceValidatorSet.Validate(lp, false));
+
+            //Not supported
+            Assert.AreEqual(1, set.GetAllIssues().Length);
+        }
     }
 }

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -45,24 +45,21 @@
     {
         public static LayerDefinition CreateLayerDefinition(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new LayerDefinition() { CurrentConnection = owner };
         }
 
         public static DrawingSource CreateDrawingSource(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new DrawingSource() { CurrentConnection = owner };
         }
 
         public static FeatureSourceType CreateFeatureSource(IServerConnection owner, string provider)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new FeatureSourceType()
             {
@@ -81,8 +78,7 @@
 
         public static MapDefinition CreateMapDefinition(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new MapDefinition() { 
                 CurrentConnection = owner,
@@ -191,8 +187,7 @@
 
         public static WebLayoutType CreateWebLayout(IServerConnection owner, string mapDefinitionId)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             //TODO: Localize these strings. Once localized we can have *translatable*
             //web layouts!
@@ -529,16 +524,14 @@
 
         public static SimpleSymbolDefinition CreateSimpleSymbol(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new SimpleSymbolDefinition() { CurrentConnection = owner };
         }
 
         public static CompoundSymbolDefinition CreateCompoundSymbol(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new CompoundSymbolDefinition() { CurrentConnection = owner };
         }
@@ -550,16 +543,14 @@
 
         public static ApplicationDefinitionType CreateFlexibleLayout(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new ApplicationDefinitionType() { CurrentConnection = owner };
         }
 
         public static PrintLayout CreatePrintLayout(IServerConnection owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             return new PrintLayout() { CurrentConnection = owner };
         }
@@ -568,8 +559,7 @@
 
         public static LoadProcedure CreateSdfLoadProcedure(IServerConnection owner, IEnumerable<string> sdfFiles)
         {
-            if (owner == null)
-                throw new ArgumentNullException("owner");
+            Check.NotNull(owner, "owner");
 
             IList<string> files = new List<string>();
             if (sdfFiles != null)

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ValidationResultSet.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ValidationResultSet.cs	2010-09-28 09:26:53 UTC (rev 5199)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ValidationResultSet.cs	2010-09-28 10:03:39 UTC (rev 5200)
@@ -76,6 +76,9 @@
 
         public void AddIssues(IEnumerable<ValidationIssue> issues)
         {
+            if (issues == null)
+                return;
+
             foreach (var issue in issues)
             {
                 AddIssue(issue);



More information about the mapguide-commits mailing list