Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- Run.cs
- SafeMILHandleMemoryPressure.cs
- ErrorHandler.cs
- PrinterSettings.cs
- RegexInterpreter.cs
- HandlerBase.cs
- CustomErrorsSection.cs
- Message.cs
- WindowsAuthenticationEventArgs.cs
- MailBnfHelper.cs
- ChtmlFormAdapter.cs
- FormattedText.cs
- DataGridViewColumnStateChangedEventArgs.cs
- StyleXamlTreeBuilder.cs
- XmlSchemaSimpleContentExtension.cs
- EventListener.cs
- GridViewPageEventArgs.cs
- QilXmlReader.cs
- XmlCodeExporter.cs
- DataControlField.cs
- ToolStripSeparatorRenderEventArgs.cs
- TdsEnums.cs
- OleDbRowUpdatingEvent.cs
- LocalizedNameDescriptionPair.cs
- WebControlsSection.cs
- TreeNodeBinding.cs
- XmlEnumAttribute.cs
- XmlSiteMapProvider.cs
- ScrollPatternIdentifiers.cs
- PropertyGridEditorPart.cs
- XmlRawWriter.cs
- ArgumentException.cs
- StickyNoteHelper.cs
- Track.cs
- RbTree.cs
- JournalEntryStack.cs
- Trace.cs
- ArglessEventHandlerProxy.cs
- Comparer.cs
- ProfileSettings.cs
- PerformanceCounterPermissionAttribute.cs
- ElementsClipboardData.cs
- ToolStripStatusLabel.cs
- TextWriterEngine.cs
- PieceNameHelper.cs
- __ComObject.cs
- QueryReaderSettings.cs
- ContentType.cs
- ConfigsHelper.cs
- SystemIPv6InterfaceProperties.cs
- WeakReadOnlyCollection.cs
- FtpCachePolicyElement.cs
- Light.cs
- TrustLevel.cs
- SessionIDManager.cs
- BitmapEffectDrawingContent.cs
- AffineTransform3D.cs
- CfgArc.cs
- SqlConnectionHelper.cs
- DecoratedNameAttribute.cs
- WindowsSecurityToken.cs
- GridViewColumnHeader.cs
- Transform3DGroup.cs
- PathSegment.cs
- BufferedReadStream.cs
- Events.cs
- HttpListenerRequest.cs
- KeyMatchBuilder.cs
- COM2Properties.cs
- DispatcherExceptionEventArgs.cs
- ProcessThread.cs
- MouseWheelEventArgs.cs
- BitmapEffectInputData.cs
- HtmlInputPassword.cs
- ReaderWriterLock.cs
- UdpTransportSettings.cs
- Source.cs
- RTLAwareMessageBox.cs
- CharConverter.cs
- MemberMaps.cs
- HashLookup.cs
- ThreadStartException.cs
- GroupBox.cs
- AutoCompleteStringCollection.cs
- NetworkAddressChange.cs
- HttpResponseInternalWrapper.cs
- DataGridViewRowStateChangedEventArgs.cs
- cache.cs
- FixedSOMTable.cs
- TimerEventSubscriptionCollection.cs
- EndSelectCardRequest.cs
- TreeNode.cs
- DataTableReaderListener.cs
- DeviceContext2.cs
- Action.cs
- TemplateBindingExpression.cs
- DocumentOrderComparer.cs
- xmlsaver.cs
- SqlTopReducer.cs
- Token.cs