merge -r 96531:96532
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / BufferModeSettings.cs
1 //
2 // System.Web.Configuration.BufferModeSettings
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.ComponentModel;
33 using System.Configuration;
34
35 #if NET_2_0
36
37 namespace System.Web.Configuration {
38
39         public sealed class BufferModeSettings : ConfigurationElement
40         {
41                 static ConfigurationProperty maxBufferSizeProp;
42                 static ConfigurationProperty maxBufferThreadsProp;
43                 static ConfigurationProperty maxFlushSizeProp;
44                 static ConfigurationProperty nameProp;
45                 static ConfigurationProperty regularFlushIntervalProp;
46                 static ConfigurationProperty urgentFlushIntervalProp;
47                 static ConfigurationProperty urgentFlushThresholdProp;
48                 static ConfigurationPropertyCollection properties;
49                 static ConfigurationElementProperty elementProperty;
50
51                 static BufferModeSettings ()
52                 {
53                         IntegerValidator iv = new IntegerValidator (1, Int32.MaxValue);
54                         
55                         maxBufferSizeProp = new ConfigurationProperty ("maxBufferSize", typeof (int), Int32.MaxValue,
56                                                                        PropertyHelper.InfiniteIntConverter, iv,
57                                                                        ConfigurationPropertyOptions.IsRequired);
58                         maxBufferThreadsProp = new ConfigurationProperty ("maxBufferThreads", typeof (int), 1,
59                                                                           PropertyHelper.InfiniteIntConverter, iv,
60                                                                           ConfigurationPropertyOptions.None);
61                         maxFlushSizeProp = new ConfigurationProperty ("maxFlushSize", typeof (int), Int32.MaxValue,
62                                                                       PropertyHelper.InfiniteIntConverter, iv,
63                                                                       ConfigurationPropertyOptions.IsRequired);
64                         nameProp = new ConfigurationProperty ("name", typeof (string), "",
65                                                               TypeDescriptor.GetConverter (typeof (string)), PropertyHelper.NonEmptyStringValidator,
66                                                               ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
67                         regularFlushIntervalProp = new ConfigurationProperty ("regularFlushInterval", typeof (TimeSpan), TimeSpan.FromSeconds (1),
68                                                                               PropertyHelper.InfiniteTimeSpanConverter,
69                                                                               PropertyHelper.PositiveTimeSpanValidator,
70                                                                               ConfigurationPropertyOptions.IsRequired);
71                         urgentFlushIntervalProp = new ConfigurationProperty ("urgentFlushInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
72                                                                              PropertyHelper.InfiniteTimeSpanConverter, null,
73                                                                              ConfigurationPropertyOptions.IsRequired);
74                         urgentFlushThresholdProp = new ConfigurationProperty ("urgentFlushThreshold", typeof (int), Int32.MaxValue,
75                                                                               PropertyHelper.InfiniteIntConverter, iv,
76                                                                               ConfigurationPropertyOptions.IsRequired);
77                         properties = new ConfigurationPropertyCollection ();
78
79                         properties.Add (nameProp);
80                         properties.Add (maxBufferSizeProp);
81                         properties.Add (maxBufferThreadsProp);
82                         properties.Add (maxFlushSizeProp);
83                         properties.Add (regularFlushIntervalProp);
84                         properties.Add (urgentFlushIntervalProp);
85                         properties.Add (urgentFlushThresholdProp);
86
87                         elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (BufferModeSettings), ValidateElement));
88                 }
89
90                 internal BufferModeSettings ()
91                 {
92                 }
93
94                 public BufferModeSettings (string name, int maxBufferSize, int maxFlushSize, int urgentFlushThreshold,
95                                            TimeSpan regularFlushInterval, TimeSpan urgentFlushInterval, int maxBufferThreads)
96                 {
97                         this.Name = name;
98                         this.MaxBufferSize = maxBufferSize;
99                         this.MaxFlushSize = maxFlushSize;
100                         this.UrgentFlushThreshold = urgentFlushThreshold;
101                         this.RegularFlushInterval = regularFlushInterval;
102                         this.UrgentFlushInterval = urgentFlushInterval;
103                         this.MaxBufferThreads = maxBufferThreads;
104                 }
105
106                 [MonoTODO("Should do some validation here")]
107                 static void ValidateElement (object o)
108                 {
109                         /* XXX do some sort of element validation here? */
110                 }
111
112                 protected override ConfigurationElementProperty ElementProperty {
113                         get { return elementProperty; }
114                 }
115
116                 [TypeConverter (typeof (InfiniteIntConverter))]
117                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
118                 [ConfigurationProperty ("maxBufferSize", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
119                 public int MaxBufferSize {
120                         get { return (int) base [maxBufferSizeProp];}
121                         set { base[maxBufferSizeProp] = value; }
122                 }
123
124                 [TypeConverter (typeof (InfiniteIntConverter))]
125                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
126                 [ConfigurationProperty ("maxBufferThreads", DefaultValue = "1")]
127                 public int MaxBufferThreads {
128                         get { return (int) base [maxBufferThreadsProp];}
129                         set { base[maxBufferThreadsProp] = value; }
130                 }
131
132                 [TypeConverter (typeof (InfiniteIntConverter))]
133                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
134                 [ConfigurationProperty ("maxFlushSize", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
135                 public int MaxFlushSize {
136                         get { return (int) base [maxFlushSizeProp];}
137                         set { base[maxFlushSizeProp] = value; }
138                 }
139
140                 [StringValidator (MinLength = 1)]
141                 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
142                 public string Name {
143                         get { return (string) base [nameProp];}
144                         set { base[nameProp] = value; }
145                 }
146
147                 [TypeConverter (typeof (InfiniteTimeSpanConverter))]
148                 [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
149                 [ConfigurationProperty ("regularFlushInterval", DefaultValue = "00:00:01", Options = ConfigurationPropertyOptions.IsRequired)]
150                 public TimeSpan RegularFlushInterval {
151                         get { return (TimeSpan) base [regularFlushIntervalProp];}
152                         set { base[regularFlushIntervalProp] = value; }
153                 }
154
155                 [TypeConverter (typeof (InfiniteTimeSpanConverter))]
156                 [ConfigurationProperty ("urgentFlushInterval", DefaultValue = "00:00:00", Options = ConfigurationPropertyOptions.IsRequired)]
157                 public TimeSpan UrgentFlushInterval {
158                         get { return (TimeSpan) base [urgentFlushIntervalProp];}
159                         set { base[urgentFlushIntervalProp] = value; }
160                 }
161
162                 [TypeConverter (typeof (InfiniteIntConverter))]
163                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
164                 [ConfigurationProperty ("urgentFlushThreshold", DefaultValue = "2147483647", Options = ConfigurationPropertyOptions.IsRequired)]
165                 public int UrgentFlushThreshold {
166                         get { return (int) base [urgentFlushThresholdProp];}
167                         set { base[urgentFlushThresholdProp] = value; }
168                 }
169
170                 protected override ConfigurationPropertyCollection Properties {
171                         get { return properties; }
172                 }
173
174         }
175
176 }
177
178 #endif
179