Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Sys / System / Configuration / SettingsBase.cs / 1 / SettingsBase.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System.Collections.Specialized; using System.Runtime.Serialization; using System.Configuration.Provider; using System.Collections; using System.ComponentModel; //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public abstract class SettingsBase { protected SettingsBase() { _PropertyValues = new SettingsPropertyValueCollection(); } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public virtual object this[string propertyName] { get { if (IsSynchronized) { lock (this) { return GetPropertyValueByName(propertyName); } } else { return GetPropertyValueByName(propertyName); } } set { if (IsSynchronized) { lock (this) { SetPropertyValueByName(propertyName, value); } } else { SetPropertyValueByName(propertyName, value); } } } private object GetPropertyValueByName(string propertyName) { if (Properties == null || _PropertyValues == null || Properties.Count == 0) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsProperty pp = Properties[propertyName]; if (pp == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsPropertyValue p = _PropertyValues[propertyName]; if (p == null) { GetPropertiesFromProvider(pp.Provider); p = _PropertyValues[propertyName]; if (p == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } return p.PropertyValue; } private void SetPropertyValueByName(string propertyName, object propertyValue) { if (Properties == null || _PropertyValues == null || Properties.Count == 0) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsProperty pp = Properties[propertyName]; if (pp == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); if (pp.IsReadOnly) throw new SettingsPropertyIsReadOnlyException(SR.GetString(SR.SettingsPropertyReadOnly, propertyName)); if (propertyValue != null && !pp.PropertyType.IsInstanceOfType(propertyValue)) throw new SettingsPropertyWrongTypeException(SR.GetString(SR.SettingsPropertyWrongType, propertyName)); SettingsPropertyValue p = _PropertyValues[propertyName]; if (p == null) { GetPropertiesFromProvider(pp.Provider); p = _PropertyValues[propertyName]; if (p == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } p.PropertyValue = propertyValue; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public void Initialize( SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) { _Context = context; _Properties = properties; _Providers = providers; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public virtual void Save() { if (IsSynchronized) { lock (this) { SaveCore(); } } else { SaveCore(); } } private void SaveCore() { if (Properties == null || _PropertyValues == null || Properties.Count == 0) return; foreach(SettingsProvider prov in Providers) { SettingsPropertyValueCollection ppcv = new SettingsPropertyValueCollection(); foreach (SettingsPropertyValue pp in PropertyValues) { if (pp.Property.Provider == prov) { ppcv.Add(pp); } } if (ppcv.Count > 0) { prov.SetPropertyValues(Context, ppcv); } } foreach (SettingsPropertyValue pp in PropertyValues) pp.IsDirty = false; } virtual public SettingsPropertyCollection Properties { get { return _Properties; }} virtual public SettingsProviderCollection Providers { get { return _Providers; }} virtual public SettingsPropertyValueCollection PropertyValues { get { return _PropertyValues; } } virtual public SettingsContext Context { get { return _Context; } } private void GetPropertiesFromProvider(SettingsProvider provider) { SettingsPropertyCollection ppc = new SettingsPropertyCollection(); foreach (SettingsProperty pp in Properties) { if (pp.Provider == provider) { ppc.Add(pp); } } if (ppc.Count > 0) { SettingsPropertyValueCollection ppcv = provider.GetPropertyValues(Context, ppc); foreach (SettingsPropertyValue p in ppcv) { if (_PropertyValues[p.Name] == null) _PropertyValues.Add(p); } } } public static SettingsBase Synchronized(SettingsBase settingsBase) { settingsBase._IsSynchronized = true; return settingsBase; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// private SettingsPropertyCollection _Properties = null; private SettingsProviderCollection _Providers = null; private SettingsPropertyValueCollection _PropertyValues = null; private SettingsContext _Context = null; private bool _IsSynchronized = false; [Browsable(false)] public bool IsSynchronized { get { return _IsSynchronized; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System.Collections.Specialized; using System.Runtime.Serialization; using System.Configuration.Provider; using System.Collections; using System.ComponentModel; //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public abstract class SettingsBase { protected SettingsBase() { _PropertyValues = new SettingsPropertyValueCollection(); } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public virtual object this[string propertyName] { get { if (IsSynchronized) { lock (this) { return GetPropertyValueByName(propertyName); } } else { return GetPropertyValueByName(propertyName); } } set { if (IsSynchronized) { lock (this) { SetPropertyValueByName(propertyName, value); } } else { SetPropertyValueByName(propertyName, value); } } } private object GetPropertyValueByName(string propertyName) { if (Properties == null || _PropertyValues == null || Properties.Count == 0) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsProperty pp = Properties[propertyName]; if (pp == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsPropertyValue p = _PropertyValues[propertyName]; if (p == null) { GetPropertiesFromProvider(pp.Provider); p = _PropertyValues[propertyName]; if (p == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } return p.PropertyValue; } private void SetPropertyValueByName(string propertyName, object propertyValue) { if (Properties == null || _PropertyValues == null || Properties.Count == 0) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); SettingsProperty pp = Properties[propertyName]; if (pp == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); if (pp.IsReadOnly) throw new SettingsPropertyIsReadOnlyException(SR.GetString(SR.SettingsPropertyReadOnly, propertyName)); if (propertyValue != null && !pp.PropertyType.IsInstanceOfType(propertyValue)) throw new SettingsPropertyWrongTypeException(SR.GetString(SR.SettingsPropertyWrongType, propertyName)); SettingsPropertyValue p = _PropertyValues[propertyName]; if (p == null) { GetPropertiesFromProvider(pp.Provider); p = _PropertyValues[propertyName]; if (p == null) throw new SettingsPropertyNotFoundException(SR.GetString(SR.SettingsPropertyNotFound, propertyName)); } p.PropertyValue = propertyValue; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public void Initialize( SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) { _Context = context; _Properties = properties; _Providers = providers; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public virtual void Save() { if (IsSynchronized) { lock (this) { SaveCore(); } } else { SaveCore(); } } private void SaveCore() { if (Properties == null || _PropertyValues == null || Properties.Count == 0) return; foreach(SettingsProvider prov in Providers) { SettingsPropertyValueCollection ppcv = new SettingsPropertyValueCollection(); foreach (SettingsPropertyValue pp in PropertyValues) { if (pp.Property.Provider == prov) { ppcv.Add(pp); } } if (ppcv.Count > 0) { prov.SetPropertyValues(Context, ppcv); } } foreach (SettingsPropertyValue pp in PropertyValues) pp.IsDirty = false; } virtual public SettingsPropertyCollection Properties { get { return _Properties; }} virtual public SettingsProviderCollection Providers { get { return _Providers; }} virtual public SettingsPropertyValueCollection PropertyValues { get { return _PropertyValues; } } virtual public SettingsContext Context { get { return _Context; } } private void GetPropertiesFromProvider(SettingsProvider provider) { SettingsPropertyCollection ppc = new SettingsPropertyCollection(); foreach (SettingsProperty pp in Properties) { if (pp.Provider == provider) { ppc.Add(pp); } } if (ppc.Count > 0) { SettingsPropertyValueCollection ppcv = provider.GetPropertyValues(Context, ppc); foreach (SettingsPropertyValue p in ppcv) { if (_PropertyValues[p.Name] == null) _PropertyValues.Add(p); } } } public static SettingsBase Synchronized(SettingsBase settingsBase) { settingsBase._IsSynchronized = true; return settingsBase; } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// private SettingsPropertyCollection _Properties = null; private SettingsProviderCollection _Providers = null; private SettingsPropertyValueCollection _PropertyValues = null; private SettingsContext _Context = null; private bool _IsSynchronized = false; [Browsable(false)] public bool IsSynchronized { get { return _IsSynchronized; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlInternalConnectionSmi.cs
- SingleSelectRootGridEntry.cs
- SecurityStandardsManager.cs
- ClientOptions.cs
- NullableConverter.cs
- DiagnosticTrace.cs
- ReferencedAssembly.cs
- LogStore.cs
- ToolStripMenuItem.cs
- ComPlusInstanceProvider.cs
- DesignerEventService.cs
- TextServicesCompartmentContext.cs
- DesignTimeHTMLTextWriter.cs
- ControlBuilderAttribute.cs
- DeferredElementTreeState.cs
- SendMailErrorEventArgs.cs
- SerializationInfoEnumerator.cs
- Message.cs
- LinqToSqlWrapper.cs
- RawAppCommandInputReport.cs
- BufferedStream.cs
- RetrieveVirtualItemEventArgs.cs
- HttpWriter.cs
- CodeCastExpression.cs
- ConnectionPointCookie.cs
- ProfileInfo.cs
- MetadataWorkspace.cs
- BaseCodePageEncoding.cs
- TileModeValidation.cs
- XsltSettings.cs
- HierarchicalDataSourceIDConverter.cs
- StrokeCollectionDefaultValueFactory.cs
- Empty.cs
- Mapping.cs
- ContentPlaceHolder.cs
- IISMapPath.cs
- InputScopeManager.cs
- WebException.cs
- ZipPackagePart.cs
- WebPartDescription.cs
- ClientSponsor.cs
- TextEditorTyping.cs
- Lease.cs
- DBDataPermissionAttribute.cs
- PeerContact.cs
- RelationshipSet.cs
- AssociationTypeEmitter.cs
- InstanceCollisionException.cs
- SqlNodeAnnotation.cs
- NativeRecognizer.cs
- PackWebRequest.cs
- ProfileBuildProvider.cs
- DynamicActivityTypeDescriptor.cs
- NativeMethods.cs
- VarRemapper.cs
- GridProviderWrapper.cs
- CacheMemory.cs
- OLEDB_Util.cs
- Drawing.cs
- BindableTemplateBuilder.cs
- ModifierKeysValueSerializer.cs
- RawAppCommandInputReport.cs
- CmsUtils.cs
- CommandEventArgs.cs
- ToolStripButton.cs
- WizardForm.cs
- NetworkInformationException.cs
- FieldTemplateFactory.cs
- DiscoveryEndpoint.cs
- TdsParameterSetter.cs
- ScopeElement.cs
- Literal.cs
- AssertUtility.cs
- CompiledXpathExpr.cs
- BindingRestrictions.cs
- BasicHttpMessageSecurity.cs
- DependencyObjectPropertyDescriptor.cs
- LogEntryHeaderSerializer.cs
- NavigationFailedEventArgs.cs
- AxHostDesigner.cs
- XPathParser.cs
- BitmapSourceSafeMILHandle.cs
- HyperLink.cs
- Single.cs
- TraceSection.cs
- PreviewKeyDownEventArgs.cs
- WebPartConnectionsDisconnectVerb.cs
- ECDiffieHellmanPublicKey.cs
- IdentityNotMappedException.cs
- DataGridViewCellParsingEventArgs.cs
- HttpHandlerActionCollection.cs
- FullTextLine.cs
- ResponseBodyWriter.cs
- FileInfo.cs
- UrlMappingCollection.cs
- FlowPosition.cs
- HtmlTable.cs
- ProcessRequestArgs.cs
- XhtmlBasicValidatorAdapter.cs
- BatchServiceHost.cs