diff options
author | Chris Toshok <toshok@novell.com> | 2006-03-08 21:21:02 +0300 |
---|---|---|
committer | Chris Toshok <toshok@novell.com> | 2006-03-08 21:21:02 +0300 |
commit | bda4c7ab635a9872d3a9247d95f12b2739b2786e (patch) | |
tree | a29417c025c66ab64c80e12aebdb5ed1893c5007 /mcs | |
parent | d3da2c39b8d4b96d15bac10656e3b1f729ae43af (diff) |
In System.Web.Configuration_2.0:
2006-03-08 Chris Toshok <toshok@ximian.com>
* ProvidersHelper.cs: implement this static class properly.
* SiteMapSection.cs (ProvidersInternal): add internal property to
get the actual SiteMapProviderCollection from here.
In System.Web:
2006-03-08 Chris Toshok <toshok@ximian.com>
* SiteMap.cs: clean this up a bunch. use the SiteMapSection to
initialize the provider collection, and don't add a provider.
web.config handles that for us. Also, don't always return true
from get_Enabled.
svn path=/trunk/mcs/; revision=57704
Diffstat (limited to 'mcs')
5 files changed, 51 insertions, 31 deletions
diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog b/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog index a67bbb69d80..f8dd1c91829 100644 --- a/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog @@ -1,3 +1,10 @@ +2006-03-08 Chris Toshok <toshok@ximian.com> + + * ProvidersHelper.cs: implement this static class properly. + + * SiteMapSection.cs (ProvidersInternal): add internal property to + get the actual SiteMapProviderCollection from here. + 2006-02-28 Chris Toshok <toshok@ximian.com> * BuildProviderAppliesTo.cs, PagesToCountAction.cs: nuke. diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/ProvidersHelper.cs b/mcs/class/System.Web/System.Web.Configuration_2.0/ProvidersHelper.cs index 153b0f40ef7..7955ab28470 100644 --- a/mcs/class/System.Web/System.Web.Configuration_2.0/ProvidersHelper.cs +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/ProvidersHelper.cs @@ -38,19 +38,27 @@ namespace System.Web.Configuration { public static class ProvidersHelper { - [MonoTODO ("is this right?")] public static ProviderBase InstantiateProvider (ProviderSettings providerSettings, Type providerType) { - ProviderBase provider = Activator.CreateInstance (providerType) as ProviderBase; + Type settingsType = Type.GetType (providerSettings.Type); + + if (settingsType == null) + throw new ConfigurationErrorsException (String.Format ("Could not find type: {0}", providerSettings.Type)); + if (!providerType.IsAssignableFrom (settingsType)) + throw new ConfigurationErrorsException (String.Format ("Provider '{0}' must subclass from '{1}'", providerSettings.Name, providerType)); + + ProviderBase provider = Activator.CreateInstance (settingsType) as ProviderBase; provider.Initialize (providerSettings.Name, providerSettings.Parameters); return provider; } - [MonoTODO ("is this right?")] public static void InstantiateProviders (ProviderSettingsCollection configProviders, ProviderCollection providers, Type providerType) { + if (!typeof (ProviderBase).IsAssignableFrom (providerType)) + throw new ConfigurationErrorsException (String.Format ("type '{0}' must subclass from ProviderBase", providerType)); + foreach (ProviderSettings settings in configProviders) providers.Add (InstantiateProvider (settings, providerType)); } diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/SiteMapSection.cs b/mcs/class/System.Web/System.Web.Configuration_2.0/SiteMapSection.cs index 5f7296194a9..cc4f9290f7e 100644 --- a/mcs/class/System.Web/System.Web.Configuration_2.0/SiteMapSection.cs +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/SiteMapSection.cs @@ -73,6 +73,17 @@ namespace System.Web.Configuration get { return (ProviderSettingsCollection) base ["providers"]; } } + SiteMapProviderCollection providers; + internal SiteMapProviderCollection ProvidersInternal { + get { + if (providers == null) { + providers = new SiteMapProviderCollection (); + ProvidersHelper.InstantiateProviders (Providers, providers, typeof (SiteMapProvider)); + } + return providers; + } + } + protected override ConfigurationPropertyCollection Properties { get { return properties; } } diff --git a/mcs/class/System.Web/System.Web/ChangeLog b/mcs/class/System.Web/System.Web/ChangeLog index f5d79e55ac4..7d78eb6edb8 100644 --- a/mcs/class/System.Web/System.Web/ChangeLog +++ b/mcs/class/System.Web/System.Web/ChangeLog @@ -1,3 +1,10 @@ +2006-03-08 Chris Toshok <toshok@ximian.com> + + * SiteMap.cs: clean this up a bunch. use the SiteMapSection to + initialize the provider collection, and don't add a provider. + web.config handles that for us. Also, don't always return true + from get_Enabled. + 2006-02-28 Chris Toshok <toshok@ximian.com> * HttpCookieMode.cs: corcompare work. diff --git a/mcs/class/System.Web/System.Web/SiteMap.cs b/mcs/class/System.Web/System.Web/SiteMap.cs index 7b45c45f2b2..91680916550 100644 --- a/mcs/class/System.Web/System.Web/SiteMap.cs +++ b/mcs/class/System.Web/System.Web/SiteMap.cs @@ -44,33 +44,17 @@ namespace System.Web { lock (locker) { if (provider == null) { SiteMapSection section = (SiteMapSection) WebConfigurationManager.GetSection ("system.web/siteMap"); - providers = new SiteMapProviderCollection (); - - if (section.Enabled) { - foreach (ProviderSettings prov in section.Providers) { - Type t = Type.GetType (prov.Type); - if (t == null) - throw new ConfigurationException ("Cannot find type: " + prov.Type); - if (!typeof(SiteMapProvider).IsAssignableFrom (t)) - throw new ConfigurationException ("The provided type is not a SiteMapProvider subclass: " + prov.Type); - - SiteMapProvider pr = (SiteMapProvider) Activator.CreateInstance (t); - pr.Initialize (prov.Name, prov.Parameters); - - if (provider == null || prov.Name == section.DefaultProvider) - provider = pr; - providers.Add (pr); - } - } - - if (providers.Count == 0) { - provider = new XmlSiteMapProvider (); - NameValueCollection attributes = new NameValueCollection (); - attributes.Add ("siteMapFile", "Web.sitemap"); - provider.Initialize ("AspNetXmlSiteMapProvider", attributes); - providers.Add (provider); - } + if (!section.Enabled) + throw new InvalidOperationException ("This feature is currently disabled. Please enable it in the system.web/siteMap section in the web.config file."); + + providers = section.ProvidersInternal; + + provider = providers[section.DefaultProvider]; + + if (provider == null) + throw new ConfigurationErrorsException ( + String.Format ("The default sitemap provider '{0}' does not exist in the provider collection.", section.DefaultProvider)); } } } @@ -78,6 +62,7 @@ namespace System.Web { public static SiteMapNode CurrentNode { get { return Provider.CurrentNode; } } + public static SiteMapNode RootNode { get { return Provider.RootNode; } } @@ -100,9 +85,11 @@ namespace System.Web { remove { Provider.SiteMapResolve -= value; } } - [MonoTODO ("By now it always return 'true'")] public static bool Enabled { - get { return true; } + get { + SiteMapSection section = (SiteMapSection) WebConfigurationManager.GetSection ("system.web/siteMap"); + return section.Enabled; + } } static SiteMapProvider provider; |