Author: toshok
Date: 2006-01-16 15:11:14 -0500 (Mon, 16 Jan 2006)
New Revision: 55650

Modified:
   trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
   
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs
   
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
Log:
2006-01-16  Chris Toshok  <[EMAIL PROTECTED]>

        * WebConfigurationManager.cs: implement a IConfigurationSystem for
        use with WebConfigurationManager.
        (GetSection): try to load the section
        using GetWebApplicationSection before calling into
        ConfigurationManager.GetSection.
        (GetWebApplicationConfiguration): move common code to here.
        (GetWebApplicationSection): use GetWebApplicationConfiguration.
        (AppSettings): implement.

        * WebConfigurationHost.cs (GetWebConfigFileName): add
        "Web.Config", and move to an array/loop implementation.  maybe we
        should scan the directory and check ToLower() instead of
        explicitly enumerating?



Modified: trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog   
2006-01-16 20:05:59 UTC (rev 55649)
+++ trunk/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog   
2006-01-16 20:11:14 UTC (rev 55650)
@@ -1,3 +1,19 @@
+2006-01-16  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * WebConfigurationManager.cs: implement a IConfigurationSystem for
+       use with WebConfigurationManager.
+       (GetSection): try to load the section
+       using GetWebApplicationSection before calling into
+       ConfigurationManager.GetSection.
+       (GetWebApplicationConfiguration): move common code to here.
+       (GetWebApplicationSection): use GetWebApplicationConfiguration.
+       (AppSettings): implement.
+
+       * WebConfigurationHost.cs (GetWebConfigFileName): add
+       "Web.Config", and move to an array/loop implementation.  maybe we
+       should scan the directory and check ToLower() instead of
+       explicitly enumerating?
+
 2006-01-10  Chris Toshok  <[EMAIL PROTECTED]>
 
        * SystemWebSectionGroup.cs (HostingEnvironment): enable this property.

Modified: 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs 
    2006-01-16 20:05:59 UTC (rev 55649)
+++ 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs 
    2006-01-16 20:11:14 UTC (rev 55650)
@@ -233,12 +233,14 @@
 
                string GetWebConfigFileName (string dir)
                {
-                       string file = Path.Combine (dir, "Web.config");
-                       if (File.Exists (file))
-                               return file;
-                       file = Path.Combine (dir, "web.config");
-                       if (File.Exists (file))
-                               return file;
+                       string[] filenames = new string[] {"Web.Config", 
"Web.config", "web.config" };
+
+                       foreach (string fn in filenames) {
+                               string file = Path.Combine (dir, fn);
+                               if (File.Exists (file))
+                                       return file;
+                       }
+
                        return null;
                }
                

Modified: 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
  2006-01-16 20:05:59 UTC (rev 55649)
+++ 
trunk/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs
  2006-01-16 20:11:14 UTC (rev 55650)
@@ -178,9 +178,12 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO ("this shouldn't call 
ConfigurationManager.GetSection")]
                public static object GetSection (string sectionName)
                {
+                       object section = GetWebApplicationSection (sectionName);
+                       if (section != null)
+                               return section;
+
                        return ConfigurationManager.GetSection (sectionName);
                }
 
@@ -190,8 +193,7 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
-               public static object GetWebApplicationSection (string 
sectionName)
+               static _Configuration GetWebApplicationConfiguration ()
                {
                        _Configuration config;
 
@@ -202,15 +204,40 @@
                        else
                                config = OpenWebConfiguration 
(HttpContext.Current.Request.PhysicalApplicationPath);
 
+                       return config;
+               }
+
+               [MonoTODO]
+               public static object GetWebApplicationSection (string 
sectionName)
+               {
+                       _Configuration config = GetWebApplicationConfiguration 
();
+
                        ConfigurationSection section = config.GetSection 
(sectionName);
 
                        return section;
                }
 
+               static _Configuration webConfiguration;
+               static NameValueCollection appSettings;
                [MonoTODO]
                public static NameValueCollection AppSettings {
                        get {
-                               throw new NotImplementedException ();
+                               if (appSettings == null) {
+
+                                       if (webConfiguration == null)
+                                               webConfiguration = 
OpenWebConfiguration ("~");
+
+                                       AppSettingsSection section = 
(AppSettingsSection)webConfiguration.GetSection ("appSettings");
+
+                                       appSettings = new NameValueCollection 
();
+                               
+                                       foreach (string key in 
section.Settings.AllKeys) {
+                                               KeyValueConfigurationElement 
ele = section.Settings[key];
+                                               appSettings.Add (ele.Key, 
ele.Value);
+                                       }
+                               }
+
+                               return appSettings;
                        }
                }
 
@@ -241,7 +268,99 @@
                                path = path.Substring (0, path.Length - 1);
                        return path;
                }
