diff options
author | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2008-10-20 16:42:34 +0400 |
---|---|---|
committer | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2008-10-20 16:42:34 +0400 |
commit | 8bcb026874d9a7ceb93be5ea1a1509769a459fdf (patch) | |
tree | 6b416604c40bc6af99421aab157e873f336aa425 | |
parent | 5074c107fb3313301550a98358a61b63042d61e5 (diff) |
2008-10-05 Gert Driesen <drieseng@users.sourceforge.net>
* CustomizableFileSettingsProvider.cs (LoadPropertyValue): Do not
hide ArgumentException.
2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
* CustomizableFileSettingsProvider.cs: when reading application or
user settings, only read those settings appropriate for the context.
This avoids duplicate key errors when 2 different groups have a key
with the same name.
* ApplicationSettingsBase.cs: the context is a hashtable with several
values set upon creation: SettingsKey, GroupName and
SettingsClassType.
Fixes bug #432466.
2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ApplicationSettingsBase.cs: honor the IsSynchronized value in the
Context, Properties, PropertyValues and Providers. All of them might
initialize an instance field for the class. Hopefully this fixes some
nullrefs.
2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ApplicationSettingsBase.cs: honor the IsSynchronized value in the
indexer.
svn path=/branches/mono-2-0/mcs/; revision=116506
3 files changed, 126 insertions, 38 deletions
diff --git a/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs b/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs index 5495326a6c7..b5967cd3d1e 100644 --- a/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs +++ b/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs @@ -32,23 +32,22 @@ using System.Xml.Serialization; using System.ComponentModel; using System.Reflection; +using System.Threading; using System.Collections.Specialized; namespace System.Configuration { - public abstract class ApplicationSettingsBase : SettingsBase, INotifyPropertyChanged + public abstract class ApplicationSettingsBase : SettingsBase, INotifyPropertyChanged { - - protected ApplicationSettingsBase () - { + protected ApplicationSettingsBase () + { Initialize (Context, Properties, Providers); - } + } protected ApplicationSettingsBase (IComponent owner) : this (owner, String.Empty) { } - protected ApplicationSettingsBase (string settingsKey) { @@ -63,8 +62,9 @@ namespace System.Configuration { if (owner == null) throw new ArgumentNullException (); +#if (CONFIGURATION_DEP) providerService = (ISettingsProviderService)owner.Site.GetService(typeof (ISettingsProviderService)); - +#endif this.settingsKey = settingsKey; Initialize (Context, Properties, Providers); @@ -159,10 +159,23 @@ namespace System.Configuration { [Browsable (false)] public override SettingsContext Context { get { - if (context == null) - context = new SettingsContext (); + if (IsSynchronized) + Monitor.Enter (this); + + try { + if (context == null) { + context = new SettingsContext (); + context ["SettingsKey"] = ""; + Type type = GetType (); + context ["GroupName"] = type.FullName; + context ["SettingsClassType"] = type; + } - return context; + return context; + } finally { + if (IsSynchronized) + Monitor.Exit (this); + } } } @@ -206,6 +219,12 @@ namespace System.Configuration { [MonoTODO] public override object this [ string propertyName ] { get { + if (IsSynchronized) { + lock (this) { + return GetPropertyValue (propertyName); + } + } + return GetPropertyValue (propertyName); } set { @@ -247,20 +266,28 @@ namespace System.Configuration { [Browsable (false)] public override SettingsPropertyCollection Properties { get { - if (properties == null) { - LocalFileSettingsProvider local_provider = null; + if (IsSynchronized) + Monitor.Enter (this); - properties = new SettingsPropertyCollection (); + try { + if (properties == null) { + LocalFileSettingsProvider local_provider = null; - foreach (PropertyInfo prop in GetType ().GetProperties ()) { // only public properties - SettingAttribute[] setting_attrs = (SettingAttribute[])prop.GetCustomAttributes (typeof (SettingAttribute), false); - if (setting_attrs == null || setting_attrs.Length == 0) - continue; - CreateSettingsProperty (prop, properties, ref local_provider); + properties = new SettingsPropertyCollection (); + + foreach (PropertyInfo prop in GetType ().GetProperties ()) { // only public properties + SettingAttribute[] setting_attrs = (SettingAttribute[])prop.GetCustomAttributes (typeof (SettingAttribute), false); + if (setting_attrs == null || setting_attrs.Length == 0) + continue; + CreateSettingsProperty (prop, properties, ref local_provider); + } } - } - return properties; + return properties; + } finally { + if (IsSynchronized) + Monitor.Exit (this); + } } } @@ -344,21 +371,37 @@ namespace System.Configuration { [Browsable (false)] public override SettingsPropertyValueCollection PropertyValues { get { - if (propertyValues == null) { - propertyValues = new SettingsPropertyValueCollection (); - } + if (IsSynchronized) + Monitor.Enter (this); + + try { + if (propertyValues == null) { + propertyValues = new SettingsPropertyValueCollection (); + } - return propertyValues; + return propertyValues; + } finally { + if (IsSynchronized) + Monitor.Exit (this); + } } } [Browsable (false)] public override SettingsProviderCollection Providers { get { - if (providers == null) - providers = new SettingsProviderCollection (); + if (IsSynchronized) + Monitor.Enter (this); + + try { + if (providers == null) + providers = new SettingsProviderCollection (); - return providers; + return providers; + } finally { + if (IsSynchronized) + Monitor.Exit (this); + } } } @@ -374,10 +417,12 @@ namespace System.Configuration { string settingsKey; SettingsContext context; +#if (CONFIGURATION_DEP) SettingsPropertyCollection properties; + ISettingsProviderService providerService; +#endif SettingsPropertyValueCollection propertyValues; SettingsProviderCollection providers; - ISettingsProviderService providerService; } } diff --git a/mcs/class/System/System.Configuration/ChangeLog b/mcs/class/System/System.Configuration/ChangeLog index db8bb9b77a2..d6f636f6bc5 100644 --- a/mcs/class/System/System.Configuration/ChangeLog +++ b/mcs/class/System/System.Configuration/ChangeLog @@ -1,3 +1,33 @@ +2008-10-05 Gert Driesen <drieseng@users.sourceforge.net> + + * CustomizableFileSettingsProvider.cs (LoadPropertyValue): Do not + hide ArgumentException. + +2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com> + + * CustomizableFileSettingsProvider.cs: when reading application or + user settings, only read those settings appropriate for the context. + This avoids duplicate key errors when 2 different groups have a key + with the same name. + * ApplicationSettingsBase.cs: the context is a hashtable with several + values set upon creation: SettingsKey, GroupName and + SettingsClassType. + + Fixes bug #432466. + +2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com> + + * ApplicationSettingsBase.cs: honor the IsSynchronized value in the + Context, Properties, PropertyValues and Providers. All of them might + initialize an instance field for the class. Hopefully this fixes some + nullrefs. + +2008-10-04 Gonzalo Paniagua Javier <gonzalo@novell.com> + + * ApplicationSettingsBase.cs: honor the IsSynchronized value in the + indexer. + + 2008-09-01 Ivan N. Zlatev <contact@i-nz.net> * SettingsPropertyValue.cs: Explicitly use the Invariant culture diff --git a/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs b/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs index 9bad8d085fc..1576011b85c 100644 --- a/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs +++ b/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs @@ -37,6 +37,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Configuration; +using System.Globalization; using System.IO; using System.Reflection; using System.Security.Cryptography; @@ -694,22 +695,33 @@ namespace System.Configuration if (allowOverwrite) values.Remove (element.Name); values.Add (value); - } catch (ArgumentException) { - throw new ConfigurationErrorsException (); + } catch (ArgumentException ex) { + throw new ConfigurationErrorsException (string.Format ( + CultureInfo.InvariantCulture, + "Failed to load value for '{0}'.", + element.Name), ex); } } - private void LoadProperies (ExeConfigurationFileMap exeMap, SettingsPropertyCollection collection, ConfigurationUserLevel level, string sectionGroupName, bool allowOverwrite) + private void LoadProperties (ExeConfigurationFileMap exeMap, SettingsPropertyCollection collection, ConfigurationUserLevel level, string sectionGroupName, bool allowOverwrite, string groupName) { Configuration config = ConfigurationManager.OpenMappedExeConfiguration (exeMap,level); ConfigurationSectionGroup sectionGroup = config.GetSectionGroup (sectionGroupName); if (sectionGroup != null) { foreach (ConfigurationSection configSection in sectionGroup.Sections) { + if (configSection.SectionInformation.Name != groupName) + continue; + ClientSettingsSection clientSection = configSection as ClientSettingsSection; - if (clientSection != null) - foreach (SettingElement element in clientSection.Settings) - LoadPropertyValue(collection, element, allowOverwrite); + if (clientSection == null) + continue; + + foreach (SettingElement element in clientSection.Settings) { + LoadPropertyValue(collection, element, allowOverwrite); + } + // Only the first one seems to be processed by MS + break; } } @@ -734,11 +746,12 @@ namespace System.Configuration if (values == null) { values = new SettingsPropertyValueCollection (); - LoadProperies (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false); - LoadProperies (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false); + string groupName = context ["GroupName"] as string; + LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName); + LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName); - LoadProperies (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true); - LoadProperies (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true); + LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName); + LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName); // create default values if not exist foreach (SettingsProperty p in collection) |