2008-05-22 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / RuleSettings.cs
1 //
2 // System.Web.Configuration.RuleSettings
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 RuleSettings : ConfigurationElement
40         {
41                 static ConfigurationProperty customProp;
42                 static ConfigurationProperty eventNameProp;
43                 static ConfigurationProperty maxLimitProp;
44                 static ConfigurationProperty minInstancesProp;
45                 static ConfigurationProperty minIntervalProp;
46                 static ConfigurationProperty nameProp;
47                 static ConfigurationProperty profileProp;
48                 static ConfigurationProperty providerProp;
49                 static ConfigurationPropertyCollection properties;
50
51                 static RuleSettings ()
52                 {
53                         customProp = new ConfigurationProperty ("custom", typeof (string), "");
54                         eventNameProp = new ConfigurationProperty ("eventName", typeof (string), "", ConfigurationPropertyOptions.IsRequired);
55                         maxLimitProp = new ConfigurationProperty ("maxLimit", typeof (int), Int32.MaxValue,
56                                                                   PropertyHelper.InfiniteIntConverter,
57                                                                   PropertyHelper.IntFromZeroToMaxValidator,
58                                                                   ConfigurationPropertyOptions.None);
59                         minInstancesProp = new ConfigurationProperty ("minInstances", typeof (int), 1,
60                                                                       TypeDescriptor.GetConverter (typeof (int)),
61                                                                       new IntegerValidator (1, Int32.MaxValue),
62                                                                       ConfigurationPropertyOptions.None);
63                         minIntervalProp = new ConfigurationProperty ("minInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
64                                                                      PropertyHelper.InfiniteTimeSpanConverter, null,
65                                                                      ConfigurationPropertyOptions.None);
66                         nameProp = new ConfigurationProperty ("name", typeof (string), "",
67                                                               TypeDescriptor.GetConverter (typeof (string)),
68                                                               PropertyHelper.NonEmptyStringValidator,
69                                                               ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
70                         profileProp = new ConfigurationProperty ("profile", typeof (string), "");
71                         providerProp = new ConfigurationProperty ("provider", typeof (string), "");
72                         properties = new ConfigurationPropertyCollection ();
73
74                         properties.Add (customProp);
75                         properties.Add (eventNameProp);
76                         properties.Add (maxLimitProp);
77                         properties.Add (minInstancesProp);
78                         properties.Add (minIntervalProp);
79                         properties.Add (nameProp);
80                         properties.Add (profileProp);
81                         properties.Add (providerProp);
82                 }
83
84                 internal RuleSettings ()
85                 {
86                 }
87
88                 public RuleSettings (string name, string eventName, string provider, string profile, int minInstances, int maxLimit, TimeSpan minInterval, string custom)
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                         this.Custom = custom;
98                 }
99
100                 public RuleSettings (string name, string eventName, string provider, string profile, int minInstances, int maxLimit, TimeSpan minInterval)
101                 {
102                         this.Name = name;
103                         this.EventName = eventName;
104                         this.Provider = provider;
105                         this.Profile = profile;
106                         this.MinInstances = minInstances;
107                         this.MaxLimit = maxLimit;
108                         this.MinInterval = minInterval;
109                 }
110
111                 public RuleSettings (string name, string eventName, string provider)
112                 {
113                         this.Name = name;
114                         this.EventName = eventName;
115                         this.Provider = provider;
116                 }
117
118                 [ConfigurationProperty ("custom", DefaultValue = "")]
119                 public string Custom {
120                         get { return (string) base [customProp];}
121                         set { base[customProp] = value; }
122                 }
123
124                 [ConfigurationProperty ("eventName", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
125                 public string EventName {
126                         get { return (string) base [eventNameProp];}
127                         set { base[eventNameProp] = value; }
128                 }
129
130                 [TypeConverter (typeof (InfiniteIntConverter))]
131                 [IntegerValidator (MinValue = 0, MaxValue = Int32.MaxValue)]
132                 [ConfigurationProperty ("maxLimit", DefaultValue = "2147483647")]
133                 public int MaxLimit {
134                         get { return (int) base [maxLimitProp];}
135                         set { base[maxLimitProp] = value; }
136                 }
137
138                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
139                 [ConfigurationProperty ("minInstances", DefaultValue = "1")]
140                 public int MinInstances {
141                         get { return (int) base [minInstancesProp];}
142                         set { base[minInstancesProp] = value; }
143                 }
144
145                 [TypeConverter (typeof (InfiniteTimeSpanConverter))]
146                 [ConfigurationProperty ("minInterval", DefaultValue = "00:00:00")]
147                 public TimeSpan MinInterval {
148                         get { return (TimeSpan) base [minIntervalProp];}
149                         set { base[minIntervalProp] = value; }
150                 }
151
152                 [StringValidator (MinLength = 1)]
153                 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
154                 public string Name {
155                         get { return (string) base [nameProp];}
156                         set { base[nameProp] = value; }
157                 }
158
159                 [ConfigurationProperty ("profile", DefaultValue = "")]
160                 public string Profile {
161                         get { return (string) base [profileProp];}
162                         set { base[profileProp] = value; }
163                 }
164
165                 [ConfigurationProperty ("provider", DefaultValue = "")]
166                 public string Provider {
167                         get { return (string) base [providerProp];}
168                         set { base[providerProp] = value; }
169                 }
170
171                 protected override ConfigurationPropertyCollection Properties {
172                         get { return properties; }
173                 }
174
175         }
176
177 }
178
179 #endif
180