[mapguide-commits] r4923 - in sandbox/maestro-2.5: Generated Maestro.Base Maestro.Base/Services Maestro.Editors/Generic OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Capability OSGeo.MapGuide.MaestroAPI/ObjectModels OSGeo.MapGuide.MaestroAPI.Http

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon May 24 07:08:00 EDT 2010


Author: jng
Date: 2010-05-24 07:07:59 -0400 (Mon, 24 May 2010)
New Revision: 4923

Modified:
   sandbox/maestro-2.5/Generated/ApplicationDefinition-1.0.0.designer.cs
   sandbox/maestro-2.5/Generated/FeatureSource-1.0.0.designer.cs
   sandbox/maestro-2.5/Generated/LayerDefinition-1.0.0.designer.cs
   sandbox/maestro-2.5/Generated/SymbolDefinition-1.0.0.designer.cs
   sandbox/maestro-2.5/Maestro.Base/Services/OpenResourceManager.cs
   sandbox/maestro-2.5/Maestro.Base/TabFactory.cs
   sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs
   sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCapabilities.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/Capability/ConnectionCapabilities.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/IConnectionCapabilities.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ObjectModels/SymbolDefinition.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs
Log:
This submission contains the following changes:
 - Fixed some ExtendedData elements from generated classes that were not re-modified since re-generation of the code.
 - Added a IsMultithreaded flag to IConnectionCapabilities, all implementations currently return false.
 - Mono stability fixes:
   - #1147: Remove the use of System.Net.WebClient and replaced it with HttpWebRequest/HttpWebResponse pairs. Though I cannot vouch for the thread safety yet (hence IsMultithreaded = false), I can vouch for improved stability in Mono, as I no longer experience freezing on what appears to be a hung WebClient on the GUI thread (at least that's what the Mono stack traces were telling me).
   - Changed all references of TabControl.SelectedTab to use SelectedIndex instead, since we already know that SelectedTab is problematic. This incidentally made our custom close button working again in Mono.
 - Split the SymbolDefinition deserialization, since the root element of a Symbol Definition could be either SimpleSymbolDefinition or CompoundSymbolDefinition, we had to peek at the XML first (ugly) in order to determine which proper Deserialize() method to call.

