Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / Mobile / DeviceFiltersSection.cs / 1305376 / DeviceFiltersSection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Web.UI.MobileControls; namespace System.Web.Mobile { [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] public sealed class DeviceFiltersSection : ConfigurationSection { internal static readonly TypeConverter StdTypeNameConverter = new MobileTypeNameConverter(); internal static readonly ConfigurationValidatorBase NonEmptyStringValidator = new StringValidator( 1 ); private static ConfigurationPropertyCollection _properties; #region Property Declarations private static readonly ConfigurationProperty _propFilters = new ConfigurationProperty( null, typeof( DeviceFilterElementCollection ), null, ConfigurationPropertyOptions.IsDefaultCollection ); #endregion private object _deviceFilterslock = new object(); private DeviceFilterDictionary _deviceFilters; static DeviceFiltersSection() { // Property initialization _properties = new ConfigurationPropertyCollection(); _properties.Add( _propFilters ); } public DeviceFiltersSection() { } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } [ConfigurationProperty("", IsDefaultCollection = true)] public DeviceFilterElementCollection Filters { get { return (DeviceFilterElementCollection)base[ _propFilters ]; } } internal DeviceFilterDictionary GetDeviceFilters() { if (_deviceFilters == null) { lock (_deviceFilterslock) { if (_deviceFilters == null) { _deviceFilters = CreateDeviceFilters(); } } } return _deviceFilters; } // Essentially this method does what MobileDeviceCapabilitiesSectionHandler.Create() // does, but use this DeviceFiltersSection for retrieving config data instead private DeviceFilterDictionary CreateDeviceFilters() { DeviceFilterDictionary filterDictionary = new DeviceFilterDictionary(); foreach (DeviceFilterElement deviceFilter in Filters) { if (deviceFilter.FilterClass != null) { filterDictionary.AddCapabilityDelegate(deviceFilter.Name, deviceFilter.GetDelegate()); } else { try { filterDictionary.AddComparisonDelegate( deviceFilter.Name, deviceFilter.Compare, deviceFilter.Argument); } catch (Exception e) { throw new ConfigurationErrorsException( SR.GetString(SR.DevCapSect_UnableAddDelegate, deviceFilter.Name, e.Message)); } } } return filterDictionary; } } [ConfigurationCollection(typeof(DeviceFilterElement), AddItemName = "filter", CollectionType = ConfigurationElementCollectionType.BasicMap)] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] public sealed class DeviceFilterElementCollection : ConfigurationElementCollection { private static readonly ConfigurationPropertyCollection _properties; static DeviceFilterElementCollection() { _properties = new ConfigurationPropertyCollection(); } public DeviceFilterElementCollection() { } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } public object[] AllKeys { get { return BaseGetAllKeys(); } } public void Add( DeviceFilterElement deviceFilter ) { BaseAdd( deviceFilter ); } public void Remove( string name ) { BaseRemove( name ); } public void Remove( DeviceFilterElement deviceFilter ) { BaseRemove( GetElementKey( deviceFilter ) ); } public void RemoveAt( int index ) { BaseRemoveAt( index ); } public new DeviceFilterElement this[ string name ] { get { return (DeviceFilterElement)BaseGet( name ); } } public DeviceFilterElement this[ int index ] { get { return (DeviceFilterElement)BaseGet( index ); } set { if ( BaseGet( index ) != null) { BaseRemoveAt( index ); } BaseAdd( index, value ); } } public void Clear() { BaseClear(); } protected override ConfigurationElement CreateNewElement() { return new DeviceFilterElement(); } protected override Object GetElementKey( ConfigurationElement element ) { return ( (DeviceFilterElement)element ).Name; } protected override string ElementName { get { return "filter"; } } public override ConfigurationElementCollectionType CollectionType { get { return ConfigurationElementCollectionType.BasicMap; } } } [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] public sealed class DeviceFilterElement : ConfigurationElement { private static readonly ConfigurationElementProperty s_elemProperty = new ConfigurationElementProperty( new CallbackValidator( typeof( DeviceFilterElement ), ValidateElement ) ); private static ConfigurationPropertyCollection _properties; #region Property Declarations private static readonly ConfigurationProperty _propName = new ConfigurationProperty( "name", typeof( string ), null, null, DeviceFiltersSection.NonEmptyStringValidator, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey ); private static readonly ConfigurationProperty _propFilterClass = new ConfigurationProperty( "type", typeof( Type ), null, DeviceFiltersSection.StdTypeNameConverter, null, ConfigurationPropertyOptions.IsTypeStringTransformationRequired); private static readonly ConfigurationProperty _propMethod = new ConfigurationProperty( "method", typeof( string ), null, null, DeviceFiltersSection.NonEmptyStringValidator, ConfigurationPropertyOptions.None ); private static readonly ConfigurationProperty _propCompare = new ConfigurationProperty( "compare", typeof( string ), null, null, DeviceFiltersSection.NonEmptyStringValidator, ConfigurationPropertyOptions.None ); private static readonly ConfigurationProperty _propArgument = new ConfigurationProperty( "argument", typeof( string ), null, null, DeviceFiltersSection.NonEmptyStringValidator, ConfigurationPropertyOptions.None ); #endregion static DeviceFilterElement() { // Property initialization _properties = new ConfigurationPropertyCollection(); _properties.Add( _propName ); _properties.Add( _propFilterClass ); _properties.Add( _propMethod ); _properties.Add( _propCompare ); _properties.Add( _propArgument ); } internal DeviceFilterElement() { } public DeviceFilterElement( string name, Type filterClass, string method ) { base[_propName] = name; base[_propFilterClass] = filterClass; base[_propMethod] = method; } public DeviceFilterElement( string name, string compareName, string argument ) { base[_propName] = name; base[_propCompare] = compareName; base[_propArgument] = argument; } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } [ConfigurationProperty("name", IsRequired = true, IsKey = true)] [StringValidator(MinLength = 1)] public string Name { get { return (string)base[ _propName ]; } } [ConfigurationProperty("type")] [TypeConverter(typeof(MobileTypeNameConverter))] public Type FilterClass { get { return (Type)base[ _propFilterClass ]; } set { base[ _propFilterClass ] = value; } } [ConfigurationProperty("method")] [StringValidator(MinLength = 1)] public string Method { get { return (string)base[ _propMethod ]; } set { base[ _propMethod ] = value; } } [ConfigurationProperty("compare")] [StringValidator(MinLength = 1)] public string Compare { get { return (string)base[ _propCompare ]; } set { base[ _propCompare ] = value; } } [ConfigurationProperty("argument")] [StringValidator(MinLength = 1)] public string Argument { get { return (string)base[ _propArgument ]; } set { base[ _propArgument ] = value; } } protected override ConfigurationElementProperty ElementProperty { get { return s_elemProperty; } } internal MobileCapabilities.EvaluateCapabilitiesDelegate GetDelegate() { try { return (MobileCapabilities.EvaluateCapabilitiesDelegate)MobileCapabilities.EvaluateCapabilitiesDelegate.CreateDelegate( typeof(MobileCapabilities.EvaluateCapabilitiesDelegate), FilterClass, Method); } catch (Exception e) { throw new ConfigurationErrorsException( SR.GetString(SR.DevCapSect_NoCapabilityEval, Method, e.Message)); } } static private void ValidateElement( object value ) { Debug.Assert((value != null) && (value is DeviceFilterElement)); DeviceFilterElement elem = (DeviceFilterElement)value; // If the filter class is specified, we need the method attribute but // not the compare and argument attributes. if (elem.FilterClass != null) { if(string.IsNullOrEmpty(elem.Method)) { throw new ConfigurationErrorsException( SR.GetString(SR.ConfigSect_MissingAttr, "method")); } if (!string.IsNullOrEmpty(elem.Compare)) { throw new ConfigurationErrorsException(SR.GetString(SR.DevCapSect_ExtraCompareDelegator)); } else if (!string.IsNullOrEmpty(elem.Argument)) { throw new ConfigurationErrorsException(SR.GetString(SR.DevCapSect_ExtraArgumentDelegator)); } // Resolve the method elem.GetDelegate(); } // Otherwise, we need the compare and argument attributes but not // the method attribute. else { if (string.IsNullOrEmpty(elem.Compare)) { throw new ConfigurationErrorsException( SR.GetString(SR.DevCapSect_MustSpecify)); } if (!string.IsNullOrEmpty(elem.Method)) { throw new ConfigurationErrorsException( SR.GetString(SR.DevCapSect_ComparisonAlreadySpecified)); } } } } } // 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
- SiteMapNodeCollection.cs
- MsmqVerifier.cs
- WebBrowserContainer.cs
- AssemblyCollection.cs
- PersonalizablePropertyEntry.cs
- XmlTypeMapping.cs
- XhtmlBasicFormAdapter.cs
- DbCommandTree.cs
- FilteredAttributeCollection.cs
- SubMenuStyleCollection.cs
- ConstraintConverter.cs
- HTMLTagNameToTypeMapper.cs
- Int32Rect.cs
- InheritedPropertyChangedEventArgs.cs
- ServerValidateEventArgs.cs
- NetSectionGroup.cs
- DateTimeFormat.cs
- RSAOAEPKeyExchangeFormatter.cs
- DragDeltaEventArgs.cs
- SwitchCase.cs
- XsltConvert.cs
- EncoderNLS.cs
- DataColumnCollection.cs
- ListViewItem.cs
- Input.cs
- SelectionEditingBehavior.cs
- PreloadHost.cs
- SemaphoreFullException.cs
- MemoryPressure.cs
- XmlException.cs
- TypeInfo.cs
- Propagator.Evaluator.cs
- Padding.cs
- TabControlEvent.cs
- ConstraintConverter.cs
- HandleInitializationContext.cs
- FormParameter.cs
- Matrix3D.cs
- Rotation3D.cs
- BinHexDecoder.cs
- StructuralType.cs
- Metadata.cs
- XmlSchemaGroupRef.cs
- InstanceContext.cs
- XomlCompilerResults.cs
- StringValueSerializer.cs
- X509Utils.cs
- EntityContainerRelationshipSet.cs
- ValueExpressions.cs
- GeometryDrawing.cs
- RowUpdatedEventArgs.cs
- NetDataContractSerializer.cs
- RequestCachePolicy.cs
- ViewBox.cs
- DocumentApplication.cs
- Int32.cs
- Pointer.cs
- StatusBarDesigner.cs
- SQLBoolean.cs
- EncodingDataItem.cs
- AnonymousIdentificationModule.cs
- HexParser.cs
- SchemaDeclBase.cs
- MailDefinition.cs
- TableLayoutCellPaintEventArgs.cs
- StringValidatorAttribute.cs
- AmbientLight.cs
- SQLBytes.cs
- DateTimeConverter.cs
- TextBoxBaseDesigner.cs
- SettingsContext.cs
- FileStream.cs
- CodeTypeDeclaration.cs
- EventProvider.cs
- NumericUpDownAcceleration.cs
- ActiveXHelper.cs
- GrabHandleGlyph.cs
- RangeValuePatternIdentifiers.cs
- ProviderBase.cs
- SessionEndingCancelEventArgs.cs
- PasswordRecoveryAutoFormat.cs
- RestHandler.cs
- ModelItemCollectionImpl.cs
- DocumentApplicationJournalEntry.cs
- DispatcherOperation.cs
- EndpointAddress.cs
- ReadOnlyDictionary.cs
- TCPListener.cs
- ClientBuildManager.cs
- ProfileManager.cs
- IisTraceListener.cs
- CodeChecksumPragma.cs
- ToolboxComponentsCreatedEventArgs.cs
- GridErrorDlg.cs
- SoapSchemaMember.cs
- ClientProxyGenerator.cs
- PopOutPanel.cs
- JavaScriptObjectDeserializer.cs
- SamlAdvice.cs
- BulletedListEventArgs.cs