ProfileSettings.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // System.Web.Configuration.ProfileSettings
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.ComponentModel;
  31. using System.Configuration;
  32. #if NET_2_0
  33. namespace System.Web.Configuration {
  34. public sealed class ProfileSettings : ConfigurationElement
  35. {
  36. static ConfigurationProperty customProp;
  37. static ConfigurationProperty maxLimitProp;
  38. static ConfigurationProperty minInstancesProp;
  39. static ConfigurationProperty minIntervalProp;
  40. static ConfigurationProperty nameProp;
  41. static ConfigurationPropertyCollection properties;
  42. static ProfileSettings ()
  43. {
  44. customProp = new ConfigurationProperty ("custom", typeof (string), "");
  45. maxLimitProp = new ConfigurationProperty ("maxLimit", typeof (int), Int32.MaxValue,
  46. PropertyHelper.InfiniteIntConverter,
  47. PropertyHelper.IntFromZeroToMaxValidator,
  48. ConfigurationPropertyOptions.None);
  49. minInstancesProp = new ConfigurationProperty ("minInstances", typeof (int), 1,
  50. TypeDescriptor.GetConverter (typeof (int)),
  51. new IntegerValidator (1, Int32.MaxValue),
  52. ConfigurationPropertyOptions.None);
  53. minIntervalProp = new ConfigurationProperty ("minInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
  54. PropertyHelper.InfiniteTimeSpanConverter,
  55. PropertyHelper.DefaultValidator,
  56. ConfigurationPropertyOptions.None);
  57. nameProp = new ConfigurationProperty ("name", typeof (string), "",
  58. TypeDescriptor.GetConverter (typeof (string)),
  59. PropertyHelper.NonEmptyStringValidator,
  60. ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  61. properties = new ConfigurationPropertyCollection ();
  62. properties.Add (customProp);
  63. properties.Add (maxLimitProp);
  64. properties.Add (minInstancesProp);
  65. properties.Add (minIntervalProp);
  66. properties.Add (nameProp);
  67. }
  68. internal ProfileSettings ()
  69. {
  70. }
  71. public ProfileSettings (string name)
  72. {
  73. this.Name = name;
  74. }
  75. public ProfileSettings (string name, int minInstances, int maxLimit, TimeSpan minInterval, string custom)
  76. {
  77. this.Name = name;
  78. this.MinInstances = minInstances;
  79. this.MaxLimit = maxLimit;
  80. this.MinInterval = MinInterval;
  81. this.Custom = custom;
  82. }
  83. public ProfileSettings (string name, int minInstances, int maxLimit, TimeSpan minInterval)
  84. {
  85. this.Name = name;
  86. this.MinInstances = minInstances;
  87. this.MaxLimit = maxLimit;
  88. this.MinInterval = MinInterval;
  89. }
  90. [ConfigurationProperty ("custom", DefaultValue = "")]
  91. public string Custom {
  92. get { return (string) base [customProp];}
  93. set { base[customProp] = value; }
  94. }
  95. [TypeConverter (typeof (InfiniteIntConverter))]
  96. [IntegerValidator (MinValue = 0, MaxValue = Int32.MaxValue)]
  97. [ConfigurationProperty ("maxLimit", DefaultValue = Int32.MaxValue)]
  98. public int MaxLimit {
  99. get { return (int) base [maxLimitProp];}
  100. set { base[maxLimitProp] = value; }
  101. }
  102. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  103. [ConfigurationProperty ("minInstances", DefaultValue = "1")]
  104. public int MinInstances {
  105. get { return (int) base [minInstancesProp];}
  106. set { base[minInstancesProp] = value; }
  107. }
  108. [TypeConverter (typeof (InfiniteTimeSpanConverter))]
  109. [ConfigurationProperty ("minInterval", DefaultValue = "00:00:00")]
  110. public TimeSpan MinInterval {
  111. get { return (TimeSpan) base [minIntervalProp];}
  112. set { base[minIntervalProp] = value; }
  113. }
  114. [StringValidator (MinLength = 1)]
  115. [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  116. public string Name {
  117. get { return (string) base [nameProp];}
  118. set { base[nameProp] = value; }
  119. }
  120. protected override ConfigurationPropertyCollection Properties {
  121. get { return properties; }
  122. }
  123. }
  124. }
  125. #endif