Modified: sandbox/maestro-2.5/Generated/ApplicationDefinition-1.0.0.designer.cs
===================================================================
--- sandbox/maestro-2.5/Generated/ApplicationDefinition-1.0.0.designer.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Generated/ApplicationDefinition-1.0.0.designer.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -1070,12 +1070,13 @@
     public partial class CustomContentType : System.ComponentModel.INotifyPropertyChanged {
         
         [EditorBrowsable(EditorBrowsableState.Never)]
-        private BindingList<System.Xml.XmlElement> anyField;
+        private System.Xml.XmlElement[] anyField;
         
         private static System.Xml.Serialization.XmlSerializer serializer;
         
         [System.Xml.Serialization.XmlAnyElementAttribute()]
-        public BindingList<System.Xml.XmlElement> Any {
+        public System.Xml.XmlElement[] Any
+        {
             get {
                 return this.anyField;
             }

Modified: sandbox/maestro-2.5/Generated/FeatureSource-1.0.0.designer.cs
===================================================================
--- sandbox/maestro-2.5/Generated/FeatureSource-1.0.0.designer.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Generated/FeatureSource-1.0.0.designer.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -618,12 +618,13 @@
     public partial class ExtendedDataType : System.ComponentModel.INotifyPropertyChanged {
         
         [EditorBrowsable(EditorBrowsableState.Never)]
-        private BindingList<System.Xml.XmlElement> anyField;
+        private System.Xml.XmlElement[] anyField;
         
         private static System.Xml.Serialization.XmlSerializer serializer;
         
         [System.Xml.Serialization.XmlAnyElementAttribute()]
-        public BindingList<System.Xml.XmlElement> Any {
+        public System.Xml.XmlElement[] Any
+        {
             get {
                 return this.anyField;
             }

Modified: sandbox/maestro-2.5/Generated/LayerDefinition-1.0.0.designer.cs
===================================================================
--- sandbox/maestro-2.5/Generated/LayerDefinition-1.0.0.designer.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Generated/LayerDefinition-1.0.0.designer.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -728,12 +728,13 @@
     public partial class ExtendedDataType : System.ComponentModel.INotifyPropertyChanged {
         
         [EditorBrowsable(EditorBrowsableState.Never)]
-        private BindingList<System.Xml.XmlElement> anyField;
+        private System.Xml.XmlElement[] anyField;
         
         private static System.Xml.Serialization.XmlSerializer serializer;
         
         [System.Xml.Serialization.XmlAnyElementAttribute()]
-        public BindingList<System.Xml.XmlElement> Any {
+        public System.Xml.XmlElement[] Any
+        {
             get {
                 return this.anyField;
             }

Modified: sandbox/maestro-2.5/Generated/SymbolDefinition-1.0.0.designer.cs
===================================================================
--- sandbox/maestro-2.5/Generated/SymbolDefinition-1.0.0.designer.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Generated/SymbolDefinition-1.0.0.designer.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -1422,12 +1422,13 @@
     public partial class ExtendedDataType : System.ComponentModel.INotifyPropertyChanged {
         
         [EditorBrowsable(EditorBrowsableState.Never)]
-        private BindingList<System.Xml.XmlElement> anyField;
+        private System.Xml.XmlElement[] anyField;
         
         private static System.Xml.Serialization.XmlSerializer serializer;
         
         [System.Xml.Serialization.XmlAnyElementAttribute()]
-        public BindingList<System.Xml.XmlElement> Any {
+        public System.Xml.XmlElement[] Any
+        {
             get {
                 return this.anyField;
             }

Modified: sandbox/maestro-2.5/Maestro.Base/Services/OpenResourceManager.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/Services/OpenResourceManager.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Maestro.Base/Services/OpenResourceManager.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -117,18 +117,18 @@
                         ed = svc.OpenContent<LoadProcedureEditor>(ViewRegion.Document);
                         break;
                     case ResourceTypes.MapDefinition:
-                        ed = svc.OpenContent<MapDefinitionEditor>(ViewRegion.Document);
+                        //ed = svc.OpenContent<MapDefinitionEditor>(ViewRegion.Document);
                         break;
                     case ResourceTypes.PrintLayout:
-                        ed = svc.OpenContent<PrintLayoutEditor>(ViewRegion.Document);
+                        //ed = svc.OpenContent<PrintLayoutEditor>(ViewRegion.Document);
                         break;
                     case ResourceTypes.SymbolDefinition:
-                        ed = svc.OpenContent<SymbolDefinitionEditor>(ViewRegion.Document);
+                        //ed = svc.OpenContent<SymbolDefinitionEditor>(ViewRegion.Document);
                         break;
                     case ResourceTypes.SymbolLibrary:
                         break;
                     case ResourceTypes.WebLayout:
-                        ed = svc.OpenContent<WebLayoutEditor>(ViewRegion.Document);
+                        //ed = svc.OpenContent<WebLayoutEditor>(ViewRegion.Document);
                         break;
                     default:
                         ed = svc.OpenContent<XmlEditor>(ViewRegion.Document);

Modified: sandbox/maestro-2.5/Maestro.Base/TabFactory.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/TabFactory.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Maestro.Base/TabFactory.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -64,14 +64,18 @@
                 if (hiddenTab != null)
                 {
                     hiddenTab.Parent.TabPages.Add(page);
-                    hiddenTab.Parent.SelectedTab = page;
+                    var indx = hiddenTab.Parent.TabPages.IndexOf(page);
+                    hiddenTab.Parent.SelectedIndex = indx;
                     _hiddenTabs.Remove(hiddenTab);
                 }
                 else //Wasn't hidden in the first place
                 {
                     var tabs = page.Parent as TabControl;
                     if (tabs != null)
-                        tabs.SelectedTab = page;
+                    {
+                        var indx = tabs.TabPages.IndexOf(page);
+                        tabs.SelectedIndex = indx;
+                    }
                 }
             };
             if (content.AllowUserClose)

Modified: sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -46,9 +46,14 @@
                 if (documentTabs.TabCount == 0)
                     return null;
 
-                var page = documentTabs.SelectedTab;
-                var cnt = (IViewContent)page.Tag;
-                return cnt;
+                var indx = documentTabs.SelectedIndex;
+                if (indx >= 0)
+                {
+                    var page = documentTabs.TabPages[indx];
+                    var cnt = (IViewContent)page.Tag;
+                    return cnt;
+                }
+                return null;
             }
         }
 
@@ -189,8 +194,12 @@
         private void ZoneTabSelectedIndexChanged(object sender, EventArgs e)
         {
             TabControl tabs = (TabControl)sender;
-            TabPage page = tabs.SelectedTab;
-            OnViewActivated((IViewContent)page.Tag);
+            var indx = tabs.SelectedIndex;
+            if (indx >= 0)
+            {
+                TabPage page = tabs.TabPages[indx];
+                OnViewActivated((IViewContent)page.Tag);
+            }
         }
     }
 }

Modified: sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -257,10 +257,7 @@
         public override void Bind(IEditorService service)
         {
             var res = service.GetEditedResource();
-
-            //HACK: Scrub out junk <ExtendedData1> elements.
             this.XmlContent = res.Serialize();
-
             resDataCtrl.Init(service);
         }
 

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/Capability/ConnectionCapabilities.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/Capability/ConnectionCapabilities.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/Capability/ConnectionCapabilities.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -46,5 +46,10 @@
         {
             get { return false; }
         }
+
+        public virtual bool IsMultithreaded
+        {
+            get { return false; }
+        }
     }
 }

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/IConnectionCapabilities.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/IConnectionCapabilities.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/IConnectionCapabilities.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -33,6 +33,11 @@
         Version GetMaxSupportedResourceVersion(ResourceTypes resourceType);
 
         /// <summary>
+        /// Indicates whether the current connection can be used between multiple threads
+        /// </summary>
+        bool IsMultithreaded { get; }
+
+        /// <summary>
         /// Gets an array of supported commands
         /// </summary>
         int[] SupportedCommands { get; }

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-05-24 11:07:59 UTC (rev 4923)
@@ -3,7 +3,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.30729</ProductVersion>
+    <ProductVersion>9.0.21022</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{80FA3158-8B5F-48D1-A393-0378AFE48A7E}</ProjectGuid>
     <OutputType>Library</OutputType>
@@ -98,9 +98,6 @@
     <Compile Include="..\Generated\MapDefinition-1.0.0.designer.cs">
       <Link>ObjectModels\MapDefinition-1.0.0.designer.cs</Link>
     </Compile>
-    <Compile Include="..\Generated\PlatformCommon-1.0.0.designer.cs">
-      <Link>ObjectModels\PlatformCommon-1.0.0.designer.cs</Link>
-    </Compile>
     <Compile Include="..\Generated\PrintLayout-1.0.0.designer.cs">
       <Link>ObjectModels\PrintLayout-1.0.0.designer.cs</Link>
     </Compile>

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ObjectModels/SymbolDefinition.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ObjectModels/SymbolDefinition.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ObjectModels/SymbolDefinition.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -26,7 +26,7 @@
 
 namespace OSGeo.MapGuide.ObjectModels.SymbolDefinition
 {
-    partial class SymbolDefinitionBase : IResource
+    partial class SimpleSymbolDefinition : IResource
     {
         private static readonly Version RES_VERSION = new Version(1, 0, 0);
 
@@ -96,4 +96,75 @@
             get { return true; }
         }
     }
+
+    partial class CompoundSymbolDefinition : IResource
+    {
+        private static readonly Version RES_VERSION = new Version(1, 0, 0);
+
+        [XmlIgnore]
+        public OSGeo.MapGuide.MaestroAPI.IServerConnection CurrentConnection
+        {
+            get;
+            set;
+        }
+
+        private string _resId;
+
+        [XmlIgnore]
+        public string ResourceID
+        {
+            get
+            {
+                return _resId;
+            }
+            set
+            {
+                if (!ResourceIdentifier.Validate(value))
+                    throw new InvalidOperationException("Not a valid resource identifier"); //LOCALIZE
+
+                var res = new ResourceIdentifier(value);
+                if (res.Extension != ResourceTypes.SymbolDefinition.ToString())
+                    throw new InvalidOperationException("Invalid resource identifier for this type of object: " + res.Extension); //LOCALIZE
+
+                _resId = value;
+                this.OnPropertyChanged("ResourceID");
+            }
+        }
+
+        [XmlIgnore]
+        public ResourceTypes ResourceType
+        {
+            get
+            {
+                return ResourceTypes.SymbolDefinition;
+            }
+        }
+
+        [XmlIgnore]
+        public Version ResourceVersion
+        {
+            get
+            {
+                return RES_VERSION;
+            }
+        }
+
+        object ICloneable.Clone()
+        {
+            return this.Clone();
+        }
+
+        [XmlAttribute("noNamespaceSchemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
+        public string ValidatingSchema
+        {
+            get { return "SymbolDefinition-1.0.0.xsd"; }
+            set { }
+        }
+
+        [XmlIgnore]
+        public bool IsStronglyTyped
+        {
+            get { return true; }
+        }
+    }
 }

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -116,7 +116,25 @@
                 new ResourceSerializer()
                 {
                     Serialize = (res) => { return res.SerializeToStream(); },
-                    Deserialize = (xml) => { return SymbolDefinitionBase.Deserialize(xml); }
+                    Deserialize = (xml) => 
+                    { 
+                        //HACK: We have to peek at the XML to determine if this is simple or compound.
+                        var doc = new XmlDocument();
+                        doc.LoadXml(xml);
+                        var node = doc.SelectSingleNode("//SimpleSymbolDefinition");
+                        if (node != null)
+                        {
+                            return SimpleSymbolDefinition.Deserialize(xml);
+                        }
+                        else
+                        {
+                            node = doc.SelectSingleNode("//CompoundSymbolDefinition");
+                            if (node != null)
+                                return CompoundSymbolDefinition.Deserialize(xml);
+                            else //WTF?
+                                throw new SerializationException("Could not determine symbol type"); //LOCALIZE
+                        }
+                    }
                 });
 
             //SymbolLibrary 1.0.0

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCapabilities.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCapabilities.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCapabilities.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -150,5 +150,10 @@
         {
             get { return true; }
         }
+
+        public bool IsMultithreaded
+        {
+            get { return false; }
+        }
     }
 }

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -49,7 +49,7 @@
 				{
 					string req = m_req.EnumerateCategories();
 					XmlDocument doc = new XmlDocument();
-					doc.Load(m_con.WebClient.OpenRead(req));
+					doc.Load(m_con.OpenRead(req));
 					XmlNodeList lst = doc.SelectNodes("StringCollection/Item");
                     CoordinateSystemCategory[] data = new CoordinateSystemCategory[lst.Count];
 					for(int i = 0; i < lst.Count; i++)
@@ -68,7 +68,7 @@
 				if (m_coordLib == null)
 				{
 					string req = m_req.GetBaseLibrary();
-					m_coordLib = System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req));
+					m_coordLib = System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req));
 				}
 				return m_coordLib;
 			}
