[mapguide-commits] r4949 - in sandbox/maestro-2.5: . Maestro OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Native OSGeo.MapGuide.MaestroAPI.Native/Mapping OSGeo.MapGuide.MaestroAPI.Native/Properties

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jun 16 10:07:54 EDT 2010


Author: jng
Date: 2010-06-16 14:07:53 +0000 (Wed, 16 Jun 2010)
New Revision: 4949

Added:
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Commands/
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCapabilities.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCategory.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeFeatureSetReader.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Mapping/
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Mapping/Selection.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-1.2.0.csproj
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.0.2.csproj
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.1.0.csproj
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.2.0.csproj
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Properties/
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Properties/AssemblyInfo-2.2.0.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Utility.cs
Removed:
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native-2.1.0/
Modified:
   sandbox/maestro-2.5/Maestro/Maestro.sln
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
   sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ServerConnectionBase.cs
Log:
This is the initial submission of the Native impl of the MaestroAPI, most of it was copy/pasted straight from the 2.1 version with some minor changes to fit the 2.5 API. 

This currently target MGOS 2.2 as that is the only thing I have on this box. This project will not build as I have not yet acquired all the needed versions of the MapGuide API assemblies that I want to target (1.2, 2.0.2, 2.1, 2.2)

Modified: sandbox/maestro-2.5/Maestro/Maestro.sln
===================================================================
--- sandbox/maestro-2.5/Maestro/Maestro.sln	2010-06-16 13:12:09 UTC (rev 4948)
+++ sandbox/maestro-2.5/Maestro/Maestro.sln	2010-06-16 14:07:53 UTC (rev 4949)
@@ -55,6 +55,14 @@
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaestroBaseTests", "..\MaestroBaseTests\MaestroBaseTests.csproj", "{CE5F281C-0162-4832-87BB-A677D13D116F}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSGeo.MapGuide.MaestroAPI.Native-1.2.0", "..\OSGeo.MapGuide.MaestroAPI.Native\OSGeo.MapGuide.MaestroAPI.Native-1.2.0.csproj", "{E9BDFC13-1555-4050-869C-D2C44B7ED447}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSGeo.MapGuide.MaestroAPI.Native-2.1.0", "..\OSGeo.MapGuide.MaestroAPI.Native\OSGeo.MapGuide.MaestroAPI.Native-2.1.0.csproj", "{AF9E8895-0B12-4265-B3C9-89E319B49E70}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSGeo.MapGuide.MaestroAPI.Native-2.2.0", "..\OSGeo.MapGuide.MaestroAPI.Native\OSGeo.MapGuide.MaestroAPI.Native-2.2.0.csproj", "{F4420153-9DF3-4407-AD65-E8ABED2B6E25}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSGeo.MapGuide.MaestroAPI.Native-2.0.2", "..\OSGeo.MapGuide.MaestroAPI.Native\OSGeo.MapGuide.MaestroAPI.Native-2.0.2.csproj", "{A6F27323-28A7-4F65-A54A-337B09962C0F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -141,6 +149,22 @@
 		{CE5F281C-0162-4832-87BB-A677D13D116F}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CE5F281C-0162-4832-87BB-A677D13D116F}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{CE5F281C-0162-4832-87BB-A677D13D116F}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E9BDFC13-1555-4050-869C-D2C44B7ED447}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E9BDFC13-1555-4050-869C-D2C44B7ED447}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E9BDFC13-1555-4050-869C-D2C44B7ED447}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E9BDFC13-1555-4050-869C-D2C44B7ED447}.Release|Any CPU.Build.0 = Release|Any CPU
+		{AF9E8895-0B12-4265-B3C9-89E319B49E70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{AF9E8895-0B12-4265-B3C9-89E319B49E70}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{AF9E8895-0B12-4265-B3C9-89E319B49E70}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{AF9E8895-0B12-4265-B3C9-89E319B49E70}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F4420153-9DF3-4407-AD65-E8ABED2B6E25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F4420153-9DF3-4407-AD65-E8ABED2B6E25}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F4420153-9DF3-4407-AD65-E8ABED2B6E25}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F4420153-9DF3-4407-AD65-E8ABED2B6E25}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A6F27323-28A7-4F65-A54A-337B09962C0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A6F27323-28A7-4F65-A54A-337B09962C0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A6F27323-28A7-4F65-A54A-337B09962C0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A6F27323-28A7-4F65-A54A-337B09962C0F}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -158,6 +182,10 @@
 		{CFD19053-2172-41D3-8460-0FD2123A1E88} = {CCF50F7F-DD89-41C1-843C-1BFA2375EEE0}
 		{5AD2CDBA-952E-4148-98A1-31D2E0D540D5} = {CCF50F7F-DD89-41C1-843C-1BFA2375EEE0}
 		{07588440-5F9F-4C30-AA06-9CF30BA6DDE6} = {CCF50F7F-DD89-41C1-843C-1BFA2375EEE0}
+		{E9BDFC13-1555-4050-869C-D2C44B7ED447} = {FCC83861-96C6-43CA-B33B-DB1D0DEC8E79}
+		{AF9E8895-0B12-4265-B3C9-89E319B49E70} = {FCC83861-96C6-43CA-B33B-DB1D0DEC8E79}
+		{F4420153-9DF3-4407-AD65-E8ABED2B6E25} = {FCC83861-96C6-43CA-B33B-DB1D0DEC8E79}
+		{A6F27323-28A7-4F65-A54A-337B09962C0F} = {FCC83861-96C6-43CA-B33B-DB1D0DEC8E79}
 		{B5EA049C-6AB7-4686-A2F4-4BA2EAC0E585} = {81BF310C-0BBC-41F0-ADA5-B201D9769AFC}
 		{EDDB0F74-6FE7-4969-80B0-817A629722CD} = {81BF310C-0BBC-41F0-ADA5-B201D9769AFC}
 		{AC5068F6-CFBE-4BCD-B68B-062725E424D4} = {81BF310C-0BBC-41F0-ADA5-B201D9769AFC}

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ServerConnectionBase.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ServerConnectionBase.cs	2010-06-16 13:12:09 UTC (rev 4948)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI/ServerConnectionBase.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -1232,24 +1232,6 @@
 		abstract public bool IsSessionExpiredException(Exception ex);
 
 		/// <summary>
-		/// Returns the avalible application templates on the server
-		/// </summary>
-		/// <returns>The avalible application templates on the server</returns>
-        abstract public AppDef.ApplicationDefinitionTemplateInfoSet GetApplicationTemplates();
-
-		/// <summary>
-		/// Returns the avalible application widgets on the server
-		/// </summary>
-		/// <returns>The avalible application widgets on the server</returns>
-        abstract public AppDef.ApplicationDefinitionWidgetInfoSet GetApplicationWidgets();
-
-		/// <summary>
-		/// Returns the avalible widget containers on the server
-		/// </summary>
-		/// <returns>The avalible widget containers on the server</returns>
-        abstract public AppDef.ApplicationDefinitionContainerInfoSet GetApplicationContainers();
-
-		/// <summary>
 		/// Returns the spatial info for a given featuresource
 		/// </summary>
 		/// <param name="resourceID">The ID of the resource to query</param>

Modified: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-06-16 13:12:09 UTC (rev 4948)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -1063,7 +1063,7 @@
 		/// Returns the avalible application templates on the server
 		/// </summary>
 		/// <returns>The avalible application templates on the server</returns>
