RuleSettings.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // System.Web.Configuration.RuleSettings
  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 RuleSettings : ConfigurationElement
  35. {
  36. static ConfigurationProperty customProp;
  37. static ConfigurationProperty eventNameProp;
  38. static ConfigurationProperty maxLimitProp;
  39. static ConfigurationProperty minInstancesProp;
  40. static ConfigurationProperty minIntervalProp;
  41. static ConfigurationProperty nameProp;
  42. static ConfigurationProperty profileProp;
  43. static ConfigurationProperty providerProp;
  44. static ConfigurationPropertyCollection properties;
  45. static RuleSettings ()
  46. {
  47. customProp = new ConfigurationProperty ("custom", typeof (string), "");
  48. eventNameProp = new ConfigurationProperty ("eventName", typeof (string), "", ConfigurationPropertyOptions.IsRequired);
  49. maxLimitProp = new ConfigurationProperty ("maxLimit", typeof (int), Int32.MaxValue,
  50. PropertyHelper.InfiniteIntConverter,
  51. PropertyHelper.IntFromZeroToMaxValidator,
  52. ConfigurationPropertyOptions.None);
  53. minInstancesProp = new ConfigurationProperty ("minInstances", typeof (int), 1,
  54. TypeDescriptor.GetConverter (typeof (int)),
  55. new IntegerValidator (1, Int32.MaxValue),
  56. ConfigurationPropertyOptions.None);
  57. minIntervalProp = new ConfigurationProperty ("minInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
  58. PropertyHelper.InfiniteTimeSpanConverter, null,
  59. ConfigurationPropertyOptions.None);
  60. nameProp = new ConfigurationProperty ("name", typeof (string), "",
  61. TypeDescriptor.GetConverter (typeof (string)),
  62. PropertyHelper.NonEmptyStringValidator,
  63. ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  64. profileProp = new ConfigurationProperty ("profile", typeof (string), "");
  65. providerProp = new ConfigurationProperty ("provider", typeof (string), "");
  66. properties = new ConfigurationPropertyCollection ();
  67. properties.Add (customProp);
  68. properties.Add (eventNameProp);
  69. properties.Add (maxLimitProp);
  70. properties.Add (minInstancesProp);
  71. properties.Add (minIntervalProp);
  72. properties.Add (nameProp);
  73. properties.Add (profileProp);
  74. properties.Add (providerProp);
  75. }
  76. internal RuleSettings ()
  77. {
  78. }
  79. public RuleSettings (string name, string eventName, string provider, string profile, int minInstances, int maxLimit, TimeSpan minInterval, string custom)
  80. {
  81. this.Name = name;
  82. this.EventName = eventName;
  83. this.Provider = provider;
  84. this.Profile = profile;
  85. this.MinInstances = minInstances;
  86. this.MaxLimit = maxLimit;
  87. this.MinInterval = minInterval;
  88. this.Custom = custom;
  89. }
  90. public RuleSettings (string name, string eventName, string provider, string profile, int minInstances, int maxLimit, TimeSpan minInterval)
  91. {
  92. this.Name = name;
  93. this.EventName = eventName;
  94. this.Provider = provider;
  95. this.Profile = profile;
  96. this.MinInstances = minInstances;
  97. this.MaxLimit = maxLimit;
  98. this.MinInterval = minInterval;
  99. }
  100. public RuleSettings (string name, string eventName, string provider)
  101. {
  102. this.Name = name;
  103. this.EventName = eventName;
  104. this.Provider = provider;
  105. }
  106. [ConfigurationProperty ("custom", DefaultValue = "")]
  107. public string Custom {
  108. get { return (string) base [customProp];}
  109. set { base[customProp] = value; }
  110. }
  111. [ConfigurationProperty ("eventName", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
  112. public string EventName {
  113. get { return (string) base [eventNameProp];}
  114. set { base[eventNameProp] = value; }
  115. }
  116. [TypeConverter (typeof (InfiniteIntConverter))]
  117. [IntegerValidator (MinValue = 0, MaxValue = Int32.MaxValue)]
  118. [ConfigurationProperty ("maxLimit", DefaultValue = "2147483647")]
  119. public int MaxLimit {
  120. get { return (int) base [maxLimitProp];}
  121. set { base[maxLimitProp] = value; }
  122. }
  123. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  124. [ConfigurationProperty ("minInstances", DefaultValue = "1")]
  125. public int MinInstances {
  126. get { return (int) base [minInstancesProp];}
  127. set { base[minInstancesProp] = value; }
  128. }
  129. [TypeConverter (typeof (InfiniteTimeSpanConverter))]
  130. [ConfigurationProperty ("minInterval", DefaultValue = "00:00:00")]
  131. public TimeSpan MinInterval {
  132. get { return (TimeSpan) base [minIntervalProp];}
  133. set { base[minIntervalProp] = value; }
  134. }
  135. [StringValidator (MinLength = 1)]
  136. [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  137. public string Name {
  138. get { return (string) base [nameProp];}
  139. set { base[nameProp] = value; }
  140. }
  141. [ConfigurationProperty ("profile", DefaultValue = "")]
  142. public string Profile {
  143. get { return (string) base [profileProp];}
  144. set { base[profileProp] = value; }
  145. }
  146. [ConfigurationProperty ("provider", DefaultValue = "")]
  147. public string Provider {
  148. get { return (string) base [providerProp];}
  149. set { base[providerProp] = value; }
  150. }
  151. protected override ConfigurationPropertyCollection Properties {
  152. get { return properties; }
  153. }
  154. }
  155. }
  156. #endif