@@ -77,31 +77,31 @@
         public override bool IsValid(string wkt)
 		{
 			string req = m_req.IsValidCoordSys(wkt);
-			return System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req)).ToLower().Trim().Equals("true");
+			return System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req)).ToLower().Trim().Equals("true");
 		}
 
         public override string ConvertWktToCoordinateSystemCode(string wkt)
 		{
 			string req = m_req.ConvertWktToCoordinateSystemCode(wkt);
-			return System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req));
+			return System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req));
 		}
 
         public override string ConvertCoordinateSystemCodeToWkt(string coordcode)
 		{
 			string req = m_req.ConvertCoordinateSystemCodeToWkt(coordcode);
-			return System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req));
+			return System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req));
 		}
 
         public override string ConvertWktToEpsgCode(string wkt)
 		{
 			string req = m_req.ConvertWktToEpsgCode(wkt);
-			return System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req));
+			return System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req));
 		}
 
         public override string ConvertEpsgCodeToWkt(string epsg)
 		{
 			string req = m_req.ConvertEpsgCodeToWkt(epsg);
-			return System.Text.Encoding.UTF8.GetString(m_con.WebClient.DownloadData(req));
+			return System.Text.Encoding.UTF8.GetString(m_con.DownloadData(req));
 		}
 
         public override bool IsLoaded { get { return m_categories != null; } }
