1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
|
//------------------------------------------------------------------------------
// <copyright file="MobileControlsSection.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
namespace System.Web.UI.MobileControls
{
[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 MobileControlsSection : ConfigurationSection
{
private ControlsConfig _controlConfig;
private object _lock = new object();
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 _propHistorySize =
new ConfigurationProperty( "sessionStateHistorySize",
typeof( int ),
Constants.DefaultSessionsStateHistorySize,
null,
new IntegerValidator( 0 ,int.MaxValue),
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propDictType =
new ConfigurationProperty( "cookielessDataDictionaryType",
typeof( Type ),
typeof( System.Web.Mobile.CookielessData ),
MobileControlsSection.StdTypeNameConverter,
new SubclassTypeValidator( typeof( IDictionary ) ),
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propAllowCustomAttributes =
new ConfigurationProperty( "allowCustomAttributes",
typeof( bool ),
false,
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propDevices =
new ConfigurationProperty( null,
typeof( DeviceElementCollection ),
null,
ConfigurationPropertyOptions.IsDefaultCollection );
#endregion
static MobileControlsSection()
{
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add( _propHistorySize );
_properties.Add( _propDevices );
_properties.Add( _propDictType );
_properties.Add( _propAllowCustomAttributes );
}
public MobileControlsSection()
{
}
// VSWhidbey 450801. Only create one ControlsConfig per MobileControlsSection instance.
internal ControlsConfig GetControlsConfig() {
if (_controlConfig == null) {
lock (_lock) {
if (_controlConfig == null) {
_controlConfig = MobileControlsSectionHelper.CreateControlsConfig(this);
}
}
}
return _controlConfig;
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
[ConfigurationProperty("sessionStateHistorySize", DefaultValue = 6)]
[IntegerValidator(MinValue = 0)]
public int SessionStateHistorySize
{
get
{
return (int)base[ _propHistorySize ];
}
set
{
base[ _propHistorySize ] = value;
}
}
[ConfigurationProperty("cookielessDataDictionaryType", DefaultValue = typeof(System.Web.Mobile.CookielessData))]
[TypeConverter(typeof(MobileTypeNameConverter))]
[SubclassTypeValidator(typeof(IDictionary))]
public Type CookielessDataDictionaryType
{
get
{
return (Type)base[ _propDictType ];
}
set
{
base[ _propDictType ] = value;
}
}
[ConfigurationProperty("allowCustomAttributes", DefaultValue = false)]
public bool AllowCustomAttributes
{
get
{
return (bool)base[ _propAllowCustomAttributes ];
}
set
{
base[ _propAllowCustomAttributes ] = value;
}
}
[ConfigurationProperty("", IsDefaultCollection = true)]
public DeviceElementCollection Devices
{
get
{
return (DeviceElementCollection)base[ _propDevices ];
}
}
}
[ConfigurationCollection(typeof(DeviceElement), AddItemName="device")]
[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 DeviceElementCollection : ConfigurationElementCollection
{
private static readonly ConfigurationPropertyCollection _properties;
static DeviceElementCollection()
{
_properties = new ConfigurationPropertyCollection();
}
public DeviceElementCollection()
{
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
public object[] AllKeys
{
get
{
return BaseGetAllKeys();
}
}
public void Add( DeviceElement deviceElement )
{
BaseAdd( deviceElement );
}
public void Remove( string name )
{
BaseRemove( name );
}
public void Remove( DeviceElement deviceElement )
{
BaseRemove( GetElementKey( deviceElement ) );
}
public void RemoveAt( int index )
{
BaseRemoveAt( index );
}
public new DeviceElement this[ string name ]
{
get
{
return (DeviceElement)BaseGet( name );
}
}
public DeviceElement this[ int index ]
{
get
{
return (DeviceElement)BaseGet( index );
}
set
{
if ( BaseGet( index ) != null)
{
BaseRemoveAt( index );
}
BaseAdd( index, value );
}
}
public void Clear()
{
BaseClear();
}
protected override ConfigurationElement CreateNewElement()
{
return new DeviceElement();
}
protected override Object GetElementKey( ConfigurationElement element )
{
return ( (DeviceElement)element ).Name;
}
protected override string ElementName
{
get
{
return "device";
}
}
protected override bool ThrowOnDuplicate
{
get
{
return true;
}
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMapAlternate;
}
}
}
[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 DeviceElement : ConfigurationElement
{
private static readonly ConfigurationElementProperty s_elemProperty = new ConfigurationElementProperty( new CallbackValidator( typeof( DeviceElement ), ValidateElement ) );
private static ConfigurationPropertyCollection _properties;
#region Property Declarations
private static readonly ConfigurationProperty _propName =
new ConfigurationProperty( "name",
typeof( string ),
null,
null,
MobileControlsSection.NonEmptyStringValidator,
ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey );
private static readonly ConfigurationProperty _propInheritsFrom =
new ConfigurationProperty( "inheritsFrom",
typeof( string ),
null,
null,
MobileControlsSection.NonEmptyStringValidator,
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propPredicateClass =
new ConfigurationProperty( "predicateClass",
typeof( Type ),
null,
MobileControlsSection.StdTypeNameConverter,
null,
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propPredicateMethod =
new ConfigurationProperty( "predicateMethod",
typeof( string ),
null,
null,
MobileControlsSection.NonEmptyStringValidator,
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propPageAdapter =
new ConfigurationProperty( "pageAdapter",
typeof( Type ),
null,
MobileControlsSection.StdTypeNameConverter,
new SubclassTypeValidator( typeof( IPageAdapter ) ),
ConfigurationPropertyOptions.None );
private static readonly ConfigurationProperty _propControls =
new ConfigurationProperty( null,
typeof(ControlElementCollection),
null,
ConfigurationPropertyOptions.IsDefaultCollection );
#endregion
static DeviceElement()
{
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add( _propName );
_properties.Add( _propInheritsFrom );
_properties.Add( _propPredicateClass );
_properties.Add( _propPredicateMethod );
_properties.Add( _propPageAdapter );
_properties.Add( _propControls );
}
internal DeviceElement()
{
}
public DeviceElement( string name, string inheritsFrom )
{
base[ _propName ] = name;
base[ _propInheritsFrom ] = inheritsFrom;
}
public DeviceElement( string name, Type predicateClass, string predicateMethod, Type pageAdapter )
{
base[ _propName] = name;
base[ _propPredicateClass] = predicateClass;
base[ _propPredicateMethod] = predicateMethod;
base[ _propPageAdapter ] = pageAdapter;
}
public DeviceElement(string name, string inheritsFrom, Type predicateClass,
string predicateMethod, Type pageAdapter)
{
base[ _propName] = name;
base[ _propInheritsFrom ] = inheritsFrom;
base[ _propPredicateClass] = predicateClass;
base[ _propPredicateMethod] = predicateMethod;
base[ _propPageAdapter ] = pageAdapter;
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
[StringValidator(MinLength = 1)]
public string Name
{
get
{
return (string)base[ _propName ];
}
set
{
base[ _propName ] = value;
}
}
[ConfigurationProperty("inheritsFrom")]
[StringValidator(MinLength = 1)]
public string InheritsFrom
{
get
{
return (string)base[ _propInheritsFrom ];
}
set
{
base[ _propInheritsFrom ] = value;
}
}
[ConfigurationProperty("predicateClass")]
[TypeConverter(typeof(MobileTypeNameConverter))]
public Type PredicateClass
{
get
{
return (Type)base[ _propPredicateClass ];
}
set
{
base[ _propPredicateClass ] = value;
}
}
[ConfigurationProperty("predicateMethod")]
[StringValidator(MinLength = 1)]
public string PredicateMethod
{
get
{
return (string)base[ _propPredicateMethod ];
}
set
{
base[ _propPredicateMethod ] = value;
}
}
[ConfigurationProperty("pageAdapter")]
[TypeConverter(typeof(MobileTypeNameConverter))]
[SubclassTypeValidator(typeof(IPageAdapter))]
public Type PageAdapter
{
get
{
return (Type)base[_propPageAdapter];
}
set
{
base[_propPageAdapter] = value;
}
}
[ConfigurationProperty("", IsDefaultCollection = true)]
public ControlElementCollection Controls
{
get
{
return (ControlElementCollection)base[ _propControls ];
}
}
protected override ConfigurationElementProperty ElementProperty
{
get
{
return s_elemProperty;
}
}
internal IndividualDeviceConfig.DeviceQualifiesDelegate GetDelegate()
{
try
{
return (IndividualDeviceConfig.DeviceQualifiesDelegate)IndividualDeviceConfig.DeviceQualifiesDelegate.CreateDelegate(
typeof(IndividualDeviceConfig.DeviceQualifiesDelegate),
PredicateClass,
PredicateMethod );
}
catch
{
throw new ConfigurationErrorsException(
SR.GetString(SR.MobileControlsSectionHandler_CantCreateMethodOnClass, PredicateMethod, PredicateClass.FullName),
ElementInformation.Source, ElementInformation.LineNumber);
}
}
static private void ValidateElement( object value )
{
Debug.Assert( ( value != null ) && ( value is DeviceElement ) );
DeviceElement elem = (DeviceElement)value;
// If there is no inheritance the properties must exists and be valid
if ( string.IsNullOrEmpty(elem.InheritsFrom) )
{
if ( elem.PredicateClass == null )
{
throw new ConfigurationErrorsException( SR.GetString(SR.ConfigSect_MissingValue, "predicateClass"),
elem.ElementInformation.Source,
elem.ElementInformation.LineNumber );
}
if ( elem.PageAdapter == null )
{
throw new ConfigurationErrorsException( SR.GetString(SR.ConfigSect_MissingValue, "pageAdapter"),
elem.ElementInformation.Source,
elem.ElementInformation.LineNumber );
}
// Resolve the method
elem.GetDelegate();
}
}
}
[ConfigurationCollection(typeof(ControlElement), AddItemName = "control")]
[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 ControlElementCollection : ConfigurationElementCollection
{
private static readonly ConfigurationPropertyCollection _properties;
static ControlElementCollection()
{
_properties = new ConfigurationPropertyCollection();
}
public ControlElementCollection()
{
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
public object[] AllKeys
{
get
{
return BaseGetAllKeys();
}
}
public void Add( ControlElement controlElement )
{
BaseAdd( controlElement );
}
public void Remove( string name )
{
BaseRemove( name );
}
public void Remove( ControlElement controlElement )
{
BaseRemove( GetElementKey( controlElement ) );
}
public void RemoveAt( int index )
{
BaseRemoveAt( index );
}
public new ControlElement this[ string name ]
{
get
{
return (ControlElement)BaseGet( name );
}
}
public ControlElement this[ int index ]
{
get
{
return (ControlElement)BaseGet( index );
}
set
{
if ( BaseGet( index ) != null)
{
BaseRemoveAt( index );
}
BaseAdd( index, value );
}
}
public void Clear()
{
BaseClear();
}
protected override ConfigurationElement CreateNewElement()
{
return new ControlElement();
}
protected override Object GetElementKey( ConfigurationElement element )
{
return ( (ControlElement)element ).Name;
}
protected override string ElementName
{
get
{
return "control";
}
}
protected override bool ThrowOnDuplicate
{
get
{
return true;
}
}
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 ControlElement : ConfigurationElement
{
private static readonly ConfigurationElementProperty s_elemProperty = new ConfigurationElementProperty( new CallbackValidator( typeof( ControlElement ), ValidateElement ) );
private static readonly ConfigurationValidatorBase s_SubclassTypeValidator = new SubclassTypeValidator( typeof( MobileControl ) );
private static ConfigurationPropertyCollection _properties;
#region Property Declarations
private static readonly ConfigurationProperty _propName =
new ConfigurationProperty( "name",
typeof( string ),
null,
null,
MobileControlsSection.NonEmptyStringValidator,
ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey );
private static readonly ConfigurationProperty _propAdapter =
new ConfigurationProperty( "adapter",
typeof( Type ),
null,
MobileControlsSection.StdTypeNameConverter,
new SubclassTypeValidator( typeof( IControlAdapter ) ),
ConfigurationPropertyOptions.IsRequired );
#endregion
static ControlElement()
{
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add( _propName );
_properties.Add( _propAdapter );
}
internal ControlElement()
{
}
public ControlElement( string name, Type adapter )
{
base[ _propName] = name;
base[ _propAdapter ] = adapter;
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
[StringValidator(MinLength = 1)]
public string Name
{
get
{
return (string)base[ _propName ];
}
set
{
base[ _propName ] = value;
}
}
public Type Control
{
get
{
return Type.GetType( Name );
}
set
{
if ( value == null )
{
throw new ArgumentNullException( "value" );
}
s_SubclassTypeValidator.Validate( value );
Name = value.FullName;
}
}
[ConfigurationProperty("adapter", IsRequired = true)]
[TypeConverter(typeof(MobileTypeNameConverter))]
[SubclassTypeValidator(typeof(IControlAdapter))]
public Type Adapter
{
get
{
return (Type)base[ _propAdapter ];
}
set
{
base[ _propAdapter ] = value;
}
}
protected override ConfigurationElementProperty ElementProperty
{
get
{
return s_elemProperty;
}
}
static private void ValidateElement( object value )
{
Debug.Assert( ( value != null ) && ( value is ControlElement ) );
ControlElement elem = (ControlElement)value;
// Make sure Name is a valid type
// This will throw if the type cannot be resolved
Type tp = MobileControlsSection.StdTypeNameConverter.ConvertFromInvariantString( elem.Name ) as Type;
// Validate that tp inherits from MobileControl
s_SubclassTypeValidator.Validate( tp );
}
}
// From old versions the default type names specified in mobile control config
// section do not associate with assembly names. So we cannot use
// System.Configuration.TypeNameConverter as it wouldn't look up the type
// names in the mobile assembly. To workaround it, we create the same
// converter here to be used in the mobile assembly.
[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 MobileTypeNameConverter : ConfigurationConverterBase {
public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci,
object value, Type targetType) {
Debug.Assert(targetType != null);
Type valueType = value as Type;
if (valueType == null) {
throw new ArgumentException(SR.GetString(SR.MobileTypeNameConverter_UnsupportedValueType,
((value == null) ? String.Empty : value.ToString()),
targetType.FullName));
}
return valueType.FullName;
}
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) {
Debug.Assert(data is string);
Type result = Type.GetType((string)data);
if (result == null) {
throw new ConfigurationErrorsException(
SR.GetString(SR.MobileTypeNameConverter_TypeNotResolved, (string)data));
}
return result;
}
}
}
|