2009-11-19 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / ProfileSettings.cs
1 //
2 // System.Web.Configuration.ProfileSettings
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 ProfileSettings : ConfigurationElement
40         {
41                 static ConfigurationProperty customProp;
42                 static ConfigurationProperty maxLimitProp;
43                 static ConfigurationProperty minInstancesProp;
44                 static ConfigurationProperty minIntervalProp;
45                 static ConfigurationProperty nameProp;
46                 static ConfigurationPropertyCollection properties;
47
48                 static ProfileSettings ()
49                 {
50                         customProp = new ConfigurationProperty ("custom", typeof (string), "");
51                         maxLimitProp = new ConfigurationProperty ("maxLimit", typeof (int), Int32.MaxValue,
52                                                                   PropertyHelper.InfiniteIntConverter,
53                                                                   PropertyHelper.IntFromZeroToMaxValidator,
54                                                                   ConfigurationPropertyOptions.None);
55                         minInstancesProp = new ConfigurationProperty ("minInstances", typeof (int), 1,
56                                                                       TypeDescriptor.GetConverter (typeof (int)),
57                                                                       new IntegerValidator (1, Int32.MaxValue),
58                                                                       ConfigurationPropertyOptions.None);
59                         minIntervalProp = new ConfigurationProperty ("minInterval", typeof (TimeSpan), TimeSpan.FromSeconds (0),
60                                                                      PropertyHelper.InfiniteTimeSpanConverter,
61                                                                      PropertyHelper.DefaultValidator,
62                                                                      ConfigurationPropertyOptions.None);
63                         nameProp = new ConfigurationProperty ("name", typeof (string), "",
64                                                               TypeDescriptor.GetConverter (typeof (string)),
65                                                               PropertyHelper.NonEmptyStringValidator,
66                                                               ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
67                         properties = new ConfigurationPropertyCollection ();
68
69                         properties.Add (customProp);
70                         properties.Add (maxLimitProp);
71                         properties.Add (minInstancesProp);
72                         properties.Add (minIntervalProp);
73                         properties.Add (nameProp);
74
75                 }
76
77                 internal ProfileSettings ()
78                 {
79                 }
80
81                 public ProfileSettings (string name)
82                 {
83                         this.Name = name;
84                 }
85
86                 public ProfileSettings (string name, int minInstances, int maxLimit, TimeSpan minInterval, string custom)
87                 {
88                         this.Name = name;
89                         this.MinInstances = minInstances;
90                         this.MaxLimit = maxLimit;
91                         this.MinInterval = MinInterval;
92                         this.Custom = custom;
93                 }
94
95                 public ProfileSettings (string name, int minInstances, int maxLimit, TimeSpan minInterval)
96                 {
97                         this.Name = name;
98                         this.MinInstances = minInstances;
99                         this.MaxLimit = maxLimit;
100                         this.MinInterval = MinInterval;
101                 }
102
103                 [ConfigurationProperty ("custom", DefaultValue = "")]
104                 public string Custom {
105                         get { return (string) base [customProp];}
106                         set { base[customProp] = value; }
107                 }
108
109                 [TypeConverter (typeof (InfiniteIntConverter))]
110                 [IntegerValidator (MinValue = 0, MaxValue = Int32.MaxValue)]
111                 [ConfigurationProperty ("maxLimit", DefaultValue = Int32.MaxValue)]
112                 public int MaxLimit {
113                         get { return (int) base [maxLimitProp];}
114                         set { base[maxLimitProp] = value; }
115                 }
116
117                 [IntegerValidator (MinValue = 1, MaxValue = Int32.MaxValue)]
118                 [ConfigurationProperty ("minInstances", DefaultValue = "1")]
119                 public int MinInstances {
120                         get { return (int) base [minInstancesProp];}
121                         set { base[minInstancesProp] = value; }
122                 }
123
124                 [TypeConverter (typeof (InfiniteTimeSpanConverter))]
125                 [ConfigurationProperty ("minInterval", DefaultValue = "00:00:00")]
126                 public TimeSpan MinInterval {
127                         get { return (TimeSpan) base [minIntervalProp];}
128                         set { base[minIntervalProp] = value; }
129                 }
130
131                 [StringValidator (MinLength = 1)]
132                 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
133                 public string Name {
134                         get { return (string) base [nameProp];}
135                         set { base[nameProp] = value; }
136                 }
137
138                 protected override ConfigurationPropertyCollection Properties {
139                         get { return properties; }
140                 }
141
142         }
143
144 }
145
146 #endif
147