@@ -123,7 +123,7 @@
 
             string req = this.RequestBuilder.EnumerateCoordinateSystems(category);
             XmlDocument doc = new XmlDocument();
-            doc.Load(m_con.WebClient.OpenRead(req));
+            doc.Load(m_con.OpenRead(req));
             XmlNodeList lst = doc.SelectNodes("BatchPropertyCollection/PropertyCollection");
             CoordinateSystemBase[] data = new CoordinateSystemBase[lst.Count];
             for (int i = 0; i < lst.Count; i++)

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-05-21 13:22:47 UTC (rev 4922)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-05-24 11:07:59 UTC (rev 4923)
@@ -51,20 +51,19 @@
                                         IDrawingService,
                                         IFusionService
 	{
-		private WebClient m_wc;
-		private RequestBuilder m_reqBuilder;
+		private RequestBuilder m_reqBuilder;   
 		
 		//These only change after server reboot, so it is probably safe to cache them
-		private FeatureProviderRegistry m_featureProviders = null;
-		private Hashtable m_cachedProviderCapabilities = null;
-		private Version m_siteVersion;
+		private FeatureProviderRegistry m_featureProviders = null; //SHARED
+		private Hashtable m_cachedProviderCapabilities = null; //SHARED
+		private Version m_siteVersion; //SHARED
 
         private bool mAnonymousUser = false;
 
 		internal HttpServerConnection()
 			: base()
 		{
-			m_wc = new WebClient();
+			//m_wc = new WebClient();
 			m_cachedProviderCapabilities = new Hashtable();
 		}
 
@@ -78,7 +77,16 @@
         /// Gets whether this connection was initialised with an Anonymous login. If it was, it will return true. 
         /// If this was not, or it was initialised from an existing session id, then it will return false.
         /// </summary>
-        public bool IsAnonymous { get { return mAnonymousUser; } }
+        public bool IsAnonymous
+        {
+            get
+            {
+                lock (SyncRoot)
+                {
+                    return mAnonymousUser;
+                }
+            }
+        }
 
         public const string PARAM_URL = "Url";
         public const string PARAM_SESSION = "SessionId";
@@ -87,6 +95,8 @@
         public const string PARAM_USERNAME = "Username";
         public const string PARAM_PASSWORD = "Password";
 
+        private ICredentials _cred;
+
         private void InitConnection(Uri hosturl, string sessionid, string locale, bool allowUntestedVersion)
         {
             m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid);
@@ -94,7 +104,7 @@
             SiteVersion sv = null;
             try
             {
-                sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), m_wc.OpenRead(req));
+                sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), OpenRead(req));
             }
             catch (Exception ex)
             {
@@ -111,7 +121,7 @@
                         hosturl = new Uri(tmp + "mapagent/mapagent.fcgi");
                         m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid);
                         req = m_reqBuilder.GetSiteVersion();
