1 //------------------------------------------------------------------------------ 2 // <copyright file="RuleSettings.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 namespace System.Web.Configuration { 8 using System; 9 using System.Xml; 10 using System.Configuration; 11 using System.Collections.Specialized; 12 using System.Collections; 13 using System.Globalization; 14 using System.IO; 15 using System.Text; 16 using System.ComponentModel; 17 using System.Web.Hosting; 18 using System.Web.Util; 19 using System.Web.Configuration; 20 using System.Web.Management; 21 using System.Web.Compilation; 22 using System.Security.Permissions; 23 24 public sealed class RuleSettings : ConfigurationElement { 25 internal static int DEFAULT_MIN_INSTANCES = 1; 26 internal static int DEFAULT_MAX_LIMIT = int.MaxValue; 27 internal static TimeSpan DEFAULT_MIN_INTERVAL = TimeSpan.Zero; 28 internal static string DEFAULT_CUSTOM_EVAL = null; 29 30 private static ConfigurationPropertyCollection _properties; 31 32 private static readonly ConfigurationProperty _propName = 33 new ConfigurationProperty("name", 34 typeof(string), 35 null, 36 null, 37 StdValidatorsAndConverters.NonEmptyStringValidator, 38 ConfigurationPropertyOptions.IsRequired | 39 ConfigurationPropertyOptions.IsKey); 40 private static readonly ConfigurationProperty _propEventName = 41 new ConfigurationProperty("eventName", 42 typeof(string), 43 String.Empty, 44 ConfigurationPropertyOptions.IsRequired); 45 46 private static readonly ConfigurationProperty _propProvider = 47 new ConfigurationProperty("provider", 48 typeof(string), 49 String.Empty, 50 ConfigurationPropertyOptions.None); 51 52 private static readonly ConfigurationProperty _propProfile = 53 new ConfigurationProperty("profile", 54 typeof(string), 55 String.Empty, 56 ConfigurationPropertyOptions.None); 57 58 private static readonly ConfigurationProperty _propMinInstances = 59 new ConfigurationProperty("minInstances", 60 typeof(int), 61 DEFAULT_MIN_INSTANCES, 62 null, 63 StdValidatorsAndConverters.NonZeroPositiveIntegerValidator, 64 ConfigurationPropertyOptions.None); 65 66 private static readonly ConfigurationProperty _propMaxLimit = 67 new ConfigurationProperty("maxLimit", 68 typeof(int), 69 DEFAULT_MAX_LIMIT, 70 new InfiniteIntConverter(), 71 StdValidatorsAndConverters.PositiveIntegerValidator, 72 ConfigurationPropertyOptions.None); 73 74 private static readonly ConfigurationProperty _propMinInterval = 75 new ConfigurationProperty("minInterval", 76 typeof(TimeSpan), 77 DEFAULT_MIN_INTERVAL, 78 StdValidatorsAndConverters.InfiniteTimeSpanConverter, 79 null, 80 ConfigurationPropertyOptions.None); 81 82 private static readonly ConfigurationProperty _propCustom = 83 new ConfigurationProperty("custom", 84 typeof(string), 85 String.Empty, 86 ConfigurationPropertyOptions.None); 87 RuleSettings()88 static RuleSettings() { 89 // Property initialization 90 _properties = new ConfigurationPropertyCollection(); 91 _properties.Add(_propName); 92 _properties.Add(_propEventName); 93 _properties.Add(_propProvider); 94 _properties.Add(_propProfile); 95 _properties.Add(_propMinInstances); 96 _properties.Add(_propMaxLimit); 97 _properties.Add(_propMinInterval); 98 _properties.Add(_propCustom); 99 } 100 RuleSettings()101 internal RuleSettings() { 102 } 103 RuleSettings(String name, String eventName, String provider)104 public RuleSettings(String name, String eventName, String provider) 105 : this() { 106 Name = name; 107 EventName = eventName; 108 Provider = provider; 109 } 110 RuleSettings(String name, String eventName, String provider, String profile, int minInstances, int maxLimit, TimeSpan minInterval)111 public RuleSettings(String name, String eventName, String provider, String profile, int minInstances, int maxLimit, TimeSpan minInterval) 112 : this(name, eventName, provider) { 113 Profile = profile; 114 MinInstances = minInstances; 115 MaxLimit = maxLimit; 116 MinInterval = minInterval; 117 } 118 RuleSettings(String name, String eventName, String provider, String profile, int minInstances, int maxLimit, TimeSpan minInterval, string custom)119 public RuleSettings(String name, String eventName, String provider, String profile, int minInstances, int maxLimit, TimeSpan minInterval, string custom) 120 : this(name, eventName, provider) { 121 Profile = profile; 122 MinInstances = minInstances; 123 MaxLimit = maxLimit; 124 MinInterval = minInterval; 125 Custom = custom; 126 } 127 128 protected override ConfigurationPropertyCollection Properties { 129 get { 130 return _properties; 131 } 132 } 133 134 [ConfigurationProperty("name", IsRequired = true, IsKey = true, DefaultValue = "")] 135 [StringValidator(MinLength = 1)] 136 public String Name { 137 get { 138 return (string)base[_propName]; 139 } 140 set { 141 base[_propName] = value; 142 } 143 } 144 145 [ConfigurationProperty("eventName", IsRequired = true, DefaultValue = "")] 146 public String EventName { 147 get { 148 return (string)base[_propEventName]; 149 } 150 set { 151 base[_propEventName] = value; 152 } 153 } 154 155 [ConfigurationProperty("custom", DefaultValue = "")] 156 public String Custom { 157 get { 158 return (string)base[_propCustom]; 159 } 160 set { 161 base[_propCustom] = value; 162 } 163 } 164 165 [ConfigurationProperty("profile", DefaultValue = "")] 166 public String Profile { 167 get { 168 return (string)base[_propProfile]; 169 } 170 set { 171 base[_propProfile] = value; 172 } 173 } 174 175 [ConfigurationProperty("provider", DefaultValue = "")] 176 public String Provider { 177 get { 178 return (string)base[_propProvider]; 179 } 180 set { 181 base[_propProvider] = value; 182 } 183 } 184 185 [ConfigurationProperty("minInstances", DefaultValue = 1)] 186 [IntegerValidator(MinValue = 1)] 187 public int MinInstances { 188 get { 189 return (int)base[_propMinInstances]; 190 } 191 set { 192 base[_propMinInstances] = value; 193 } 194 } 195 196 [ConfigurationProperty("maxLimit", DefaultValue = int.MaxValue)] 197 [TypeConverter(typeof(InfiniteIntConverter))] 198 [IntegerValidator(MinValue = 0)] 199 public int MaxLimit { 200 get { 201 return (int)base[_propMaxLimit]; 202 } 203 set { 204 base[_propMaxLimit] = value; 205 } 206 } 207 208 [ConfigurationProperty("minInterval", DefaultValue = "00:00:00")] 209 [TypeConverter(typeof(InfiniteTimeSpanConverter))] 210 public TimeSpan MinInterval { 211 get { 212 return (TimeSpan)base[_propMinInterval]; 213 } 214 set { 215 base[_propMinInterval] = value; 216 } 217 } 218 } 219 } 220