-		public override ApplicationDefinitionTemplateInfoSet GetApplicationTemplates()
+		public ApplicationDefinitionTemplateInfoSet GetApplicationTemplates()
 		{
 			//TODO: Caching these should be safe
 			return (ApplicationDefinitionTemplateInfoSet)base.DeserializeObject(typeof(ApplicationDefinitionTemplateInfoSet), this.OpenRead(m_reqBuilder.EnumerateApplicationTemplates()));
@@ -1073,7 +1073,7 @@
 		/// Returns the avalible application widgets on the server
 		/// </summary>
 		/// <returns>The avalible application widgets on the server</returns>
-		public override ApplicationDefinitionWidgetInfoSet GetApplicationWidgets()
+		public ApplicationDefinitionWidgetInfoSet GetApplicationWidgets()
 		{
 			//TODO: Caching these should be safe
 			return (ApplicationDefinitionWidgetInfoSet)base.DeserializeObject(typeof(ApplicationDefinitionWidgetInfoSet), this.OpenRead(m_reqBuilder.EnumerateApplicationWidgets()));
@@ -1083,7 +1083,7 @@
 		/// Returns the avalible widget containers on the server
 		/// </summary>
 		/// <returns>The avalible widget containers on the server</returns>
-		public override ApplicationDefinitionContainerInfoSet GetApplicationContainers()
+		public ApplicationDefinitionContainerInfoSet GetApplicationContainers()
 		{
 			//TODO: Caching these should be safe
 			return (ApplicationDefinitionContainerInfoSet)base.DeserializeObject(typeof(ApplicationDefinitionContainerInfoSet), this.OpenRead(m_reqBuilder.EnumerateApplicationContainers()));

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCapabilities.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCapabilities.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCapabilities.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,63 @@
+#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.Services;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeCapabilities : IConnectionCapabilities
+    {
+        public Version GetMaxSupportedResourceVersion(ResourceTypes resourceType)
+        {
+            throw new NotImplementedException();
+        }
+
+        public bool IsMultithreaded
+        {
+            get { return false; }
+        }
+
+        public int[] SupportedCommands
+        {
+            get
+            {
+                return new int[0];
+            }
+        }
+
+        public int[] SupportedServices
+        {
+            get
+            {
+                return new int[] {
+                        (int)ServiceType.Resource,
+                        (int)ServiceType.Feature,
+                };
+            }
+        }
+
+        public bool SupportsResourcePreviews
+        {
+            get { return false; }
+        }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,925 @@
+#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.ObjectModels.Common;
+using System.Collections.Specialized;
+using OSGeo.MapGuide.ObjectModels.Capabilities;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
+using OSGeo.MapGuide.ObjectModels.MapDefinition;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
+using System.IO;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.MaestroAPI.Serialization;
+using OSGeo.MapGuide.MaestroAPI.Native.Mapping;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeConnection : ServerConnectionBase, 
+                                         IServerConnection,
+                                         IFeatureService,
+                                         IResourceService
+    {
+        private OSGeo.MapGuide.MgSiteConnection m_con;
+        private string m_locale;
+        private string m_sessionId;
+        private Version m_siteVersion = null;
+
+        public const string PARAM_SESSION = "SessionId";
+        public const string PARAM_CONFIG = "ConfigFile";
+        public const string PARAM_USERNAME = "Username";
+        public const string PARAM_PASSWORD = "Password";
+        public const string PARAM_LOCALE = "Locale";
+
+        private LocalNativeConnection()
+            : base()
+        {
+        }
+
+        //This is the constructor used by ConnectionProviderRegistry.CreateConnection
+
+        internal LocalNativeConnection(NameValueCollection initParams)
+            : this()
+        {
+            if (initParams[PARAM_SESSION] != null)
+            {
+                string sessionid = initParams[PARAM_SESSION];
+
+                InitConnection(sessionid);
+            }
+            else
+            {
+                if (initParams[PARAM_CONFIG] == null)
+                    throw new ArgumentException("Missing connection parameter: " + PARAM_CONFIG);
+                if (initParams[PARAM_PASSWORD] == null)
+                    throw new ArgumentException("Missing connection parameter: " + PARAM_PASSWORD);
+                if (initParams[PARAM_USERNAME] == null)
+                    throw new ArgumentException("Missing connection parameter: " + PARAM_USERNAME);
+
+                string configFile = initParams[PARAM_CONFIG];
+                string password = initParams[PARAM_PASSWORD];
+                string username = initParams[PARAM_USERNAME];
+                string locale = null;
+                if (initParams[PARAM_LOCALE] != null)
+                    locale = initParams[PARAM_LOCALE];
+
+                InitConnection(configFile, username, password, locale);
+            }
+        }
+
+        private void InitConnection(string sessionid)
+        {
+            MgUserInformation mgui = new MgUserInformation(sessionid);
+            m_con = new MgSiteConnection();
+            m_con.Open(mgui);
+            m_sessionId = sessionid;
+        }
+
+        private void InitConnection(string configFile, string username, string password, string locale)
+        {
+            m_username = username;
+            m_password = password;
+            m_locale = locale;
+
+            OSGeo.MapGuide.MapGuideApi.MgInitializeWebTier(configFile);
+            //Throws an exception if it fails
+            RestartSession();
+        }
+
+        // <summary>
+        /// Returns a working copy of the site connection.
+        /// </summary>
+        private MgSiteConnection Connection
+        {
+            get
+            {
+                //It seems that the connection 'forgets' that it is logged in.
+                if (string.IsNullOrEmpty(m_con.GetSite().GetCurrentSession()))
+                    m_con.Open(new MgUserInformation(this.SessionID));
+                return m_con;
+            }
+        }
+
+       public override string SessionID
+		{
+			get
+			{
+				return m_sessionId;
+			}
+		}
+
+		public ResourceList RepositoryResources
+		{
+			get
+			{
+				return GetRepositoryResources();
+			}
+		}
+
+		public override ResourceList GetRepositoryResources(string startingpoint, string type, int depth, bool computeChildren)
+		{
+			if (type == null)
+				type = "";
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			System.Reflection.MethodInfo mi = res.GetType().GetMethod("EnumerateResources", new Type[] { typeof(MgResourceIdentifier), typeof(int), typeof(string), typeof(bool) });
+			return (ResourceList) base.DeserializeObject(typeof(ResourceList), Utility.MgStreamToNetStream(res, mi, new object[] {new MgResourceIdentifier(startingpoint), depth, type, computeChildren }));
+		}
+
+		public override FeatureProviderRegistryFeatureProvider[] FeatureProviders
+		{
+			get
+			{
+				MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+                var reg = (FeatureProviderRegistry)base.DeserializeObject(typeof(FeatureProviderRegistry), Utility.MgStreamToNetStream(fes, fes.GetType().GetMethod("GetFeatureProviders"), new object[] { }));
+                return reg.FeatureProvider.ToArray();
+			}
+		}
+
+		public string TestConnection(string providername, System.Collections.Specialized.NameValueCollection parameters)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			System.Text.StringBuilder sb = new System.Text.StringBuilder();
+			if (parameters != null)
+			{
+				foreach(System.Collections.DictionaryEntry de in parameters)
+					sb.Append((string)de.Key + "=" + (string)de.Value + "\t");
+				if (sb.Length > 0)
+					sb.Length--;
+			}
+			return fes.TestConnection(providername, sb.ToString()) ? "True" : "Unspecified errors";
+		}
+
+		public override string TestConnection(string featuresource)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			return fes.TestConnection(new MgResourceIdentifier(featuresource)) ? "True" : "Unspecified errors";
+		}
+
+		public void DescribeSchema()
+		{
+			throw new MissingMethodException();
+		}
+
+
+		public FdoProviderCapabilities GetProviderCapabilities(string provider)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			return (FdoProviderCapabilities) base.DeserializeObject(typeof(FdoProviderCapabilities), Utility.MgStreamToNetStream(fes, fes.GetType().GetMethod("GetCapabilities"), new object[] { provider }));
+		}
+
+		public override System.IO.MemoryStream GetResourceData(string resourceID, string dataname)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			return Utility.MgStreamToNetStream(res, res.GetType().GetMethod("GetResourceData"), new object[] { new MgResourceIdentifier(resourceID), dataname });
+		}
+
+
+		public override Stream GetResourceXmlData(string resourceID)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+            return Utility.MgStreamToNetStream(res, res.GetType().GetMethod("GetResourceContent"), new object[] { new MgResourceIdentifier(resourceID) });
+		}
+
+        //public override FeatureProviderRegistryFeatureProvider GetFeatureProvider(string providername)
+        //{
+        //    MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+        //    System.IO.MemoryStream ms = Utility.MgStreamToNetStream(fes, fes.GetType().GetMethod("GetCapabilities"), new object[] { providername });
+        //    return (FeatureProviderRegistryFeatureProvider)DeserializeObject(typeof(FeatureProviderRegistryFeatureProvider), ms);
+        //}
+
+		public System.IO.Stream GetMapDWF(string resourceID)
+		{
+			throw new MissingMethodException();
+		}
+
+		public override void SetResourceXmlData(string resourceid, System.IO.Stream content, System.IO.Stream header)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+
+            byte[] bufHeader = header == null ? new byte[0] : Utility.StreamAsArray(header);
+            byte[] bufContent = content == null ? new byte[0] : Utility.StreamAsArray(content);
+            MgByteReader rH = bufHeader.Length == 0 ? null : new MgByteReader(bufHeader, bufHeader.Length, "text/xml");
+            MgByteReader rC = bufContent.Length == 0 ? null : new MgByteReader(bufContent, bufContent.Length, "text/xml");
+            res.SetResource(new MgResourceIdentifier(resourceid), rC, rH);
+		}
+
+        public FeatureSetReader ExecuteSqlQuery(string featureSourceID, string sql)
+        {
+            MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+            MgSqlDataReader reader = fes.ExecuteSqlQuery(new MgResourceIdentifier(featureSourceID), sql);
+            return new LocalNativeFeatureSetReader(reader);
+        }
+
+		public FeatureSetReader QueryFeatureSource(string resourceID, string schema, string query)
+		{
+			return QueryFeatureSource(resourceID, schema, query, null);
+		}
+
+		public FeatureSetReader QueryFeatureSource(string resourceID, string schema)
+		{
+			return QueryFeatureSource(resourceID, schema, null, null);
+		}
+
+        public FeatureSetReader QueryFeatureSource(string resourceID, string schema, string query, string[] columns)
+        {
+            return QueryFeatureSource(resourceID, schema, query, columns, null);
+        }
+
+		public FeatureSetReader QueryFeatureSource(string resourceID, string schema, string query, string[] columns, System.Collections.Specialized.NameValueCollection computedProperties)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			MgFeatureQueryOptions mgf = new MgFeatureQueryOptions();
+			if (query != null)
+				mgf.SetFilter(query);
+
+			if (columns != null && columns.Length != 0)
+				foreach(string s in columns)
+					mgf.AddFeatureProperty(s);
+
+            if (computedProperties != null && computedProperties.Count > 0)
+                foreach (string s in computedProperties.Keys)
+                    mgf.AddComputedProperty(s, computedProperties[s]);
+
+            MgReader mr = fes.SelectFeatures(new MgResourceIdentifier(resourceID), schema, mgf);
+
+            
+
+   			return new LocalNativeFeatureSetReader(mr);
+		}
+
+        private FeatureSetReader AggregateQueryFeatureSourceCore(string resourceID, string schema, string query, string[] columns, System.Collections.Specialized.NameValueCollection computedProperties)
+        {
+            MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+            MgFeatureAggregateOptions mgf = new MgFeatureAggregateOptions();
+            if (query != null)
+                mgf.SetFilter(query);
+
+            if (columns != null && columns.Length != 0)
+                foreach (string s in columns)
+                    mgf.AddFeatureProperty(s);
+
+            if (computedProperties != null && computedProperties.Count > 0)
+                foreach (string s in computedProperties.Keys)
+                    mgf.AddComputedProperty(s, computedProperties[s]);
+
+            return new LocalNativeFeatureSetReader(fes.SelectAggregate(new MgResourceIdentifier(resourceID), schema, mgf));
+        }
+
+        public override FeatureSetReader AggregateQueryFeatureSource(string resourceID, string schema, string filter, string[] columns)
+        {
+            return AggregateQueryFeatureSourceCore(resourceID, schema, filter, columns, null);
+        }
+
+        public override FeatureSetReader AggregateQueryFeatureSource(string resourceID, string schema, string filter, System.Collections.Specialized.NameValueCollection aggregateFunctions)
+        {
+            return AggregateQueryFeatureSourceCore(resourceID, schema, filter, null, aggregateFunctions);
+        }
+
+
+		public override FeatureSourceDescription DescribeFeatureSource(string resourceID)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(fes.DescribeSchemaAsXml(new MgResourceIdentifier(resourceID), "")));
+			return new FeatureSourceDescription(ms);
+		}
+
+		public override FeatureSourceDescription DescribeFeatureSource(string resourceID, string schema)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+            if (schema != null && schema.IndexOf(":") > 0)
+                schema = schema.Split(':')[0];
+			System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(fes.DescribeSchemaAsXml(new MgResourceIdentifier(resourceID), schema)));
+			return new FeatureSourceDescription(ms);
+		}
+
+		public override void CreateRuntimeMap(string resourceID, string mapdefinition)
+		{
+            string mapname = new ResourceIdentifier(resourceID).Path;
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			MgMap map = new MgMap();
+			map.Create(res, new MgResourceIdentifier(mapdefinition), mapname);
+			map.Save(res, new MgResourceIdentifier(resourceID));
+        
+            //Grrr... This does not happen automatically, even though it is required!
+            MgSelection sel = new MgSelection(map);
+            sel.Save(res, mapname);
+        }
+
+		public void CreateRuntimeMap(string resourceID, MapDefinition map)
+		{
+			ResourceIdentifier guid = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.MapDefinition, this.SessionID);
+			try
+			{
+				SaveResourceAs(map, guid);
+				CreateRuntimeMap(resourceID, guid);
+			}
+			finally
+			{
+				try { DeleteResource(guid); }
+				catch { }
+			}
+		}
+
+		public void SaveRuntimeMap(string resourceID, RuntimeMapBase map)
+		{
+			System.IO.MemoryStream ms = new System.IO.MemoryStream();
+			System.IO.MemoryStream ms2 = null;
+
+			//Apparently the name is used to reconstruct the resourceId rather than pass it around
+			//inside the map server
+			string r = map.Name;
+			string t = map.ResourceID;
+
+			string mapname = resourceID.Substring(resourceID.IndexOf("//") + 2);
+			mapname = mapname.Substring(0, mapname.LastIndexOf("."));
+			map.Name = mapname;
+			map.ResourceID = resourceID;
+
+			try
+			{
+				map.Serialize(new MgBinarySerializer(ms, this.SiteVersion));
+				if (this.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
+				{
+					ms2 = new System.IO.MemoryStream();
+					map.SerializeLayerData(new MgBinarySerializer(ms2, this.SiteVersion));
+				}
+
+				SetResourceData(resourceID, "RuntimeData", ResourceDataType.Stream, ms);
+				if (ms2 != null)
+					SetResourceData(resourceID, "LayerGroupData", ResourceDataType.Stream, ms2);
+
+                if (map.HasLoadedSelectionXml)
+                    SetSelectionXml(resourceID, map.Selection.ToXml());
+			}
+			finally
+			{
+				map.Name = r;
+				map.ResourceID = t;
+			}
+		}
+
+		public void DeleteResourceData(string resourceID, string dataname)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.DeleteResourceData(new MgResourceIdentifier(resourceID), dataname);
+		}
+
+		public ResourceDataList EnumerateResourceData(string resourceID)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			System.IO.MemoryStream ms = Utility.MgStreamToNetStream(res, res.GetType().GetMethod("EnumerateResourceData"), new object[] { new MgResourceIdentifier(resourceID) });			
+			return (ResourceDataList)DeserializeObject(typeof(ResourceDataList), ms);
+		}
+
+		public override void DeleteResource(string resourceID)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.DeleteResource(new MgResourceIdentifier(resourceID));
+		}
+
+		public void DeleteFolder(string folderPath)
+		{
+			if (!folderPath.EndsWith("/"))
+				folderPath += "/";
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.DeleteResource(new MgResourceIdentifier(folderPath));
+		}
+
+		public RuntimeMapBase GetRuntimeMap(string resourceID)
+		{
+			RuntimeMapBase m = RuntimeMapBase.Deserialize(new MgBinaryDeserializer(this.GetResourceData(resourceID, "RuntimeData"), this.SiteVersion));
+			if (this.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
+				m.DeserializeLayerData(new MgBinaryDeserializer(this.GetResourceData(resourceID, "LayerGroupData"), this.SiteVersion));
+		
+			m.CurrentConnection = this;
+			return m;
+		}
+
+		public override Version SiteVersion
+		{
+			get
+			{
+                if (m_siteVersion != null)
+                    return m_siteVersion;
+
+                try
+                {
+                    MgSite site = m_con.GetSite();
+
+                    MgServerAdmin amd = new MgServerAdmin();
+                    amd.Open(new MgUserInformation(m_sessionId));
+
+                    MgPropertyCollection col = amd.GetInformationProperties();
+
+                    for (int i = 0; i < col.Count; i++)
+                    {
+                        if (col[i].Name == "ServerVersion")
+                        {
+                            m_siteVersion = new Version(((MgStringProperty)col[i]).GetValue());
+                            break;
+                        }
+                    }
+                }
+                catch
+                {
+                }
+
+
+                //Default
+                if (m_siteVersion == null)
+                    m_siteVersion = SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2);
+
+                return m_siteVersion;
+            }
+		}
+
+
+        private ICoordinateSystemCatalog m_coordsys = null;
+        //TODO: Figure out a strategy for cache invalidation 
+        
+        public ICoordinateSystemCatalog CoordinateSystemCatalog
+		{
+            get
+            {
+                if (this.SiteVersion < OSGeo.MapGuide.MaestroAPI.SiteVersions.GetVersion(OSGeo.MapGuide.MaestroAPI.KnownSiteVersions.MapGuideOS1_2))
+                    return null;
+                else
+                {
+                    if (m_coordsys == null)
+                        m_coordsys = new LocalNativeCoordinateSystemCatalog(this);
+                    return m_coordsys;
+                }
+            }
+        }
+
+		public string DisplayName
+		{
+			get
+			{
+				return this.Connection.GetSite().GetCurrentSiteAddress();
+			}
+		}
+
+		public override ResourceReferenceList EnumerateResourceReferences(string resourceid)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			System.IO.MemoryStream ms = Utility.MgStreamToNetStream(res, res.GetType().GetMethod("EnumerateReferences"), new object[] { new MgResourceIdentifier(resourceid) });
+			return (ResourceReferenceList)DeserializeObject(typeof(ResourceReferenceList), ms);
+		}
+
+		public override void CopyResource(string oldpath, string newpath, bool overwrite)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.CopyResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+		}
+
+		public override void CopyFolder(string oldpath, string newpath, bool overwrite)
+		{
+			if (!oldpath.EndsWith("/"))
+				oldpath += "/";
+			if (!newpath.EndsWith("/"))
+				newpath += "/";
+
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.CopyResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+		}
+
+		public override void MoveResource(string oldpath, string newpath, bool overwrite)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.MoveResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+		}
+
+		public override void MoveFolder(string oldpath, string newpath, bool overwrite)
+		{
+			if (!oldpath.EndsWith("/"))
+				oldpath += "/";
+			if (!newpath.EndsWith("/"))
+				newpath += "/";
+
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			res.MoveResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+		}
+
+		public override System.IO.Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format, bool clip)
+		{
+			MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			MgGeometryFactory gf = new MgGeometryFactory();
+
+			string mapname = new ResourceIdentifier(resourceId).Path;
+
+			MgMap map = new MgMap();
+			map.Open(res, mapname);
+			MgSelection sel = new MgSelection(map);
+            //The color accepted by MgColor has alpha as the last value, but the returned has alpha first
+			MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor()));
+
+            //TODO: The render method is missing the overload for the Clip parameter
+            object[] args = new object[] { map, sel, gf.CreateCoordinateXY(x, y), scale, width, height, color, format, true };
+            Type[] types = new Type[] { args[0].GetType(), args[1].GetType(), args[2].GetType(), args[3].GetType(), args[4].GetType(), args[5].GetType(), args[6].GetType(), args[7].GetType(), args[8].GetType() };
+			return Utility.MgStreamToNetStream(rnd, rnd.GetType().GetMethod("RenderMap", types), args);
+		}
+
+        public override System.IO.Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip)
+        {
+            MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
+            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+            MgGeometryFactory gf = new MgGeometryFactory();
+
+            string mapname = new ResourceIdentifier(resourceId).Path;
+
+            MgMap map = new MgMap();
+            map.Open(res, mapname);
+            MgSelection sel = new MgSelection(map);
+            //The color accepted by MgColor has alpha as the last value, but the returned has alpha first
+            MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor()));
+            MgEnvelope env = new MgEnvelope(gf.CreateCoordinateXY(x1, y1), gf.CreateCoordinateXY(x2, y2));
+
+            //TODO: The render is missing the clip param for the extent override method
+
+            object[] args = new object[] { map, sel, env, width, height, color, format };
+            Type[] types = new Type[] { args[0].GetType(), args[1].GetType(), args[2].GetType(), args[3].GetType(), args[4].GetType(), args[5].GetType(), args[6].GetType() };
+            return Utility.MgStreamToNetStream(rnd, rnd.GetType().GetMethod("RenderMap", types), args);
+        }
+
+		public override bool IsSessionExpiredException(Exception ex)
+		{
+			return ex != null && ex.GetType() == typeof(OSGeo.MapGuide.MgSessionExpiredException) ||  ex.GetType() == typeof(OSGeo.MapGuide.MgSessionNotFoundException);
+		}
+
+		/// <summary>
+		/// Returns the spatial info for a given featuresource
+		/// </summary>
+		/// <param name="resourceID">The ID of the resource to query</param>
+		/// <param name="activeOnly">Query only active items</param>
+		/// <returns>A list of spatial contexts</returns>
+		public override FdoSpatialContextList GetSpatialContextInfo(string resourceID, bool activeOnly)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			MgSpatialContextReader rd = fes.GetSpatialContexts(new MgResourceIdentifier(resourceID), activeOnly);
+            return this.DeserializeObject(typeof(FdoSpatialContextList), Utility.MgStreamToNetStream(rd, rd.GetType().GetMethod("ToXml"), null)) as FdoSpatialContextList;
+		}
+
+		/// <summary>
+		/// Gets the names of the identity properties from a feature
+		/// </summary>
+		/// <param name="resourceID">The resourceID for the FeatureSource</param>
+		/// <param name="classname">The classname of the feature, including schema</param>
+		/// <returns>A string array with the found identities</returns>
+		public override string[] GetIdentityProperties(string resourceID, string classname)
+		{
+			MgFeatureService fes = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+			string[] parts = classname.Split(':');
+            MgResourceIdentifier resId = new MgResourceIdentifier(resourceID);
+			MgPropertyDefinitionCollection props;
+		    if (parts.Length == 1)
+				parts = new string[] { classname };
+			else if (parts.Length != 2)
+				throw new Exception("Unable to parse classname into class and schema: " + classname);
+
+            foreach(MgClassDefinition cdef in fes.DescribeSchema(resId, parts[0])[0].GetClasses())
+                if (parts.Length == 1 || cdef.Name.ToLower().Trim().Equals(parts[1].ToLower().Trim()))
+                {
+                    props = cdef.GetIdentityProperties();
+
+                    string[] res = new string[props.Count];
+                    for (int i = 0; i < props.Count; i++)
+                        res[i] = (props[i] as MgProperty).Name;
+
+                    return res;
+                }
+
+            throw new Exception("Unable to find class: " + parts[1] + " in schema " + parts[0]);
+		}
+
+		/// <summary>
+		/// Restarts the server session, and creates a new session ID
+		/// </summary>
+		/// <param name="throwException">If set to true, the call throws an exception if the call failed</param>
+		/// <returns>True if the creation succeed, false otherwise</returns>
+		public override bool RestartSession(bool throwException)
+		{
+			if (m_username == null || m_password == null)
+				if (throwException)
+					throw new Exception("Cannot recreate session, because connection was not opened with username and password");
+				else
+					return false;
+
+			try
+			{
+				MgUserInformation mgui = new MgUserInformation(m_username, m_password);
+				if (m_locale != null)
+					mgui.SetLocale(m_locale);
+				else
+					mgui.SetLocale("en");
+				MgSiteConnection con = new MgSiteConnection(); 
+				con.Open(mgui);
+				string s = con.GetSite().CreateSession();
+				if (s == null || s.Trim().Length == 0)
+					throw new Exception("Failed to retrieve new session identifier");
+
+				m_sessionId = s;
+				m_con = con;
+				return true;
+			}
+			catch
+			{
+				if (throwException)
+					throw;
+				else
+					return false;
+			}
+		}
+
+		/// <summary>
+		/// Sets the selection of a map
+		/// </summary>
+		/// <param name="runtimeMap">The resourceID of the runtime map</param>
+		/// <param name="selectionXml">The selection xml</param>
+		public override void SetSelectionXml(string runtimeMap, string selectionXml)
+		{
+			ResourceIdentifier.Validate(runtimeMap, ResourceTypes.RuntimeMap);
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			MgMap map = new MgMap();
+            string mapname = new ResourceIdentifier(runtimeMap).Path;
+			map.Open(res, mapname);
+			MgSelection sel = string.IsNullOrEmpty(selectionXml) ? new MgSelection(map) : new MgSelection(map, selectionXml);
+			sel.Save(res, mapname);
+		}
+
+		/// <summary>
+		/// Gets the selection from a map
+		/// </summary>
+		/// <param name="runtimeMap">The resourceID of the runtime map</param>
+		/// <returns>The selection xml</returns>
+		public override string GetSelectionXml(string runtimeMap)
+		{
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			MgMap map = new MgMap();
+            string mapname = new ResourceIdentifier(runtimeMap).Path;
+			map.Open(res, mapname);
+			MgSelection sel = new MgSelection(map);
+			return sel.ToXml();
+		}
+
+		/// <summary>
+		/// Enumerates all unmanaged folders, meaning alias'ed folders
+		/// </summary>
+		/// <param name="type">The type of data to return</param>
+		/// <param name="filter">A filter applied to the items</param>
+		/// <param name="recursive">True if the list should contains recursive results</param>
+		/// <param name="startpath">The path to retrieve the data from</param>
+		/// <returns>A list of unmanaged data</returns>
+		public override UnmanagedDataList EnumerateUnmanagedData(string startpath, string filter, bool recursive, UnmanagedDataTypes type)
+		{
+			throw new MissingMethodException();
+		}
+
+        public override string QueryMapFeatures(string runtimemap, string wkt, bool persist, QueryMapFeaturesLayerAttributes attributes, bool raw)
+        {
+            MgRenderingService rs = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService;
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+			MgMap map = new MgMap();
+			string mapname = runtimemap.IndexOf(":") > 0 ? new ResourceIdentifier(runtimemap).Path : runtimemap;
+			map.Open(res, mapname);
+
+            MgWktReaderWriter r = new MgWktReaderWriter();
+            MgFeatureInformation info = rs.QueryFeatures(map, null, r.Read(wkt), (int)MgFeatureSpatialOperations.Intersects, "", -1, (int)attributes);
+
+            string xml = System.Text.Encoding.UTF8.GetString(Utility.MgStreamToNetStream(info, info.GetType().GetMethod("ToXml"), null).ToArray()).Trim();
+
+            if (persist)
+            {
+                MgSelection sel = new MgSelection(map, xml);
+                sel.Save(res, mapname);
+            }
+ 
+            return xml;
+        }
+
+        public override void UpdateRepository(string resourceId, ResourceFolderHeaderType header)
+        {
+            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+
+            if (header == null)
+                res.UpdateRepository(new MgResourceIdentifier(resourceId), null, null);
+            else
+            {
+                byte[] data = this.SerializeObject(header).ToArray();
+                MgByteReader rd = new MgByteReader(data, data.Length, "text/xml");
+                res.UpdateRepository(new MgResourceIdentifier(resourceId), null, rd);
+            }
+        }
+
+        public override object GetFolderOrResourceHeader(string resourceID)
+        {
+			MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+            if (ResourceIdentifier.IsFolderResource(resourceID))
+                return this.DeserializeObject<ResourceFolderHeaderType>(Utility.MgStreamToNetStream(res, res.GetType().GetMethod("GetResourceHeader"), new object[] { new MgResourceIdentifier(resourceID) }));
+            else
+                return this.DeserializeObject<ResourceDocumentHeaderType>(Utility.MgStreamToNetStream(res, res.GetType().GetMethod("GetResourceHeader"), new object[] { new MgResourceIdentifier(resourceID) }));
+        }
+
+
+        /// <summary>
+        /// Gets a list of users in a group
+        /// </summary>
+        /// <param name="group">The group to retrieve the users from</param>
+        /// <returns>The list of users</returns>
+        public override UserList EnumerateUsers(string group)
+        {
+            if (m_cachedUserList == null)
+                m_cachedUserList = this.DeserializeObject<UserList>(Utility.MgStreamToNetStream(this.Connection.GetSite(), this.Connection.GetSite().GetType().GetMethod("EnumerateUsers"), new object[] { group }));
+            return m_cachedUserList;
+        }
+
+        /// <summary>
+        /// Gets a list of all groups on the server
+        /// </summary>
+        /// <returns>The list of groups</returns>
+        public override GroupList EnumerateGroups()
+        {
+            if (m_cachedGroupList == null)
+                m_cachedGroupList = this.DeserializeObject<GroupList>(Utility.MgStreamToNetStream(this.Connection.GetSite(), this.Connection.GetSite().GetType().GetMethod("EnumerateGroups"), null));
+            return m_cachedGroupList;
+        }
+
+        public override System.IO.Stream GetTile(string mapdefinition, string baselayergroup, int col, int row, int scaleindex, string format)
+        {
+            MgTileService ts = this.Connection.CreateService(MgServiceType.TileService) as MgTileService;
+
+            Type[] types = new Type[] { typeof(MgResourceIdentifier), typeof(string), typeof(int), typeof(int), typeof(int) };
+
+            return Utility.MgStreamToNetStream(ts, ts.GetType().GetMethod("GetTile", types), new object[] { new MgResourceIdentifier(mapdefinition), baselayergroup, col, row, scaleindex });
+            //ts.GetTile(new MgResourceIdentifier(mapdefinition), baselayergroup, col, row, scaleindex)
+        }
+
+        public override bool ResourceExists(string resourceid)
+        {
+            try
+            {
+                MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+                return res.ResourceExists(new MgResourceIdentifier(resourceid));
+            }
+            catch (Exception ex)
+            {
+                try { return base.ResourceExists(resourceid); }
+                catch { throw ex; } //Throw original error
+            }
+            
+        }
+
+        public string[] GetConnectionPropertyValues(string providerName, string propertyName, string partialConnectionString)
+        {
+            MgFeatureService featSvc = this.Connection.CreateService(MgServiceType.FeatureService) as MgFeatureService;
+            MgStringCollection result = featSvc.GetConnectionPropertyValues(providerName, propertyName, partialConnectionString);
+            string[] values = new string[result.GetCount()];
+            for (int i = 0; i < result.GetCount(); i++)
+            {
+                values[i] = result.GetItem(i);
+            }
+            return values;
+        }
+
+        public bool SupportsResourcePreviews
+        {
+            get { return false; }
+        }
+
+        public override void Dispose()
+        {
+            if (m_con != null)
+            {
+                m_con.Dispose();
+                m_con = null;
+            }
+        }
+
+        /// <summary>
+        /// Renders a minature bitmap of the layers style
+        /// </summary>
+        /// <param name="scale">The scale for the bitmap to match</param>
+        /// <param name="layerdefinition">The layer the image should represent</param>
+        /// <param name="themeIndex">If the layer is themed, this gives the theme index, otherwise set to 0</param>
+        /// <param name="type">The geometry type, 1 for point, 2 for line, 3 for area, 4 for composite</param>
+        /// <returns>The minature bitmap</returns>
+        public override System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type)
+        {
+            MgMappingService ms = this.Connection.CreateService(MgServiceType.MappingService) as MgMappingService;
+            MgResourceIdentifier ldef = new MgResourceIdentifier(layerdefinition);
+
+            return new System.Drawing.Bitmap(Utility.MgStreamToNetStream(ms, ms.GetType().GetMethod("GenerateLegendImage"), new object[] { ldef, scale, 16, 16, "PNG", type, themeIndex }));
+        }
+
+        public OSGeo.MapGuide.MaestroAPI.Services.IFeatureService FeatureService
+        {
+            get { return this; }
+        }
+
+        public OSGeo.MapGuide.MaestroAPI.Services.IResourceService ResourceService
+        {
+            get { return this; }
+        }
+
+        public OSGeo.MapGuide.MaestroAPI.Commands.ICommand CreateCommand(int commandType)
+        {
+            throw new NotImplementedException();
+        }
+
+        private IConnectionCapabilities _caps;
+
+        public IConnectionCapabilities Capabilities
+        {
+            get 
+            {
+                if (_caps == null)
+                {
+                    _caps = new LocalNativeCapabilities();
+                }
+                return _caps;
+            }
+        }
+
+        public OSGeo.MapGuide.MaestroAPI.Services.IService GetService(int serviceType)
+        {
+            throw new NotImplementedException();
+        }
+
+        protected override IServerConnection GetInterface()
+        {
+            return this;
+        }
+
+        public override void SetResourceData(string resourceid, string dataname, ResourceDataType datatype, Stream stream, OSGeo.MapGuide.MaestroAPI.Utility.StreamCopyProgressDelegate callback)
+        {
+            byte[] data = Utility.StreamAsArray(stream);
+            if (callback != null)
+                callback(0, data.Length, data.Length);
+            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+            MgByteReader reader = new MgByteReader(data, data.Length, "binary/octet-stream");
+            res.SetResourceData(new MgResourceIdentifier(resourceid), dataname, datatype.ToString(), reader);
+
+            if (callback != null)
+                callback(data.Length, 0, data.Length);
+        }
+
+        public override void UploadPackage(string filename, OSGeo.MapGuide.MaestroAPI.Utility.StreamCopyProgressDelegate callback)
+        {
+            System.IO.FileInfo fi = new System.IO.FileInfo(filename);
+
+            if (callback != null)
+                callback(0, fi.Length, fi.Length);
+
+            MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
+            MgByteSource pkgSource = new MgByteSource(filename);
+            MgByteReader rd = pkgSource.GetReader();
+            res.ApplyResourcePackage(rd);
+            rd.Dispose();
+
+
+            if (callback != null)
+                callback(fi.Length, 0, fi.Length);
+        }
+
+        public override string[] GetCustomPropertyNames()
+        {
+            throw new NotImplementedException();
+        }
+
+        public override Type GetCustomPropertyType(string name)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override void SetCustomProperty(string name, object value)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override object GetCustomProperty(string name)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,67 @@
+#region Disclaimer / License
+// Copyright (C) 2009, Kenneth Skovhede
+// http://www.hexad.dk, opensource at hexad.dk
+// 
+// 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;
+using System.Collections.Generic;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeCoordinateSystem : CoordinateSystemBase
+    {
+        internal LocalNativeCoordinateSystem() : base() { }
+
+        internal LocalNativeCoordinateSystem(CoordinateSystemCategory parent, MgPropertyCollection props)
+            : base(parent)
+        {
+            for (int i = 0; i < props.Count; i++)
+            {
+                switch (props[i].Name.ToLower())
+                {
+                    case "code":
+                        m_code = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "description":
+                        m_description = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "projection":
+                        m_projection = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "projection description":
+                        m_projectionDescription = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "Datum":
+                        m_datum = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "datum description":
+                        m_datumDescription = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "ellipsoid":
+                        m_ellipsoid = (props[i] as MgStringProperty).Value;
+                        break;
+                    case "ellipsoid description":
+                        m_ellipsoidDescription = (props[i] as MgStringProperty).Value;
+                        break;
+                }
+            }
+        }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,123 @@
+#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.CoordinateSystem;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeCoordinateSystemCatalog : CoordinateSystemCatalog
+    {
+        private LocalNativeConnection m_con;
+        private CoordinateSystemCategory[] m_categories;
+        private string m_coordLib = null;
+        internal OSGeo.MapGuide.MgCoordinateSystemFactory m_cf;
+
+        internal LocalNativeCoordinateSystemCatalog(LocalNativeConnection con)
+        {
+            m_con = con;
+            m_cf = new MgCoordinateSystemFactory();
+        }
+
+        public override CoordinateSystemCategory[] Categories
+        {
+            get
+            {
+                if (m_categories == null)
+                {
+                    MgStringCollection c = m_cf.EnumerateCategories();
+                    CoordinateSystemCategory[] data = new CoordinateSystemCategory[c.GetCount()];
+
+                    for (int i = 0; i < c.GetCount(); i++)
+                        data[i] = new LocalNativeCoordinateSystemCategory(this, c.GetItem(i));
+                    m_categories = data;
+                }
+
+                return m_categories;
+            }
+        }
+
+        public override string ConvertCoordinateSystemCodeToWkt(string coordcode)
+        {
+            return m_cf.ConvertCoordinateSystemCodeToWkt(coordcode);
+        }
+
+        public override string ConvertEpsgCodeToWkt(string epsg)
+        {
+            return m_cf.ConvertEpsgCodeToWkt(int.Parse(epsg));
+        }
+
+        public override string ConvertWktToCoordinateSystemCode(string wkt)
+        {
+            return m_cf.ConvertWktToCoordinateSystemCode(wkt);
+        }
+
+        public override string ConvertWktToEpsgCode(string wkt)
+        {
+            return m_cf.ConvertWktToEpsgCode(wkt).ToString();
+        }
+
+        public override bool IsValid(string wkt)
+        {
+            return m_cf.IsValid(wkt);
+        }
+
+        public override string LibraryName
+        {
+            get
+            {
+                if (m_coordLib == null)
+                    m_coordLib = m_cf.GetBaseLibrary();
+                return m_coordLib;
+            }
+        }
+
+        public override bool IsLoaded { get { return m_categories != null; } }
+
+        public override CoordinateSystemBase[] EnumerateCoordinateSystems(string category)
+        {
+            CoordinateSystemCategory cat = null;
+            foreach (CoordinateSystemCategory csc in this.Categories)
+            {
+                if (csc.Name == category)
+                {
+                    cat = csc;
+                    break;
+                }
+            }
+
+            if (cat == null)
+                return new CoordinateSystemBase[0];
+
+            MgBatchPropertyCollection bp = m_cf.EnumerateCoordinateSystems(category);
+            List<CoordinateSystemBase> lst = new List<CoordinateSystemBase>();
+            for (int i = 0; i < bp.Count; i++)
+                lst.Add(new LocalNativeCoordinateSystem(cat, bp[i]));
+
+            return lst.ToArray();
+        }
+
+        public override CoordinateSystemBase CreateEmptyCoordinateSystem()
+        {
+            return new LocalNativeCoordinateSystem();
+        }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCategory.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCategory.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCategory.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,31 @@
+#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.CoordinateSystem;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeCoordinateSystemCategory : CoordinateSystemCategory
+    {
+        public LocalNativeCoordinateSystemCategory(ICoordinateSystemCatalog parent, string name) : base(parent, name) { }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeFeatureSetReader.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeFeatureSetReader.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeFeatureSetReader.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,200 @@
+#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.Exceptions;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public class LocalNativeFeatureSetReader : FeatureSetReader
+    {
+        private OSGeo.MapGuide.MgReader m_rd;
+
+        public LocalNativeFeatureSetReader(OSGeo.MapGuide.MgReader mr)
+            : base()
+        {
+            m_rd = mr;
+
+            FeatureSetColumn[] cols = new FeatureSetColumn[mr.GetPropertyCount()];
+            for (int i = 0; i < cols.Length; i++)
+                cols[i] = new LocalNativeFeatureSetColumn(mr.GetPropertyName(i), mr.GetPropertyType(mr.GetPropertyName(i)));
+
+            InitColumns(cols);
+        }
+
+        protected override bool ReadInternal()
+        {
+            return m_rd.ReadNext();
+        }
+
+        protected override FeatureSetRow ProcessFeatureRow()
+        {
+            return new LocalNativeFeatureSetRow(this, m_rd);
+        }
+
+        protected override void CloseInternal()
+        {
+            m_rd.Close();
+        }
+
+        public override int Depth
+        {
+            get
+            {
+                return -1;
+            }
+        }
+
+        public override System.Data.DataTable GetSchemaTable()
+        {
+            throw new NotImplementedException();
+        }
+
+        public override int RecordsAffected
+        {
+            get { throw new NotImplementedException(); }
+        }
+    }
+
+    public class LocalNativeFeatureSetRow : FeatureSetRow
+    {
+        private Topology.IO.MapGuide.MgReader m_mgReader = null;
+
+        private Topology.IO.MapGuide.MgReader MgReader
+        {
+            get
+            {
+                if (m_mgReader == null)
+                {
+                    m_mgReader = new Topology.IO.MapGuide.MgReader();
+                }
+
+                return m_mgReader;
+            }
+        }
+
+        internal LocalNativeFeatureSetRow(FeatureSetReader parent, OSGeo.MapGuide.MgReader rd)
+            : base(parent)
+        {
+            for (int i = 0; i < m_parent.Columns.Length; i++)
+            {
+                string p = m_parent.Columns[i].Name;
+                int ordinal = GetOrdinal(p);
+                m_nulls[ordinal] = rd.IsNull(p);
+
+                if (!m_nulls[ordinal])
+                {
+                    if (parent.Columns[ordinal].Type == typeof(string))
+                        m_items[ordinal] = rd.GetString(p);
+                    else if (parent.Columns[ordinal].Type == typeof(int))
+                        m_items[ordinal] = rd.GetInt32(p);
+                    else if (parent.Columns[ordinal].Type == typeof(long))
+                        m_items[ordinal] = rd.GetInt64(p);
+                    else if (parent.Columns[ordinal].Type == typeof(short))
+                        m_items[ordinal] = rd.GetInt16(p);
+                    else if (parent.Columns[ordinal].Type == typeof(double))
+                        m_items[ordinal] = rd.GetDouble(p);
+                    else if (parent.Columns[ordinal].Type == typeof(float))
+                        m_items[ordinal] = rd.GetSingle(p);
+                    else if (parent.Columns[ordinal].Type == typeof(bool))
+                        m_items[ordinal] = rd.GetBoolean(p);
+                    else if (parent.Columns[ordinal].Type == typeof(DateTime))
+                    {
+                        MgDateTime t = rd.GetDateTime(p);
+                        try
+                        {
+                            m_items[ordinal] = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second);
+                        }
+                        catch (Exception ex)
+                        {
+                            //Unfortunately FDO supports invalid dates, such as the 30th feb
+                            m_nulls[ordinal] = true;
+                            m_items[ordinal] = ex;
+                        }
+                    }
+                    else if (parent.Columns[ordinal].Type == Utility.GeometryType)
+                    {
+                        //TODO: Uncomment this once the Topology.Net API gets updated to 2.0.0
+                        //It is optional to include the Topology.IO.MapGuide dll
+                        /*if (this.MgReader != null)
+                            m_items[ordinal] = this.MgReader.ReadGeometry(ref rd, p);
+                        else*/
+                        {
+                            try
+                            {
+                                //No MapGuide dll, convert to WKT and then to internal representation
+                                System.IO.MemoryStream ms = Utility.MgStreamToNetStream(rd, rd.GetType().GetMethod("GetGeometry"), new string[] { p });
+                                OSGeo.MapGuide.MgAgfReaderWriter rdw = new OSGeo.MapGuide.MgAgfReaderWriter();
+                                OSGeo.MapGuide.MgGeometry g = rdw.Read(rd.GetGeometry(p));
+                                OSGeo.MapGuide.MgWktReaderWriter rdww = new OSGeo.MapGuide.MgWktReaderWriter();
+                                m_items[ordinal] = this.Reader.Read(rdww.Write(g));
+                            }
+                            catch (MgException ex)
+                            {
+                                //Just like the XmlFeatureSetReader, invalid geometry can bite us again
+                                m_nulls[ordinal] = true;
+                                m_items[ordinal] = NestedExceptionMessageProcessor.GetFullMessage(ex);
+                                ex.Dispose();
+                            }
+                        }
+                    }
+                    else if (parent.Columns[ordinal].Type == Utility.UnmappedType)
+                    {
+                        //Attempt to read it as a string
+                        try { m_items[ordinal] = rd.GetString(p); }
+                        catch { m_items[ordinal] = null; }
+                    }
+                    else
+                        throw new Exception("Unknown type: " + parent.Columns[ordinal].Type.FullName);
+                }
+            }
+        }
+
+        public object this[int index]
+        {
+            get
+            {
+                if (index >= m_items.Length)
+                    throw new InvalidOperationException("Index " + index.ToString() + ", was out of bounds");
+                else
+                {
+                    if (m_lazyloadGeometry[index] && !m_nulls[index])
+                    {
+                        m_items[index] = this.Reader.Read((string)m_items[index]);
+                        m_lazyloadGeometry[index] = false;
+                    }
+
+                    return m_items[index];
+                }
+            }
+        }
+    }
+
+    public class LocalNativeFeatureSetColumn : FeatureSetColumn
+    {
+        internal LocalNativeFeatureSetColumn(string name, int type)
+            : base()
+        {
+            m_name = name;
+            m_type = Utility.ConvertMgTypeToNetType(type);
+        }
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Mapping/Selection.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Mapping/Selection.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Mapping/Selection.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,30 @@
+#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.Mapping;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native.Mapping
+{
+    public class Selection : MapSelectionBase
+    {
+    }
+}

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-1.2.0.csproj
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-1.2.0.csproj	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-1.2.0.csproj	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.21022</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{E9BDFC13-1555-4050-869C-D2C44B7ED447}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>OSGeo.MapGuide.MaestroAPI.Native</RootNamespace>
+    <AssemblyName>OSGeo.MapGuide.MaestroAPI.Native-1.2.0</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Topology, Version=1.0.8.24721, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.dll</HintPath>
+    </Reference>
+    <Reference Include="Topology.IO.MapGuide, Version=1.0.8.40022, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.IO.MapGuide.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Utility.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.0.2.csproj
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.0.2.csproj	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.0.2.csproj	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.21022</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{A6F27323-28A7-4F65-A54A-337B09962C0F}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>OSGeo.MapGuide.MaestroAPI.Native</RootNamespace>
+    <AssemblyName>OSGeo.MapGuide.MaestroAPI.Native-1.2.0</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Topology, Version=1.0.8.24721, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.dll</HintPath>
+    </Reference>
+    <Reference Include="Topology.IO.MapGuide, Version=1.0.8.40022, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.IO.MapGuide.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Utility.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.1.0.csproj
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.1.0.csproj	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.1.0.csproj	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.21022</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{AF9E8895-0B12-4265-B3C9-89E319B49E70}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>OSGeo.MapGuide.MaestroAPI.Native</RootNamespace>
+    <AssemblyName>OSGeo.MapGuide.MaestroAPI.Native-1.2.0</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Topology, Version=1.0.8.24721, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.dll</HintPath>
+    </Reference>
+    <Reference Include="Topology.IO.MapGuide, Version=1.0.8.40022, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.IO.MapGuide.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Utility.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.2.0.csproj
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.2.0.csproj	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/OSGeo.MapGuide.MaestroAPI.Native-2.2.0.csproj	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.21022</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{F4420153-9DF3-4407-AD65-E8ABED2B6E25}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>OSGeo.MapGuide.MaestroAPI.Native</RootNamespace>
+    <AssemblyName>OSGeo.MapGuide.MaestroAPI.Native-1.2.0</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="OSGeo.MapGuide.Foundation, Version=1.0.0.1, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\MGAPI\2.2.0\OSGeo.MapGuide.Foundation.dll</HintPath>
+    </Reference>
+    <Reference Include="OSGeo.MapGuide.Geometry, Version=1.0.0.1, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\MGAPI\2.2.0\OSGeo.MapGuide.Geometry.dll</HintPath>
+    </Reference>
+    <Reference Include="OSGeo.MapGuide.MapGuideCommon, Version=1.0.0.1, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\MGAPI\2.2.0\OSGeo.MapGuide.MapGuideCommon.dll</HintPath>
+    </Reference>
+    <Reference Include="OSGeo.MapGuide.PlatformBase, Version=1.0.0.1, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\MGAPI\2.2.0\OSGeo.MapGuide.PlatformBase.dll</HintPath>
+    </Reference>
+    <Reference Include="OSGeo.MapGuide.Web, Version=1.0.0.1, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\MGAPI\2.2.0\OSGeo.MapGuide.Web.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Topology, Version=1.0.8.24721, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.dll</HintPath>
+    </Reference>
+    <Reference Include="Topology.IO.MapGuide, Version=1.0.8.40022, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.IO.MapGuide.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo-2.2.0.cs" />
+    <Compile Include="LocalNativeCapabilities.cs" />
+    <Compile Include="LocalNativeConnection.cs" />
+    <Compile Include="LocalNativeCoordinateSystem.cs" />
+    <Compile Include="LocalNativeCoordinateSystemCatalog.cs" />
+    <Compile Include="LocalNativeCoordinateSystemCategory.cs" />
+    <Compile Include="LocalNativeFeatureSetReader.cs" />
+    <Compile Include="Mapping\Selection.cs" />
+    <Compile Include="Utility.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\OSGeo.MapGuide.MaestroAPI\OSGeo.MapGuide.MaestroAPI.csproj">
+      <Project>{80FA3158-8B5F-48D1-A393-0378AFE48A7E}</Project>
+      <Name>OSGeo.MapGuide.MaestroAPI</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Commands\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Properties/AssemblyInfo-2.2.0.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Properties/AssemblyInfo-2.2.0.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Properties/AssemblyInfo-2.2.0.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,55 @@
+#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.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("OSGeo.MapGuide.MaestroAPI.Native-2.2.0")]
+[assembly: AssemblyDescription("MaestroAPI implementation wrapper for MapGuide Open Source 2.2")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("OSGeo.MapGuide.MaestroAPI.Native-2.2.0")]
+[assembly: AssemblyCopyright("Copyright ©  2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("D80991DF-E4D3-43ee-AF2B-C96AD8462C70")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

Added: sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Utility.cs
===================================================================
--- sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Utility.cs	                        (rev 0)
+++ sandbox/maestro-2.5/OSGeo.MapGuide.MaestroAPI.Native/Utility.cs	2010-06-16 14:07:53 UTC (rev 4949)
@@ -0,0 +1,220 @@
+#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.Drawing;
+
+namespace OSGeo.MapGuide.MaestroAPI.Native
+{
+    public static class Utility
+    {
+        /// <summary>
+        /// Reads all data from a stream, and returns it as a single array.
+        /// Note that this is very inefficient if the stream is several megabytes long.
+        /// </summary>
+        /// <param name="s">The stream to exhaust</param>
+        /// <returns>The streams content as an array</returns>
+        public static byte[] StreamAsArray(System.IO.Stream s)
+        {
+            if (s as System.IO.MemoryStream != null)
+                return ((System.IO.MemoryStream)s).ToArray();
+
+            if (!s.CanSeek)
+            {
+                System.IO.MemoryStream ms = new System.IO.MemoryStream();
+                byte[] buf = new byte[1024];
+                int c;
+                while ((c = s.Read(buf, 0, buf.Length)) > 0)
+                    ms.Write(buf, 0, c);
+                return ms.ToArray();
+            }
+            else
+            {
+                byte[] buf = new byte[s.Length];
+                s.Position = 0;
+                s.Read(buf, 0, buf.Length);
+                return buf;
+            }
+        }
+
+
+        /// <summary>
+        /// Converts a MgStream to a .Net Stream object.
+        /// Due to some swig issues, it is not possible to pass on an MgStream to a function,
+        /// so this function calls a method to retrieve the stream locally.
+        /// </summary>
+        /// <param name="source">The object which has a stream</param>
+        /// <param name="mi">The method to call</param>
+        /// <param name="args">Arguments to the method</param>
+        /// <returns>A memorystream with the MgStream's content</returns>
+        public static System.IO.MemoryStream MgStreamToNetStream(object source, System.Reflection.MethodInfo mi, object[] args)
+        {
+            try
+            {
+                OSGeo.MapGuide.MgByteReader rd = (OSGeo.MapGuide.MgByteReader)mi.Invoke(source, args);
+                System.IO.MemoryStream ms = new System.IO.MemoryStream();
+                byte[] buf = new byte[1024];
+                int c = 0;
+                do
+                {
+                    c = rd.Read(buf, buf.Length);
+                    ms.Write(buf, 0, c);
+                } while (c != 0);
+                ms.Position = 0;
+                return ms;
+            }
+            catch (System.Reflection.TargetInvocationException tex)
+            {
+                if (tex.InnerException != null)
+                    throw tex.InnerException;
+                else
+                    throw;
+            }
+        }
+
+        /// <summary>
+        /// Returns a type used to define a raster column in a feature reader
+        /// </summary>
+        public static Type RasterType
+        {
+            get { return typeof(System.Drawing.Bitmap); }
+        }
+
+        /// <summary>
+        /// Returns the type used to define a geometry column in a feature reader
+        /// </summary>
+        public static Type GeometryType
+        {
+            get { return typeof(Topology.Geometries.IGeometry); }
+        }
+
+        /// <summary>
+        /// Gets the type of an item, given the MapGuide type id
+        /// </summary>
+        /// <param name="MgType">The MapGuide type id</param>
+        /// <returns>The corresponding .Net type</returns>
+        public static Type ConvertMgTypeToNetType(int MgType)
+        {
+            switch (MgType)
+            {
+                case OSGeo.MapGuide.MgPropertyType.Byte:
+                    return typeof(byte);
+                case OSGeo.MapGuide.MgPropertyType.Int16:
+                    return typeof(short);
+                case OSGeo.MapGuide.MgPropertyType.Int32:
+                    return typeof(int);
+                case OSGeo.MapGuide.MgPropertyType.Int64:
+                    return typeof(long);
+                case OSGeo.MapGuide.MgPropertyType.Single:
+                    return typeof(float);
+                case OSGeo.MapGuide.MgPropertyType.Double:
+                    return typeof(double);
+                case OSGeo.MapGuide.MgPropertyType.Boolean:
+                    return typeof(bool);
+                case OSGeo.MapGuide.MgPropertyType.Geometry:
+                    return Utility.GeometryType;
+                case OSGeo.MapGuide.MgPropertyType.String:
+                    return typeof(string);
+                case OSGeo.MapGuide.MgPropertyType.DateTime:
+                    return typeof(DateTime);
+                case OSGeo.MapGuide.MgPropertyType.Raster:
+                    return Utility.RasterType;
+                case OSGeo.MapGuide.MgPropertyType.Blob:
+                    return typeof(byte[]);
+                case OSGeo.MapGuide.MgPropertyType.Clob:
+                    return typeof(byte[]);
+                default:
+                    throw new Exception("Failed to find type for: " + MgType.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Parses a color in HTML notation (ea. #ffaabbff)
+        /// </summary>
+        /// <param name="color">The HTML representation of the color</param>
+        /// <returns>The .Net color structure that matches the color</returns>
+        public static Color ParseHTMLColor(string color)
+        {
+            if (color.Length == 8)
+            {
+                int a = int.Parse(color.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
+                int r = int.Parse(color.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
+                int g = int.Parse(color.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
+                int b = int.Parse(color.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
+
+                return Color.FromArgb(a, r, g, b);
+            }
+            else if (color.Length == 6)
+            {
+                int r = int.Parse(color.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
+                int g = int.Parse(color.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
+                int b = int.Parse(color.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
+
+                return Color.FromArgb(r, g, b);
+            }
+            else
+                throw new Exception("Bad HTML color: \"" + color + "\"");
+        }
+
+        /// <summary>
+        /// Returns a type used to define an unknown column type in a feature reader
+        /// </summary>
+        public static Type UnmappedType
+        {
+            get { return typeof(UnmappedDataType); }
+        }
+
+        /// <summary>
+        /// Gets the MapGuide id for a given type
+        /// </summary>
+        /// <param name="type">The .Net type</param>
+        /// <returns>The corresponding MapGuide type id</returns>
+        public static int ConvertNetTypeToMgType(Type type)
+        {
+            if (type == typeof(short))
+                return OSGeo.MapGuide.MgPropertyType.Int16;
+            else if (type == typeof(byte))
+                return OSGeo.MapGuide.MgPropertyType.Byte;
+            else if (type == typeof(bool))
+                return OSGeo.MapGuide.MgPropertyType.Boolean;
+            else if (type == typeof(int))
+                return OSGeo.MapGuide.MgPropertyType.Int32;
+            else if (type == typeof(long))
+                return OSGeo.MapGuide.MgPropertyType.Int64;
+            else if (type == typeof(float))
+                return OSGeo.MapGuide.MgPropertyType.Single;
+            else if (type == typeof(double))
+                return OSGeo.MapGuide.MgPropertyType.Double;
+            else if (type == Utility.GeometryType)
+                return OSGeo.MapGuide.MgPropertyType.Geometry;
+            else if (type == typeof(string))
+                return OSGeo.MapGuide.MgPropertyType.String;
+            else if (type == typeof(DateTime))
+                return OSGeo.MapGuide.MgPropertyType.DateTime;
+            else if (type == Utility.RasterType)
+                return OSGeo.MapGuide.MgPropertyType.Raster;
+            else if (type == typeof(byte[]))
+                return OSGeo.MapGuide.MgPropertyType.Blob;
+
+            throw new Exception("Failed to find type for: " + type.FullName.ToString());
+        }
+    }
+}



More information about the mapguide-commits mailing list