[mapguide-commits] r6494 - in trunk/Tools/Maestro: Maestro.Editors/FeatureSource/Providers OSGeo.MapGuide.MaestroAPI/ObjectModels

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Feb 8 07:56:55 EST 2012


Author: jng
Date: 2012-02-08 04:56:55 -0800 (Wed, 08 Feb 2012)
New Revision: 6494

Modified:
   trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/GenericCtrl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs
Log:
#1925: Avoid unnecessary flagging of dirty state in the Generic FS editor when testing a connection. We do this by creating a clone of the currently edited feature source object with all change listeners detached to not accidentally trigger the dirty state. This submission also fixes a defect where a new feature source object is not initialized with default connection property values where applicable.

Modified: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/GenericCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/GenericCtrl.cs	2012-02-08 12:09:06 UTC (rev 6493)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/GenericCtrl.cs	2012-02-08 12:56:55 UTC (rev 6494)
@@ -101,22 +101,26 @@
                 nameCell.Value = p.Name;
                 nameCell.ToolTipText = p.LocalizedName;
 
+                var currentValue = _fs.GetConnectionProperty(p.Name);
                 DataGridViewCell valueCell = null;
                 if (p.Enumerable)
                 {
                     valueCell = new DataGridViewTextBoxCell();
                     valueCell.Tag = p;
-                    valueCell.Value = _fs.GetConnectionProperty(p.Name);
+                    valueCell.Value = currentValue;
                 }
                 else
                 {
                     valueCell = new DataGridViewTextBoxCell();
                     valueCell.Tag = p;
-                    valueCell.Value = _fs.GetConnectionProperty(p.Name);
+                    valueCell.Value = currentValue;
                 }
 
-                if (!string.IsNullOrEmpty(p.DefaultValue))
+                if (string.IsNullOrEmpty(currentValue) && !string.IsNullOrEmpty(p.DefaultValue))
+                {
                     valueCell.Value = p.DefaultValue;
+                    _fs.SetConnectionProperty(p.Name, p.DefaultValue);
+                }
 
                 row.Cells.Add(nameCell);
                 row.Cells.Add(valueCell);
@@ -182,15 +186,20 @@
         private void btnTest_Click(object sender, EventArgs e)
         {
             txtTestResult.Text = string.Empty;
+            var param = GetConnectionParameters();
 
-            var param = GetConnectionParameters();
+            var cloneFs = (IFeatureSource)_fs.Clone();
+            _service.ResourceService.SaveResourceAs(cloneFs, "Session:" + _service.SessionID + "//" + Guid.NewGuid().ToString() + ".FeatureSource");
+            
+            cloneFs.ClearConnectionProperties();
             foreach (var key in param.AllKeys)
             {
-                _fs.SetConnectionProperty(key, param[key]);
+                cloneFs.SetConnectionProperty(key, param[key]);
             }
-            _service.ResourceService.SaveResource(_fs);
-            string msg = _service.FeatureService.TestConnection(_fs.ResourceID);
+            _service.ResourceService.SaveResource(cloneFs);
 
+            string msg = _service.FeatureService.TestConnection(cloneFs.ResourceID);
+
             if (string.IsNullOrEmpty(msg))
                 msg = Properties.Resources.TestConnectionNoErrors;
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs	2012-02-08 12:09:06 UTC (rev 6493)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs	2012-02-08 12:56:55 UTC (rev 6494)
@@ -25,6 +25,7 @@
 using OSGeo.MapGuide.MaestroAPI;
 using OSGeo.MapGuide.ObjectModels.Common;
 using OSGeo.MapGuide.ObjectModels.FeatureSource;
+using System.ComponentModel;
 
 #pragma warning disable 1591, 0114, 0108
 
@@ -86,7 +87,9 @@
 
         object ICloneable.Clone()
         {
-            return this.Clone();
+            var fs = this.Clone();
+            fs.DetachChangeListeners();
+            return fs;
         }
 
         [XmlAttribute("noNamespaceSchemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
@@ -155,6 +158,19 @@
             OnPropertyChanged("Parameter");
         }
 
+        protected void DetachChangeListeners()
+        {
+            var handler = this.PropertyChanged;
+            if (handler != null)
+            {
+                foreach (var h in handler.GetInvocationList())
+                {
+                    this.PropertyChanged -= (PropertyChangedEventHandler)h;
+                }
+                handler = null;
+            }
+        }
+
         [XmlIgnore]
         public string ConnectionString
         {



More information about the mapguide-commits mailing list