+
+
+#region stuff copied from WebConfigurationSettings
+#if TARGET_J2EE
+               static private IConfigurationSystem oldConfig {
+                       get {
+                               return 
(IConfigurationSystem)AppDomain.CurrentDomain.GetData("WebConfigurationManager.oldConfig");
+                       }
+                       set {
+                               
AppDomain.CurrentDomain.SetData("WebConfigurationManager.oldConfig", value);
+                       }
+               }
+
+               static private Web20DefaultConfig config {
+                       get {
+                               return 
(Web20DefaultConfig)AppDomain.CurrentDomain.GetData("WebConfigurationManager.config");
+                       }
+                       set {
+                               
AppDomain.CurrentDomain.SetData("WebConfigurationManager.config", value);
+                       }
+               }
+#else
+               static IConfigurationSystem oldConfig;
+               static Web20DefaultConfig config;
+#endif
+               const BindingFlags privStatic = BindingFlags.NonPublic | 
BindingFlags.Static;
+               static readonly object lockobj = new object ();
+
+               public static void Init ()
+               {
+                       lock (lockobj) {
+                               if (config != null)
+                                       return;
+
+                               Web20DefaultConfig settings = 
Web20DefaultConfig.GetInstance ();
+                               Type t = typeof (ConfigurationSettings);
+                               MethodInfo changeConfig = t.GetMethod 
("ChangeConfigurationSystem",
+                                                                     
privStatic);
+
+                               if (changeConfig == null)
+                                       throw new ConfigurationException 
("Cannot find method CCS");
+
+                               object [] args = new object [] {settings};
+                               oldConfig = (IConfigurationSystem) 
changeConfig.Invoke (null, args);
+                               config = settings;
+
+                               config.Init ();
+                       }
+               }
        }
+
+       class Web20DefaultConfig : IConfigurationSystem
+       {
+#if TARGET_J2EE
+               static private Web20DefaultConfig instance {
+                       get {
+                               Web20DefaultConfig val = 
(Web20DefaultConfig)AppDomain.CurrentDomain.GetData("Web20DefaultConfig.instance");
+                               if (val == null) {
+                                       val = new Web20DefaultConfig();
+                                       
AppDomain.CurrentDomain.SetData("Web20DefaultConfig.instance", val);
+                               }
+                               return val;
+                       }
+                       set {
+                               
AppDomain.CurrentDomain.SetData("Web20DefaultConfig.instance", value);
+                       }
+               }
+#else
+               static Web20DefaultConfig instance;
+#endif
+
+               static Web20DefaultConfig ()
+               {
+                       instance = new Web20DefaultConfig ();
+               }
+
+               public static Web20DefaultConfig GetInstance ()
+               {
+                       return instance;
+               }
+
+               public object GetConfig (string sectionName)
+               {
+                       return WebConfigurationManager.GetSection (sectionName);
+               }
+
+               public void Init ()
+               {
+                       // nothing. We need a context.
+               }
+       }
+
+#endregion
 }
 
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to