[mapguide-commits] r5060 - trunk/Tools/Maestro/MaestroAPI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jul 30 07:46:03 EDT 2010


Author: jng
Date: 2010-07-30 11:46:03 +0000 (Fri, 30 Jul 2010)
New Revision: 5060

Modified:
   trunk/Tools/Maestro/MaestroAPI/ConnectionFactory.cs
   trunk/Tools/Maestro/MaestroAPI/ConnectionProviderRegistry.cs
Log:
Possible fix for #1370: Use System.Data.Common.DbConnectionStringBuilder to construct/de-construct connection strings as this can take into account reserved characters which would've tripped up the connection creation with our previous approach


Modified: trunk/Tools/Maestro/MaestroAPI/ConnectionFactory.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/ConnectionFactory.cs	2010-07-29 13:13:00 UTC (rev 5059)
+++ trunk/Tools/Maestro/MaestroAPI/ConnectionFactory.cs	2010-07-30 11:46:03 UTC (rev 5060)
@@ -19,23 +19,16 @@
         /// <returns></returns>
         public static ServerConnectionI CreateHttpConnection(Uri hosturl, string sessionid, string locale, bool allowUntestedVersion)
         {
+            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
+            builder[HttpServerConnection.PARAM_URL] = hosturl.ToString();
+            builder[HttpServerConnection.PARAM_SESSION] = sessionid;
+            builder[HttpServerConnection.PARAM_UNTESTED] = allowUntestedVersion;
             string connStr = string.Empty;
-            if (string.IsNullOrEmpty(locale))
+            if (!string.IsNullOrEmpty(locale))
             {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5}",
-                    HttpServerConnection.PARAM_URL, hosturl.ToString(),
-                    HttpServerConnection.PARAM_SESSION, sessionid,
-                    HttpServerConnection.PARAM_UNTESTED, allowUntestedVersion);
+                builder[HttpServerConnection.PARAM_LOCALE] = locale;
             }
-            else
-            {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5};{6}={7}",
-                    HttpServerConnection.PARAM_URL, hosturl.ToString(),
-                    HttpServerConnection.PARAM_SESSION, sessionid,
-                    HttpServerConnection.PARAM_LOCALE, locale,
-                    HttpServerConnection.PARAM_UNTESTED, allowUntestedVersion);
-            }
-            return ConnectionProviderRegistry.CreateConnection("Maestro.Http", connStr);
+            return ConnectionProviderRegistry.CreateConnection("Maestro.Http", builder.ToString());
         }
 
         /// <summary>
@@ -49,25 +42,17 @@
         /// <returns></returns>
         public static ServerConnectionI CreateHttpConnection(Uri hosturl, string username, string password, string locale, bool allowUntestedVersion)
         {
-            string connStr = string.Empty;
-            if (string.IsNullOrEmpty(locale))
+            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
+            builder[HttpServerConnection.PARAM_URL] = hosturl.ToString();
+            builder[HttpServerConnection.PARAM_USERNAME] = username;
+            builder[HttpServerConnection.PARAM_PASSWORD] = password;
+            builder[HttpServerConnection.PARAM_UNTESTED] = allowUntestedVersion;
+            
+            if (!string.IsNullOrEmpty(locale))
             {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5};{6}={7}",
-                    HttpServerConnection.PARAM_URL, hosturl.ToString(),
-                    HttpServerConnection.PARAM_USERNAME, username,
-                    HttpServerConnection.PARAM_PASSWORD, password,
-                    HttpServerConnection.PARAM_UNTESTED, allowUntestedVersion);
+                builder[HttpServerConnection.PARAM_LOCALE] = locale;
             }
-            else
-            {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5};{6}={7};{8}={9}",
-                    HttpServerConnection.PARAM_URL, hosturl.ToString(),
-                    HttpServerConnection.PARAM_USERNAME, username,
-                    HttpServerConnection.PARAM_PASSWORD, password,
-                    HttpServerConnection.PARAM_LOCALE, locale,
-                    HttpServerConnection.PARAM_UNTESTED, allowUntestedVersion);
-            }
-            return ConnectionProviderRegistry.CreateConnection("Maestro.Http", connStr);
+            return ConnectionProviderRegistry.CreateConnection("Maestro.Http", builder.ToString());
         }
 
         /// <summary>
@@ -80,23 +65,15 @@
         /// <returns></returns>
         public static ServerConnectionI CreateLocalNativeConnection(string configFile, string username, string password, string locale)
         {
-            string connStr = string.Empty;
-            if (string.IsNullOrEmpty(locale))
+            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
+            builder[LocalNativeConnection.PARAM_CONFIG] = configFile;
+            builder[LocalNativeConnection.PARAM_USERNAME] = username;
+            builder[LocalNativeConnection.PARAM_PASSWORD] = password;
+            if (!string.IsNullOrEmpty(locale))
             {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5}",
-                    LocalNativeConnection.PARAM_CONFIG, configFile,
-                    LocalNativeConnection.PARAM_USERNAME, username,
-                    LocalNativeConnection.PARAM_PASSWORD, password);
+                builder[LocalNativeConnection.PARAM_LOCALE] = locale;
             }
-            else
-            {
-                connStr = string.Format("{0}={1};{2}={3};{4}={5};{6}={7}",
-                    LocalNativeConnection.PARAM_CONFIG, configFile,
-                    LocalNativeConnection.PARAM_USERNAME, username,
-                    LocalNativeConnection.PARAM_PASSWORD, password,
-                    LocalNativeConnection.PARAM_LOCALE, locale);
-            }
-            return ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", connStr);
+            return ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", builder.ToString());
         }
 
         /// <summary>
@@ -106,7 +83,9 @@
         /// <returns></returns>
         public static ServerConnectionI CreateLocalNativeConnection(string sessionid)
         {
-            return ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", LocalNativeConnection.PARAM_SESSION + "=" + sessionid);
+            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
+            builder[LocalNativeConnection.PARAM_SESSION] = sessionid;
+            return ConnectionProviderRegistry.CreateConnection("Maestro.LocalNative", sessionid);
         }
     }
 }

Modified: trunk/Tools/Maestro/MaestroAPI/ConnectionProviderRegistry.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/ConnectionProviderRegistry.cs	2010-07-29 13:13:00 UTC (rev 5059)
+++ trunk/Tools/Maestro/MaestroAPI/ConnectionProviderRegistry.cs	2010-07-30 11:46:03 UTC (rev 5060)
@@ -78,16 +78,14 @@
 
         private static NameValueCollection ParseConnectionString(string connectionString)
         {
+            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
+            builder.ConnectionString = connectionString;
+
             NameValueCollection values = new NameValueCollection();
-            string[] tokens = connectionString.Split(';');
-            foreach (string tok in tokens)
+            
+            foreach (string key in builder.Keys)
             {
-                string[] nameValue = tok.Split('=');
-
-                if (nameValue.Length == 2)
-                {
-                    values.Add(nameValue[0], nameValue[1]);
-                }
+                values.Add(key, builder[key].ToString());
             }
             return values;
         }



More information about the mapguide-commits mailing list