-                        sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), m_wc.OpenRead(req));
+                        sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), OpenRead(req));
                         ok = true;
                     }
                 }
@@ -122,20 +132,24 @@
             }
             if (!allowUntestedVersion)
                 ValidateVersion(sv);
-            m_siteVersion = new Version(sv.Version);
+
+            lock (SyncRoot)
+            {
+                m_siteVersion = new Version(sv.Version);
+            }
         }
 
         private void InitConnection(Uri hosturl, string username, string password, string locale, bool allowUntestedVersion)
         {
             m_reqBuilder = new RequestBuilder(hosturl, locale);
-            m_wc.Credentials = new NetworkCredential(username, password);
+            mAnonymousUser = (username == "Anonymous");
+
+            _cred = new NetworkCredential(username, password);
             string req = m_reqBuilder.CreateSession();
 
             m_username = username;
             m_password = password;
 
-            mAnonymousUser = (username == "Anonymous");
-
             try
             {
                 this.RestartSession();
@@ -146,7 +160,7 @@
             }
 
             if (!allowUntestedVersion)
-                ValidateVersion(m_siteVersion);
+                ValidateVersion(this.SiteVersion);
             m_username = username;
             m_password = password;
         }
@@ -211,7 +225,6 @@
 			}
 		}
 
-
 		public override ResourceList GetRepositoryResources(string startingpoint, string type, int depth, bool computeChildren)
 		{
 			string req = m_reqBuilder.EnumerateResources(startingpoint, depth, type, computeChildren);
@@ -225,9 +238,12 @@
 			get
 			{
 				string req = m_reqBuilder.GetFeatureProviders();
-			
-				if (m_featureProviders == null)
-					m_featureProviders = (FeatureProviderRegistry)DeserializeObject(typeof(FeatureProviderRegistry), this.OpenRead(req));
+                
+                lock (SyncRoot)
+                {
+                    if (m_featureProviders == null)
+                        m_featureProviders = (FeatureProviderRegistry)DeserializeObject(typeof(FeatureProviderRegistry), this.OpenRead(req));
+                }
 
                 var providers = new FeatureProviderRegistryFeatureProvider[m_featureProviders.FeatureProvider.Count];
                 int i = 0;
@@ -240,8 +256,6 @@
 			}
 		}
 
