[mapguide-commits] r6388 - in trunk/Tools/Maestro: MaestroAPITests OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Mapping

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Dec 30 10:53:59 EST 2011


Author: jng
Date: 2011-12-30 07:53:59 -0800 (Fri, 30 Dec 2011)
New Revision: 6388

Modified:
   trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs
   trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
Log:
Add a new IsDirty property to RuntimeMap, which indicates if state modifications have been made which requires a call to Save()

Modified: trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs	2011-12-30 14:16:32 UTC (rev 6387)
+++ trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs	2011-12-30 15:53:59 UTC (rev 6388)
@@ -148,9 +148,10 @@
 
             resSvc.SetResourceXmlData(target, resSvc.GetResourceXmlData(source));
 
-            string dataName = "";
+            string dataName = "UT_HydrographicPolygons.sdf";
             var resDataList = resSvc.EnumerateResourceData(source);
-            dataName = resDataList.ResourceData[0].Name;
+            if (resDataList.ResourceData.Count == 1)
+                dataName = resDataList.ResourceData[0].Name;
 
             resSvc.SetResourceData(target,
                                    dataName,

Modified: trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2011-12-30 14:16:32 UTC (rev 6387)
+++ trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2011-12-30 15:53:59 UTC (rev 6388)
@@ -196,7 +196,9 @@
             
             //Call save
             Assert.IsTrue(Matches(map, mdf));
+            Assert.IsFalse(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
             Assert.IsTrue(Matches(map, mdf));
             Assert.IsTrue(resSvc.ResourceExists(mid));
 
@@ -219,7 +221,9 @@
 
             //Save
             Assert.IsFalse(Matches(map2, mdf));
+            Assert.IsTrue(map2.IsDirty);
             map2.Save();
+            Assert.IsFalse(map2.IsDirty);
             Assert.IsFalse(Matches(map2, mdf));
 
             var map3 = mapSvc.OpenMap(mid);
@@ -273,7 +277,9 @@
 
             //Doesn't exist yet because save isn't called
             Assert.IsTrue(!resSvc.ResourceExists(mid));
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render default
             RenderAndVerify(mapSvc, map, "TestRender75k.png", "PNG");
@@ -285,7 +291,9 @@
             var rail = map.GetLayerByName("Rail");
             Assert.NotNull(rail);
             rail.Visible = false;
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render again
             RenderAndVerify(mapSvc, map, "TestRender75k_NoRail.png", "PNG");
@@ -298,7 +306,9 @@
             rail = map.GetLayerByName("Rail");
             Assert.NotNull(rail);
             rail.Visible = true;
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render again
             RenderAndVerify(mapSvc, map, "TestRender75k_RailBackOn.png", "PNG");
@@ -490,7 +500,9 @@
 
             //Doesn't exist yet because save isn't called
             Assert.IsTrue(!resSvc.ResourceExists(mid));
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             int counter = 0;
             foreach (var layer in map.Layers)
@@ -555,7 +567,9 @@
 
             //Doesn't exist yet because save isn't called
             Assert.IsTrue(!resSvc.ResourceExists(mid));
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render default
             RenderAndVerify(mapSvc, map, "TestRender12k.png", "PNG");
@@ -567,7 +581,9 @@
             var parcels = map.GetLayerByName("Parcels");
             Assert.NotNull(parcels);
             parcels.Visible = false;
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
             
             //Render again
             RenderAndVerify(mapSvc, map, "TestRender12k_NoParcels.png", "PNG");
@@ -580,7 +596,9 @@
             parcels = map.GetLayerByName("Parcels");
             Assert.NotNull(parcels);
             parcels.Visible = true;
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render again
             RenderAndVerify(mapSvc, map, "TestRender12k_ParcelsBackOn.png", "PNG");
@@ -621,7 +639,9 @@
 
             //Doesn't exist yet because save isn't called
             Assert.IsTrue(!resSvc.ResourceExists(mid));
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render default
             RenderAndVerify(mapSvc, map, "TestMapManipulation12kWithRail.png", "PNG");
@@ -636,7 +656,9 @@
             var rail = map.GetLayerByName("Rail");
             Assert.NotNull(rail);
             map.RemoveLayer(rail);
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render again
             RenderAndVerify(mapSvc, map, "TestMapManipulation12k_RailRemoved.png", "PNG");
@@ -665,7 +687,9 @@
             //var parcels = map.GetLayerByName("Parcels");
             //rail.SetDrawOrder(parcels.DisplayOrder - 0.000001);
 
+            Assert.IsTrue(map.IsDirty);
             map.Save();
+            Assert.IsFalse(map.IsDirty);
 
             //Render again. Rail should be above parcels
             RenderAndVerify(mapSvc, map, "TestMapManipulation12k_RailReAdded.png", "PNG");
@@ -934,9 +958,13 @@
             ResourceIdentifier mapid = new ResourceIdentifier(mapName, ResourceTypes.RuntimeMap, conn.SessionID);
             IMapDefinition mdef = (IMapDefinition)conn.ResourceService.GetResource(mapdefinition);
             RuntimeMap rtm = mapSvc.CreateMap(mdef); // Create new runtime map
+            Assert.IsFalse(rtm.IsDirty);
             rtm.Save();
+            Assert.IsFalse(rtm.IsDirty);
             RuntimeMap tmprtm = mapSvc.CreateMap(mapid, mdef); // Create new map in data cache
+            Assert.IsFalse(tmprtm.IsDirty);
             tmprtm.Save();
+            Assert.IsFalse(tmprtm.IsDirty);
 
             RuntimeMap mymap = mapSvc.OpenMap(mapid); 
         }
@@ -949,6 +977,7 @@
             IMapDefinition mdef = (IMapDefinition)conn.ResourceService.GetResource(mapdefinition);
             RuntimeMap rtm = mapSvc.CreateMap(mdef); // Create new runtime map
             rtm.Save();
+            Assert.IsFalse(rtm.IsDirty);
             RuntimeMap mymap = mapSvc.OpenMap("Session:" + conn.SessionID + "//" + rtm.Name + ".Map");
         }
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2011-12-30 14:16:32 UTC (rev 6387)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2011-12-30 15:53:59 UTC (rev 6388)
@@ -171,6 +171,7 @@
             this.Layers = new RuntimeMapLayerCollection(this);
             this.Groups = new RuntimeMapGroupCollection(this);
             this.Selection = new MapSelection(this);
