RuleSettings.cs 6.2 KB

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