BufferModeSettings.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // System.Web.Configuration.BufferModeSettings
  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 BufferModeSettings : ConfigurationElement
  35. {
  36. static ConfigurationProperty maxBufferSizeProp;
  37. static ConfigurationProperty maxBufferThreadsProp;
  38. static ConfigurationProperty maxFlushSizeProp;
  39. static ConfigurationProperty nameProp;
  40. static ConfigurationProperty regularFlushIntervalProp;
  41. static ConfigurationProperty urgentFlushIntervalProp;
  42. static ConfigurationProperty urgentFlushThresholdProp;
  43. static ConfigurationPropertyCollection properties;
  44. static ConfigurationElementProperty elementProperty;
  45. static BufferModeSettings ()
  46. {
  47. IntegerValidator iv = new IntegerValidator (1, Int32.MaxValue);
  48. maxBufferSizeProp = new ConfigurationProperty ("maxBufferSize", typeof (int), Int32.MaxValue,
  49. PropertyHelper.InfiniteIntConverter, iv,
  50. ConfigurationPropertyOptions.IsRequired);
  51. maxBufferThreadsProp = new ConfigurationProperty ("maxBufferThreads", typeof (int), 1,
  52. PropertyHelper.InfiniteIntConverter, iv,
  53. ConfigurationPropertyOptions.None);
  54. maxFlushSizeProp = new ConfigurationProperty ("maxFlushSize", typeof (int), Int32.MaxValue,
  55. PropertyHelper.InfiniteIntConverter, iv,
  56. ConfigurationPropertyOptions.IsRequired);
  57. nameProp = new ConfigurationProperty ("name", typeof (string), "",
  58. TypeDescriptor.GetConverter (typeof (string)), PropertyHelper.NonEmptyStringValidator,
  59. ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  60. regularFlushIntervalProp = new ConfigurationProperty ("regularFlushInterval", typeof (TimeSpan), TimeSpan.FromSeconds (1),
  61. PropertyHelper.InfiniteTimeSpanConverter,
  62. PropertyHelper.PositiveTimeSpanValidator,
  63. ConfigurationPropertyOptions.IsRequired);
  64. urgentFlushIntervalProp = new ConfigurationProperty ("urgentFlushInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
  65. PropertyHelper.InfiniteTimeSpanConverter, null,
  66. ConfigurationPropertyOptions.IsRequired);
  67. urgentFlushThresholdProp = new ConfigurationProperty ("urgentFlushThreshold", typeof (int), Int32.MaxValue,
  68. PropertyHelper.InfiniteIntConverter, iv,
  69. ConfigurationPropertyOptions.IsRequired);
  70. properties = new ConfigurationPropertyCollection ();
  71. properties.Add (nameProp);
  72. properties.Add (maxBufferSizeProp);
  73. properties.Add (maxBufferThreadsProp);
  74. properties.Add (maxFlushSizeProp);
  75. properties.Add (regularFlushIntervalProp);
  76. properties.Add (urgentFlushIntervalProp);
  77. properties.Add (urgentFlushThresholdProp);
  78. elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (BufferModeSettings), ValidateElement));
  79. }
  80. internal BufferModeSettings ()
  81. {
  82. }
  83. public BufferModeSettings (string name, int maxBufferSize, int maxFlushSize, int urgentFlushThreshold,
  84. TimeSpan regularFlushInterval, TimeSpan urgentFlushInterval, int maxBufferThreads)
  85. {
  86. this.Name = name;
  87. this.MaxBufferSize = maxBufferSize;
  88. this.MaxFlushSize = maxFlushSize;
  89. this.UrgentFlushThreshold = urgentFlushThreshold;
  90. this.RegularFlushInterval = regularFlushInterval;
  91. this.UrgentFlushInterval = urgentFlushInterval;
  92. this.MaxBufferThreads = maxBufferThreads;
  93. }
  94. [MonoTODO]
  95. static void ValidateElement (object o)
  96. {
  97. /* XXX do some sort of element validation here? */
  98. }
  99. protected override ConfigurationElementProperty ElementProperty {
  100. get { return elementProperty; }
  101. }
  102. [TypeConverter (typeof (InfiniteIntConverter))]
  103. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  104. [ConfigurationProperty ("maxBufferSize", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
  105. public int MaxBufferSize {
  106. get { return (int) base [maxBufferSizeProp];}
  107. set { base[maxBufferSizeProp] = value; }
  108. }
  109. [TypeConverter (typeof (InfiniteIntConverter))]
  110. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  111. [ConfigurationProperty ("maxBufferThreads", DefaultValue = "1")]
  112. public int MaxBufferThreads {
  113. get { return (int) base [maxBufferThreadsProp];}
  114. set { base[maxBufferThreadsProp] = value; }
  115. }
  116. [TypeConverter (typeof (InfiniteIntConverter))]
  117. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  118. [ConfigurationProperty ("maxFlushSize", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
  119. public int MaxFlushSize {
  120. get { return (int) base [maxFlushSizeProp];}
  121. set { base[maxFlushSizeProp] = value; }
  122. }
  123. [StringValidator (MinLength = 1)]
  124. [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  125. public string Name {
  126. get { return (string) base [nameProp];}
  127. set { base[nameProp] = value; }
  128. }
  129. [TypeConverter (typeof (InfiniteTimeSpanConverter))]
  130. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  131. [ConfigurationProperty ("regularFlushInterval", DefaultValue = "00:00:01", Options = ConfigurationPropertyOptions.IsRequired)]
  132. public TimeSpan RegularFlushInterval {
  133. get { return (TimeSpan) base [regularFlushIntervalProp];}
  134. set { base[regularFlushIntervalProp] = value; }
  135. }
  136. [TypeConverter (typeof (InfiniteTimeSpanConverter))]
  137. [ConfigurationProperty ("urgentFlushInterval", DefaultValue = "00:00:00", Options = ConfigurationPropertyOptions.IsRequired)]
  138. public TimeSpan UrgentFlushInterval {
  139. get { return (TimeSpan) base [urgentFlushIntervalProp];}
  140. set { base[urgentFlushIntervalProp] = value; }
  141. }
  142. [TypeConverter (typeof (InfiniteIntConverter))]
  143. [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
  144. [ConfigurationProperty ("urgentFlushThreshold", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
  145. public int UrgentFlushThreshold {
  146. get { return (int) base [urgentFlushThresholdProp];}
  147. set { base[urgentFlushThresholdProp] = value; }
  148. }
  149. protected override ConfigurationPropertyCollection Properties {
  150. get { return properties; }
  151. }
  152. }
  153. }
  154. #endif