-		internal WebClient WebClient { get { return m_wc; } }
-
 		public override string TestConnection(string featuresource)
 		{
 			string req = m_reqBuilder.TestConnection(featuresource);
@@ -377,14 +391,6 @@
 			return ms;
 		}
 
-        public WebHeaderCollection LastResponseHeaders
-        {
-            get
-            {
-                return m_wc.ResponseHeaders;
-            }
-        }
-
 		public override Stream GetResourceXmlData(string resourceID)
 		{
 			ResourceIdentifier.Validate(resourceID, ResourceTypes.FeatureSource);
@@ -436,7 +442,7 @@
 			{
 #endif
 				System.Net.WebRequest req = m_reqBuilder.SetResourceData(resourceid, dataname, datatype, outStream, stream, callback);
-				req.Credentials = m_wc.Credentials;
+                req.Credentials = _cred;
 				outStream.Position = 0;
 				
 				//Protect against session expired
@@ -479,7 +485,7 @@
                 this.DownloadData(m_reqBuilder.GetSiteVersion());
 
             System.Net.WebRequest req = m_reqBuilder.SetResource(resourceid, outStream, content, header);
-            req.Credentials = m_wc.Credentials;
+            req.Credentials = _cred;
             outStream.Position = 0;
             try
             {
@@ -673,7 +679,7 @@
             SetResourceXmlData(selectionID, new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(RuntimeMapBase.RUNTIMEMAP_SELECTION_XML)));
 
 			System.IO.MemoryStream ms = new System.IO.MemoryStream();
-			MgBinarySerializer serializer = new MgBinarySerializer(ms, m_siteVersion);
+			MgBinarySerializer serializer = new MgBinarySerializer(ms, this.SiteVersion);
             MapSelectionBase sel = new MapSelectionBase();
 			sel.Serialize(serializer);
 			ms.Position = 0;
@@ -785,13 +791,22 @@
 
         public override Version SiteVersion
         {
-            get { return m_siteVersion; }
+            get 
+            {
+                lock (SyncRoot)
+                {
+                    return m_siteVersion;
+                }
+            }
         }
 
         //For unit testing purposes
         internal void SetSiteVersion(Version v)
         {
-            m_siteVersion = v;
+            lock (SyncRoot)
+            {
+                m_siteVersion = v;
+            }
         }
 
         private ICoordinateSystemCatalog m_coordsys = null;
@@ -801,7 +816,7 @@
 		{ 
 			get 
 			{ 
-				if (m_siteVersion < OSGeo.MapGuide.MaestroAPI.SiteVersions.GetVersion(OSGeo.MapGuide.MaestroAPI.KnownSiteVersions.MapGuideOS1_1))
+				if (this.SiteVersion < OSGeo.MapGuide.MaestroAPI.SiteVersions.GetVersion(OSGeo.MapGuide.MaestroAPI.KnownSiteVersions.MapGuideOS1_1))
 					return null;
 				else
 				{	
@@ -1112,6 +1127,8 @@
 			return ids;
 		}
 
+        private readonly object SyncRoot = new object();
+
 		/// <summary>
 		/// Restarts the server session, and creates a new session ID
 		/// </summary>
@@ -1175,16 +1192,15 @@
 				}
 
 				//Reset cached items
-				m_siteVersion = new Version(((SiteVersion)DeserializeObject(typeof(SiteVersion), wc.OpenRead(reqb.GetSiteVersion()))).Version);
+                lock (SyncRoot)
+                {
+                    m_siteVersion = new Version(((SiteVersion)DeserializeObject(typeof(SiteVersion), wc.OpenRead(reqb.GetSiteVersion()))).Version);
 
-				m_featureProviders = null;
-				m_cachedProviderCapabilities = null;
-				m_reqBuilder = reqb;
-                //This ensures we do not hit the connection limit in .Net
-                try { m_wc.Dispose(); }
-                catch { }
-				m_wc = wc;
-
+                    m_featureProviders = null;
+                    m_cachedProviderCapabilities = null;
+                    m_reqBuilder = reqb;
+                }
+               
 				return true;
 			}
 			catch
@@ -1201,12 +1217,22 @@
 		/// </summary>
 		/// <param name="req">The request URI</param>
 		/// <returns>The data at the given location</returns>
-		protected byte[] DownloadData(string req)
+		internal byte[] DownloadData(string req)
 		{
 			string prev_session = m_reqBuilder.SessionID;
 			try
 			{
-				return m_wc.DownloadData(req);
+                var httpreq = HttpWebRequest.Create(req);
+                var httpresp = httpreq.GetResponse();
+
+                using (var st = httpresp.GetResponseStream())
+                {
+                    using (var ms = new MemoryStream())
+                    {
+                        Utility.CopyStream(st, ms);
+                        return ms.GetBuffer();
+                    }
+                }
 			}
 			catch (Exception ex)
 			{
@@ -1219,8 +1245,22 @@
                         throw;
                 }
                 else
+                {
                     //Do not try more than once
-                    return m_wc.DownloadData(req.Replace(prev_session, m_reqBuilder.SessionID)); 
+                    req = req.Replace(prev_session, m_reqBuilder.SessionID);
+
+                    var httpreq = HttpWebRequest.Create(req);
+                    var httpresp = httpreq.GetResponse();
+
+                    using (var st = httpresp.GetResponseStream())
+                    {
+                        using (var ms = new MemoryStream())
+                        {
+                            Utility.CopyStream(st, ms);
+                            return ms.GetBuffer();
+                        }
+                    }
+                }
 			}
 		}
 
@@ -1229,16 +1269,21 @@
 		/// </summary>
 		/// <param name="req">The request URI</param>
 		/// <returns>The data at the given location</returns>
-		protected System.IO.Stream OpenRead(string req)
+		internal System.IO.Stream OpenRead(string req)
 		{
 			string prev_session = m_reqBuilder.SessionID;
 			try
 			{
-				return m_wc.OpenRead(req);
+                var httpreq = HttpWebRequest.Create(req);
+                if (_cred != null)
+                    httpreq.Credentials = _cred;
+                var httpresp = httpreq.GetResponse();
+                return httpresp.GetResponseStream();
 			}
 			catch (Exception ex)
 			{
-                if (!this.m_autoRestartSession || !this.IsSessionExpiredException(ex) || !this.RestartSession(false))
+                var sessionRecreated = this.RestartSession(false);
+                if (!this.m_autoRestartSession || !this.IsSessionExpiredException(ex) || !sessionRecreated)
                 {
                     Exception ex2 = Utility.ThrowAsWebException(ex);
                     if (ex2 != ex)
@@ -1247,8 +1292,14 @@
                         throw;
                 }
                 else
-                    //Do not try more than once
-                    return m_wc.OpenRead(req.Replace(prev_session, m_reqBuilder.SessionID)); 
+                {
+                    req = req.Replace(prev_session, m_reqBuilder.SessionID);
+                    var httpreq = HttpWebRequest.Create(req);
+                    if (_cred != null)
+                        httpreq.Credentials = _cred;
+                    var httpresp = httpreq.GetResponse();
+                    return httpresp.GetResponseStream();
+                }
 			}
 		}
 
@@ -1265,7 +1316,7 @@
 			//SetResourceXmlData(selectionID, new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(RUNTIMEMAP_SELECTION_XML)));
 
 			System.IO.MemoryStream ms = new System.IO.MemoryStream();
-			MgBinarySerializer serializer = new MgBinarySerializer(ms, m_siteVersion);
+			MgBinarySerializer serializer = new MgBinarySerializer(ms, this.SiteVersion);
             MapSelectionBase sel = new MapSelectionBase(selectionXml);
 			sel.Serialize(serializer);
 			ms.Position = 0;
@@ -1282,7 +1333,7 @@
             ResourceIdentifier.Validate(runtimeMap, ResourceTypes.RuntimeMap);
 			string selectionID = runtimeMap.Substring(0, runtimeMap.LastIndexOf(".")) + ".Selection";
 			System.IO.MemoryStream ms = GetResourceData(selectionID, "RuntimeData");
-			MgBinaryDeserializer deserializer = new MgBinaryDeserializer(ms, m_siteVersion);
+			MgBinaryDeserializer deserializer = new MgBinaryDeserializer(ms, this.SiteVersion);
             MapSelectionBase sel = new MapSelectionBase();
 			sel.Deserialize(deserializer);
 			return sel.SelectionXml;
@@ -1353,7 +1404,7 @@
                 using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                 {
                     System.Net.WebRequest req = m_reqBuilder.ApplyPackage(fs, callback);
-                    req.Credentials = m_wc.Credentials;
+                    req.Credentials = _cred;
                     req.GetRequestStream().Flush();
                     req.GetRequestStream().Close();
 
@@ -1378,7 +1429,7 @@
             try
             {
                 System.Net.WebRequest req = m_reqBuilder.UpdateRepository(resourceId, this.SerializeObject(header));
-                req.Credentials = m_wc.Credentials;
+                req.Credentials = _cred;
                 req.GetRequestStream().Flush();
                 req.GetRequestStream().Close();
 
@@ -1470,17 +1521,13 @@
 
         public override void Dispose()
         {
-            if (m_featureProviders != null)
-                m_featureProviders = null;
+            lock (SyncRoot)
+            {
+                if (m_featureProviders != null)
+                    m_featureProviders = null;
 
-            if (m_cachedProviderCapabilities != null)
-                m_cachedProviderCapabilities = null;
-
-            if (m_wc != null)
-            {
-                try { m_wc.Dispose(); }
-                catch { }
-                m_wc = null;
+                if (m_cachedProviderCapabilities != null)
+                    m_cachedProviderCapabilities = null;
             }
         }
 
@@ -1492,7 +1539,7 @@
             if (mAnonymousUser)
                 req = m_reqBuilder.GetTileAnonymous(mapdefinition, baselayergroup, row, col, scaleindex, format);
             else
-                req = m_reqBuilder.GetTile(mapdefinition, baselayergroup, row, col, scaleindex, format, m_wc.Credentials == null);
+                req = m_reqBuilder.GetTile(mapdefinition, baselayergroup, row, col, scaleindex, format, _cred == null);
             return this.OpenRead(req);
         }
 



More information about the mapguide-commits mailing list