[mapguide-commits] r5474 - in sandbox/maestro-3.0: Maestro.Base/Editor Maestro.Base/Properties Maestro.Editors/FeatureSource OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Resource/Validation

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Dec 13 07:33:52 EST 2010


Author: jng
Date: 2010-12-13 04:33:52 -0800 (Mon, 13 Dec 2010)
New Revision: 5474

Added:
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/Validation/ResourceValidationContext.cs
Modified:
   sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs
   sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs
   sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
   sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
   sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
   sandbox/maestro-3.0/Maestro.Editors/FeatureSource/ExtensionsCtrl.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
Log:
3.0 sandbox changes:
 - Add missing ResourceValidationContext from previous submission. Oops!
 - Feature Source Editor: Fix remove button not removing selected node if it is an extension
 - #1496: Add warnings when saving resources that may trigger a tile cache invalidation

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/FeatureSourceEditor.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -27,6 +27,7 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using Maestro.Editors;
 using ICSharpCode.Core;
+using OSGeo.MapGuide.ObjectModels.MapDefinition;
 
 namespace Maestro.Base.Editor
 {
@@ -50,5 +51,50 @@
             fsEditorCtrl.Controls.Add(fsOpts);
             fsEditorCtrl.Bind(service);
         }
+
+        protected override void OnBeforeSave(object sender, CancelEventArgs e)
+        {
+            List<string> affectedMapDefinitions = new List<string>();
+            var refs = _edsvc.ResourceService.EnumerateResourceReferences(_edsvc.ResourceID);
+            foreach (var r in refs.ResourceId)
+            {
+                ResourceIdentifier rid = new ResourceIdentifier(r);
+                if (rid.ResourceType == OSGeo.MapGuide.MaestroAPI.ResourceTypes.LayerDefinition)
+                {
+                    var lrefs = _edsvc.ResourceService.EnumerateResourceReferences(r);
+                    foreach (var lr in lrefs.ResourceId)
+                    {
+                        ResourceIdentifier rid2 = new ResourceIdentifier(lr);
+                        if (rid2.ResourceType == OSGeo.MapGuide.MaestroAPI.ResourceTypes.MapDefinition)
+                        {
+                            var mdf = (IMapDefinition)_edsvc.ResourceService.GetResource(lr);
+                            if (mdf.BaseMap != null)
+                            {
+                                foreach (var blg in mdf.BaseMap.BaseMapLayerGroup)
+                                {
+                                    foreach (var bl in blg.BaseMapLayer)
+                                    {
+                                        if (bl.ResourceId.Equals(r))
+                                        {
+                                            affectedMapDefinitions.Add(r);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (affectedMapDefinitions.Count > 0)
+            {
+                if (!MessageService.AskQuestionFormatted(Properties.Resources.Confirm, Properties.Resources.ConfirmBaseMapInvalidationFeatureSourceSave, string.Join(Environment.NewLine, affectedMapDefinitions.ToArray()) + Environment.NewLine))
+                {
+                    e.Cancel = true;
+                    return;
+                }
+            }
+            base.OnBeforeSave(sender, e);
+        }
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/LayerDefinitionEditor.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -32,6 +32,7 @@
 using ICSharpCode.Core;
 using OSGeo.MapGuide.ObjectModels;
 using Maestro.Base.UI.Preferences;
+using OSGeo.MapGuide.ObjectModels.MapDefinition;
 
 namespace Maestro.Base.Editor
 {
@@ -50,7 +51,6 @@
             panelBody.Controls.Clear();
 
             _edsvc = service;
-            _edsvc.BeforeSave += new CancelEventHandler(OnBeforeSave);
             _res = service.GetEditedResource() as ILayerDefinition;
             Debug.Assert(_res != null);
 
@@ -79,5 +79,49 @@
                 throw new NotSupportedException(Properties.Resources.LayerSubTypeNotSupported);
             }
         }
+
+        protected override void OnBeforeSave(object sender, CancelEventArgs e)
+        {
+            if (_edsvc.IsNew)
+            {
+                base.OnBeforeSave(sender, e);
+                return;
+            }
+
+            List<string> affectedMapDefinitions = new List<string>();
+            var refs = _edsvc.ResourceService.EnumerateResourceReferences(_edsvc.ResourceID);
+            foreach (var r in refs.ResourceId)
+            {
+                var resId = new ResourceIdentifier(r);
+                if (resId.ResourceType == OSGeo.MapGuide.MaestroAPI.ResourceTypes.MapDefinition)
+                {
+                    var mdf = (IMapDefinition)_edsvc.ResourceService.GetResource(r);
+                    if (mdf.BaseMap != null)
+                    {
+                        foreach (var blg in mdf.BaseMap.BaseMapLayerGroup)
+                        {
+                            foreach (var bl in blg.BaseMapLayer)
+                            {
+                                if (bl.ResourceId.Equals(_edsvc.ResourceID))
+                                {
+                                    affectedMapDefinitions.Add(r);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (affectedMapDefinitions.Count > 0)
+            {
+                if (!MessageService.AskQuestionFormatted(Properties.Resources.Confirm, Properties.Resources.ConfirmBaseMapInvalidationLayerSave, string.Join(Environment.NewLine, affectedMapDefinitions.ToArray()) + Environment.NewLine))
+                {
+                    e.Cancel = true;
+                    return;
+                }
+            }
+
+            base.OnBeforeSave(sender, e);
+        }
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -27,6 +27,7 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using Maestro.Editors;
 using ICSharpCode.Core;
+using OSGeo.MapGuide.ObjectModels.MapDefinition;
 
 namespace Maestro.Base.Editor
 {
@@ -44,10 +45,33 @@
         {
             _edsvc = service;
             _res = _edsvc.GetEditedResource();
-            _edsvc.BeforeSave += new CancelEventHandler(OnBeforeSave);
             mapEditorCtrl.Bind(service);
         }
 
+        protected override void OnBeforeSave(object sender, CancelEventArgs e)
+        {
+            if (_edsvc.IsNew)
+            {
+                base.OnBeforeSave(sender, e);
+                return;
+            }
+
+            var mdf = (IMapDefinition)_edsvc.GetEditedResource();
+            if (mdf.BaseMap != null)
+            {
+                if (mdf.BaseMap.HasLayers())
+                {
+                    if (!MessageService.AskQuestion(Properties.Resources.ConfirmBaseMapInvalidation))
+                    {
+                        e.Cancel = true;
+                        return;
+                    }
+                }
+            }
+                            
+            base.OnBeforeSave(sender, e);
+        }
+
         public override bool CanProfile
         {
             get

Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -301,6 +301,33 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to This map definition has tiled layers. Saving this map definition will reset the tile cache if these layer existed when you first edited this map. Continue with save?.
+        /// </summary>
+        internal static string ConfirmBaseMapInvalidation {
+            get {
+                return ResourceManager.GetString("ConfirmBaseMapInvalidation", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to This feature source is refrenced by at least one tiled layer in the following maps: {0} Saving this feature source may reset the cached tiles of these maps. Continue with save?.
+        /// </summary>
+        internal static string ConfirmBaseMapInvalidationFeatureSourceSave {
+            get {
+                return ResourceManager.GetString("ConfirmBaseMapInvalidationFeatureSourceSave", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to This layer is used as a tiled layer in the following maps: {0} Saving this layer may reset the cached tiles of these maps. Continue with save?.
+        /// </summary>
+        internal static string ConfirmBaseMapInvalidationLayerSave {
+            get {
+                return ResourceManager.GetString("ConfirmBaseMapInvalidationLayerSave", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to You have open editors with unsaved changes. Continue anyway?.
         /// </summary>
         internal static string ConfirmCloseEditors {

Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx	2010-12-13 12:33:52 UTC (rev 5474)
@@ -823,4 +823,13 @@
   <data name="SiteExplorer_Repoint" xml:space="preserve">
     <value>Repoint this resource</value>
   </data>
+  <data name="ConfirmBaseMapInvalidation" xml:space="preserve">
+    <value>This map definition has tiled layers. Saving this map definition will reset the tile cache if these layer existed when you first edited this map. Continue with save?</value>
+  </data>
+  <data name="ConfirmBaseMapInvalidationFeatureSourceSave" xml:space="preserve">
+    <value>This feature source is refrenced by at least one tiled layer in the following maps: {0} Saving this feature source may reset the cached tiles of these maps. Continue with save?</value>
+  </data>
+  <data name="ConfirmBaseMapInvalidationLayerSave" xml:space="preserve">
+    <value>This layer is used as a tiled layer in the following maps: {0} Saving this layer may reset the cached tiles of these maps. Continue with save?</value>
+  </data>
 </root>
\ No newline at end of file

Modified: sandbox/maestro-3.0/Maestro.Editors/FeatureSource/ExtensionsCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/FeatureSource/ExtensionsCtrl.cs	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/Maestro.Editors/FeatureSource/ExtensionsCtrl.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -281,6 +281,7 @@
                 {
                     _fs.RemoveExtension(ext);
                     OnResourceChanged();
+                    trvExtensions.Nodes.Remove(node);
                 }
                 else if (join != null)
                 {

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-12-13 11:38:21 UTC (rev 5473)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-12-13 12:33:52 UTC (rev 5474)
@@ -278,6 +278,14 @@
     <Compile Include="Resource\Validation\SymbolLibraryValidator.cs" />
     <Compile Include="Resource\Validation\ValidationResultSet.cs" />
     <Compile Include="Resource\Validation\WebLayoutValidator.cs" />
+    <Compile Include="SchemaOverrides\ConfigurationDocument.cs" />
+    <Compile Include="SchemaOverrides\GenericConfigurationDocument.cs" />
+    <Compile Include="SchemaOverrides\OdbcConfigurationDocument.cs" />
+    <Compile Include="SchemaOverrides\RasterConfigurationDocument.cs" />
+    <Compile Include="SchemaOverrides\RasterFileItem.cs" />
+    <Compile Include="SchemaOverrides\RasterItem.cs" />
+    <Compile Include="SchemaOverrides\RasterWmsItem.cs" />
+    <Compile Include="SchemaOverrides\SpatialContextData.cs" />
     <Compile Include="Serialization\Enums.cs" />
     <Compile Include="Serialization\IBinarySerializable.cs" />
     <Compile Include="Serialization\MgBinaryDeserializer.cs" />

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/Validation/ResourceValidationContext.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/Validation/ResourceValidationContext.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/Validation/ResourceValidationContext.cs	2010-12-13 12:33:52 UTC (rev 5474)
@@ -0,0 +1,112 @@
+#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 System.Diagnostics;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.ObjectModels.Common;
+
+namespace OSGeo.MapGuide.MaestroAPI.Resource.Validation
+{
+    /// <summary>
+    /// Provides the means for the resource validation system to avoid validating
+    /// already validated resources
+    /// </summary>
+    public class ResourceValidationContext
+    {
+        private Dictionary<string, string> _validated;
+        private Dictionary<string, IResource> _resources;
+        private Dictionary<string, FeatureSourceDescription> _schemas;
+        private Dictionary<string, FdoSpatialContextList> _spatialContexts;
+
+        private IResourceService _resSvc;
+        private IFeatureService _featSvc;
+
+        public ResourceValidationContext(IResourceService resSvc, IFeatureService featSvc)
+        {
+            _resSvc = resSvc;
+            _featSvc = featSvc;
+            _validated = new Dictionary<string, string>();
+            _resources = new Dictionary<string, IResource>();
+            _schemas = new Dictionary<string, FeatureSourceDescription>();
+            _spatialContexts = new Dictionary<string, FdoSpatialContextList>();
+        }
+
+        public FdoSpatialContextList GetSpatialContexts(string resourceId)
+        {
+            if (_spatialContexts.ContainsKey(resourceId))
+            {
+                Trace.TraceInformation("Fetching cached spatial contexts of: " + resourceId);
+                return _spatialContexts[resourceId];
+            }
+
+            var scList = _featSvc.GetSpatialContextInfo(resourceId, false);
+            _spatialContexts[resourceId] = scList;
+
+            return scList;
+        }
+
+        public FeatureSourceDescription DescribeFeatureSource(string resourceId)
+        {
+            if (_schemas.ContainsKey(resourceId))
+            {
+                Trace.TraceInformation("Fetching cached schema of: " + resourceId);
+                return _schemas[resourceId];
+            }
+
+            var desc = _featSvc.DescribeFeatureSource(resourceId);
+            _schemas[resourceId] = desc;
+
+            return desc;
+        }
+
+        public IResource GetResource(string resourceId)
+        {
+            if (_resources.ContainsKey(resourceId))
+            {
+                Trace.TraceInformation("Fetching cached copy of: " + resourceId);
+                return _resources[resourceId];
+            }
+
+            var res = _resSvc.GetResource(resourceId);
+            _resources[resourceId] = res;
+
+            return res;
+        }
+
+        public bool IsAlreadyValidated(string resourceId)
+        {
+            var res = _validated.ContainsKey(resourceId);
+
+            if (res)
+                Trace.TraceInformation("Skipping validation: " + resourceId);
+
+            return res;
+        }
+
+        public void MarkValidated(string resourceId)
+        {
+            _validated[resourceId] = resourceId;
+
+            Trace.TraceInformation("Validated: " + resourceId);
+        }
+    }
+}



More information about the mapguide-commits mailing list