+            this.IsDirty = false;
         }
 
         static IEnumerable<string> GetLayerIds(IMapDefinition mdf)
@@ -842,6 +843,7 @@
             }
 
             _disableChangeTracking = false;
+            this.IsDirty = false;
         }
 
         private static IEnvelope DeserializeExtents(MgBinaryDeserializer d)
@@ -1203,6 +1205,7 @@
                     this.ResourceService.SetResourceData(resourceID, "LayerGroupData", ResourceDataType.Stream, ms2);
 
                 SaveSelectionXml(resourceID);
+                this.IsDirty = false;
             }
             finally
             {
@@ -1211,6 +1214,18 @@
             }
         }
 
+        /// <summary>
+        /// Gets whether this instance has state changes which require a call to <see cref="M:OSGeo.MapGuide.MaestroAPI.Mapping.RuntimeMap.Save"/>
+        /// </summary>
+        /// <value>
+        ///   <c>true</c> if this instance is dirty; otherwise, <c>false</c>.
+        /// </value>
+        public bool IsDirty
+        {
+            get;
+            internal set;
+        }
+
         private void SaveSelectionXml(string resourceID)
         {
             if (this.Selection == null)
@@ -1258,9 +1273,21 @@
 
             var change = new Change(type, param);
             changes.Changes.Add(change);
+
+            this.IsDirty = true;
         }
 
         /// <summary>
+        /// Raises the <see cref="PropertyChanged"/> event
+        /// </summary>
+        /// <param name="propertyName"></param>
+        protected override void OnPropertyChanged(string propertyName)
+        {
+            base.OnPropertyChanged(propertyName);
+            this.IsDirty = true;
+        }
+
+        /// <summary>
         /// Clears all tracked changes
         /// </summary>
         protected void ClearChanges()

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2011-12-30 14:16:32 UTC (rev 6387)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2011-12-30 15:53:59 UTC (rev 6388)
@@ -313,7 +313,8 @@
                 if (this.Type == kBaseMap)
                     throw new InvalidOperationException("Setting visbility of a tiled map layer is not permitted");
 
-                SetField(ref _visible, value, "Visible");
+                if (SetField(ref _visible, value, "Visible"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -331,7 +332,8 @@
             }
             set
             {
-                SetField(ref _group, value, "Group");
+                if (SetField(ref _group, value, "Group"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -359,7 +361,8 @@
             }
             set
             {
-                SetField(ref _selectable, value, "Selectable");
+                if (SetField(ref _selectable, value, "Selectable"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -377,7 +380,8 @@
             }
             set
             {
-                SetField(ref _name, value, "Name");
+                if (SetField(ref _name, value, "Name"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -395,7 +399,8 @@
             }
             set
             {
-                SetField(ref _showInLegend, value, "ShowInLegend");
+                if (SetField(ref _showInLegend, value, "ShowInLegend"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -413,7 +418,8 @@
             }
             set
             {
-                SetField(ref _legendLabel, value, "LegendLabel");
+                if (SetField(ref _legendLabel, value, "LegendLabel"))
+                    Parent.IsDirty = true;
             }
         }
 
@@ -431,7 +437,8 @@
             }
             set
             {
-                SetField(ref _expandInLegend, value, "ExpandInLegend");
+                if (SetField(ref _expandInLegend, value, "ExpandInLegend"))
+                    Parent.IsDirty = true;
             }
         }
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2011-12-30 14:16:32 UTC (rev 6387)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2011-12-30 15:53:59 UTC (rev 6388)
@@ -1897,6 +1897,7 @@
         {
             var map = new RuntimeMap(mdf, metersPerUnit);
             map.ResourceID = runtimeMapResourceId;
+            map.IsDirty = false;
             return map;
         }
 
@@ -1915,6 +1916,7 @@
             if (this.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
                 map.DeserializeLayerData(new MgBinaryDeserializer(this.GetResourceData(runtimeMapResourceId, "LayerGroupData"), this.SiteVersion));
 
+            map.IsDirty = false;
             return map;
         }
         #endregion



More information about the mapguide-commits mailing list