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