New tests.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Configuration / XmlDictionaryReaderQuotasElement.cs
1 //
2 // XmlDictionaryReaderQuotasElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Collections.ObjectModel;
33 using System.ComponentModel;
34 using System.Configuration;
35 using System.Net;
36 using System.Net.Security;
37 using System.Reflection;
38 using System.Security.Cryptography.X509Certificates;
39 using System.Security.Principal;
40 using System.IdentityModel.Claims;
41 using System.IdentityModel.Policy;
42 using System.IdentityModel.Tokens;
43 using System.ServiceModel;
44 using System.ServiceModel.Channels;
45 using System.ServiceModel.Description;
46 using System.ServiceModel.Diagnostics;
47 using System.ServiceModel.Dispatcher;
48 using System.ServiceModel.MsmqIntegration;
49 using System.ServiceModel.PeerResolvers;
50 using System.ServiceModel.Security;
51 using System.Runtime.Serialization;
52 using System.Text;
53 using System.Xml;
54
55 namespace System.ServiceModel.Configuration
56 {
57         public sealed partial class XmlDictionaryReaderQuotasElement
58                  : ConfigurationElement
59         {
60                 // Static Fields
61                 static ConfigurationPropertyCollection properties;
62                 static ConfigurationProperty max_array_length;
63                 static ConfigurationProperty max_bytes_per_read;
64                 static ConfigurationProperty max_depth;
65                 static ConfigurationProperty max_name_table_char_count;
66                 static ConfigurationProperty max_string_content_length;
67
68                 static XmlDictionaryReaderQuotasElement ()
69                 {
70                         properties = new ConfigurationPropertyCollection ();
71                         max_array_length = new ConfigurationProperty ("maxArrayLength",
72                                 typeof (int), "0", null/* FIXME: get converter for int*/, null,
73                                 ConfigurationPropertyOptions.None);
74
75                         max_bytes_per_read = new ConfigurationProperty ("maxBytesPerRead",
76                                 typeof (int), "0", null/* FIXME: get converter for int*/, null,
77                                 ConfigurationPropertyOptions.None);
78
79                         max_depth = new ConfigurationProperty ("maxDepth",
80                                 typeof (int), "0", null/* FIXME: get converter for int*/, null,
81                                 ConfigurationPropertyOptions.None);
82
83                         max_name_table_char_count = new ConfigurationProperty ("maxNameTableCharCount",
84                                 typeof (int), "0", null/* FIXME: get converter for int*/, null,
85                                 ConfigurationPropertyOptions.None);
86
87                         max_string_content_length = new ConfigurationProperty ("maxStringContentLength",
88                                 typeof (int), "0", null/* FIXME: get converter for int*/, null,
89                                 ConfigurationPropertyOptions.None);
90
91                         properties.Add (max_array_length);
92                         properties.Add (max_bytes_per_read);
93                         properties.Add (max_depth);
94                         properties.Add (max_name_table_char_count);
95                         properties.Add (max_string_content_length);
96                 }
97
98                 public XmlDictionaryReaderQuotasElement ()
99                 {
100                 }
101
102
103                 // Properties
104
105                 [IntegerValidator ( MinValue = 0,
106                         MaxValue = int.MaxValue,
107                         ExcludeRange = false)]
108                 [ConfigurationProperty ("maxArrayLength",
109                          DefaultValue = "0",
110                          Options = ConfigurationPropertyOptions.None)]
111                 public int MaxArrayLength {
112                         get { return (int) base [max_array_length]; }
113                         set { base [max_array_length] = value; }
114                 }
115
116                 [IntegerValidator ( MinValue = 0,
117                         MaxValue = int.MaxValue,
118                         ExcludeRange = false)]
119                 [ConfigurationProperty ("maxBytesPerRead",
120                          DefaultValue = "0",
121                          Options = ConfigurationPropertyOptions.None)]
122                 public int MaxBytesPerRead {
123                         get { return (int) base [max_bytes_per_read]; }
124                         set { base [max_bytes_per_read] = value; }
125                 }
126
127                 [IntegerValidator ( MinValue = 0,
128                         MaxValue = int.MaxValue,
129                         ExcludeRange = false)]
130                 [ConfigurationProperty ("maxDepth",
131                          DefaultValue = "0",
132                          Options = ConfigurationPropertyOptions.None)]
133                 public int MaxDepth {
134                         get { return (int) base [max_depth]; }
135                         set { base [max_depth] = value; }
136                 }
137
138                 [IntegerValidator ( MinValue = 0,
139                         MaxValue = int.MaxValue,
140                         ExcludeRange = false)]
141                 [ConfigurationProperty ("maxNameTableCharCount",
142                          DefaultValue = "0",
143                          Options = ConfigurationPropertyOptions.None)]
144                 public int MaxNameTableCharCount {
145                         get { return (int) base [max_name_table_char_count]; }
146                         set { base [max_name_table_char_count] = value; }
147                 }
148
149                 [ConfigurationProperty ("maxStringContentLength",
150                          DefaultValue = "0",
151                          Options = ConfigurationPropertyOptions.None)]
152                 [IntegerValidator ( MinValue = 0,
153                         MaxValue = int.MaxValue,
154                         ExcludeRange = false)]
155                 public int MaxStringContentLength {
156                         get { return (int) base [max_string_content_length]; }
157                         set { base [max_string_content_length] = value; }
158                 }
159
160                 protected override ConfigurationPropertyCollection Properties {
161                         get { return properties; }
162                 }
163
164                 internal XmlDictionaryReaderQuotas Create ()
165                 {
166                         var q =  new XmlDictionaryReaderQuotas ();
167                         ApplyConfiguration (q);
168                         return q;
169                 }
170                 
171                 internal void ApplyConfiguration (XmlDictionaryReaderQuotas q)
172                 {
173                         if (MaxArrayLength > 0)
174                                 q.MaxArrayLength = MaxArrayLength;
175                         if (MaxBytesPerRead > 0)
176                                 q.MaxBytesPerRead = MaxBytesPerRead;
177                         if (MaxDepth > 0)
178                                 q.MaxDepth = MaxDepth;
179                         if (MaxNameTableCharCount > 0)
180                                 q.MaxNameTableCharCount = MaxNameTableCharCount;
181                         if (MaxStringContentLength > 0)
182                                 q.MaxStringContentLength = MaxStringContentLength;
183                 }
184
185                 internal void ApplyConfiguration (XmlDictionaryReaderQuotasElement q)
186                 {
187                         if (MaxArrayLength > 0)
188                                 q.MaxArrayLength = MaxArrayLength;
189                         if (MaxBytesPerRead > 0)
190                                 q.MaxBytesPerRead = MaxBytesPerRead;
191                         if (MaxDepth > 0)
192                                 q.MaxDepth = MaxDepth;
193                         if (MaxNameTableCharCount > 0)
194                                 q.MaxNameTableCharCount = MaxNameTableCharCount;
195                         if (MaxStringContentLength > 0)
196                                 q.MaxStringContentLength = MaxStringContentLength;
197                 }
198
199                 internal void InitializeFrom (XmlDictionaryReaderQuotas q)
200                 {
201                         if (q.MaxArrayLength > 0)
202                                 MaxArrayLength = q.MaxArrayLength;
203                         if (q.MaxBytesPerRead > 0)
204                                 MaxBytesPerRead = q.MaxBytesPerRead;
205                         if (q.MaxDepth > 0)
206                                 MaxDepth = q.MaxDepth;
207                         if (q.MaxNameTableCharCount > 0)
208                                 MaxNameTableCharCount = q.MaxNameTableCharCount;
209                         if (q.MaxStringContentLength > 0)
210                                 MaxStringContentLength = q.MaxStringContentLength;
211                 }
212
213                 internal void CopyFrom (XmlDictionaryReaderQuotasElement q)
214                 {
215                         if (q.MaxArrayLength > 0)
216                                 MaxArrayLength = q.MaxArrayLength;
217                         if (q.MaxBytesPerRead > 0)
218                                 MaxBytesPerRead = q.MaxBytesPerRead;
219                         if (q.MaxDepth > 0)
220                                 MaxDepth = q.MaxDepth;
221                         if (q.MaxNameTableCharCount > 0)
222                                 MaxNameTableCharCount = q.MaxNameTableCharCount;
223                         if (q.MaxStringContentLength > 0)
224                                 MaxStringContentLength = q.MaxStringContentLength;
225                 }
226         }
227
228 }