New tests.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Configuration / MsmqElementBase.cs
1 //
2 // MsmqElementBase.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006,2010 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 abstract class MsmqElementBase
58                  : TransportElement
59         {
60                 ConfigurationPropertyCollection _properties;
61
62                 protected MsmqElementBase () {
63                 }
64
65
66                 // Properties
67
68                 [ConfigurationProperty ("customDeadLetterQueue",
69                          Options = ConfigurationPropertyOptions.None,
70                          DefaultValue = null)]
71                 public Uri CustomDeadLetterQueue {
72                         get { return (Uri) base ["customDeadLetterQueue"]; }
73                         set { base ["customDeadLetterQueue"] = value; }
74                 }
75
76                 [ConfigurationProperty ("deadLetterQueue",
77                          Options = ConfigurationPropertyOptions.None,
78                          DefaultValue = "System")]
79                 public DeadLetterQueue DeadLetterQueue {
80                         get { return (DeadLetterQueue) base ["deadLetterQueue"]; }
81                         set { base ["deadLetterQueue"] = value; }
82                 }
83
84                 [ConfigurationProperty ("durable",
85                          Options = ConfigurationPropertyOptions.None,
86                         DefaultValue = true)]
87                 public bool Durable {
88                         get { return (bool) base ["durable"]; }
89                         set { base ["durable"] = value; }
90                 }
91
92                 [ConfigurationProperty ("exactlyOnce",
93                          Options = ConfigurationPropertyOptions.None,
94                         DefaultValue = true)]
95                 public bool ExactlyOnce {
96                         get { return (bool) base ["exactlyOnce"]; }
97                         set { base ["exactlyOnce"] = value; }
98                 }
99
100                 [ConfigurationProperty ("maxRetryCycles",
101                          Options = ConfigurationPropertyOptions.None,
102                          DefaultValue = "2")]
103                 [IntegerValidator (MinValue = 0,
104                         MaxValue = int.MaxValue,
105                         ExcludeRange = false)]
106                 public int MaxRetryCycles {
107                         get { return (int) base ["maxRetryCycles"]; }
108                         set { base ["maxRetryCycles"] = value; }
109                 }
110
111                 [ConfigurationProperty ("msmqTransportSecurity",
112                          Options = ConfigurationPropertyOptions.None)]
113                 public MsmqTransportSecurityElement MsmqTransportSecurity {
114                         get { return (MsmqTransportSecurityElement) base ["msmqTransportSecurity"]; }
115                 }
116
117                 protected override ConfigurationPropertyCollection Properties {
118                         get {
119                                 if (_properties == null) {
120                                         _properties = base.Properties;
121                                         _properties.Add (new ConfigurationProperty ("customDeadLetterQueue", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
122                                         _properties.Add (new ConfigurationProperty ("deadLetterQueue", typeof (DeadLetterQueue), "System", null, null, ConfigurationPropertyOptions.None));
123                                         _properties.Add (new ConfigurationProperty ("durable", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
124                                         _properties.Add (new ConfigurationProperty ("exactlyOnce", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
125                                         _properties.Add (new ConfigurationProperty ("maxRetryCycles", typeof (int), "2", null, new IntegerValidator (0, int.MaxValue, false), ConfigurationPropertyOptions.None));
126                                         _properties.Add (new ConfigurationProperty ("msmqTransportSecurity", typeof (MsmqTransportSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
127                                         _properties.Add (new ConfigurationProperty ("receiveErrorHandling", typeof (ReceiveErrorHandling), "Fault", null, null, ConfigurationPropertyOptions.None));
128                                         _properties.Add (new ConfigurationProperty ("receiveRetryCount", typeof (int), "5", null, new IntegerValidator (0, int.MaxValue, false), ConfigurationPropertyOptions.None));
129                                         _properties.Add (new ConfigurationProperty ("retryCycleDelay", typeof (TimeSpan), "00:30:00", null, null, ConfigurationPropertyOptions.None));
130                                         _properties.Add (new ConfigurationProperty ("timeToLive", typeof (TimeSpan), "1.00:00:00", null, null, ConfigurationPropertyOptions.None));
131                                         _properties.Add (new ConfigurationProperty ("useMsmqTracing", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
132                                         _properties.Add (new ConfigurationProperty ("useSourceJournal", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
133                                 }
134                                 return _properties;
135                         }
136                 }
137
138                 [ConfigurationProperty ("receiveErrorHandling",
139                          Options = ConfigurationPropertyOptions.None,
140                          DefaultValue = "Fault")]
141                 public ReceiveErrorHandling ReceiveErrorHandling {
142                         get { return (ReceiveErrorHandling) base ["receiveErrorHandling"]; }
143                         set { base ["receiveErrorHandling"] = value; }
144                 }
145
146                 [ConfigurationProperty ("receiveRetryCount",
147                          Options = ConfigurationPropertyOptions.None,
148                          DefaultValue = "5")]
149                 [IntegerValidator (MinValue = 0,
150                         MaxValue = int.MaxValue,
151                         ExcludeRange = false)]
152                 public int ReceiveRetryCount {
153                         get { return (int) base ["receiveRetryCount"]; }
154                         set { base ["receiveRetryCount"] = value; }
155                 }
156
157                 [ConfigurationProperty ("retryCycleDelay",
158                          Options = ConfigurationPropertyOptions.None,
159                          DefaultValue = "00:30:00")]
160                 public TimeSpan RetryCycleDelay {
161                         get { return (TimeSpan) base ["retryCycleDelay"]; }
162                         set { base ["retryCycleDelay"] = value; }
163                 }
164
165                 [ConfigurationProperty ("timeToLive",
166                          Options = ConfigurationPropertyOptions.None,
167                          DefaultValue = "1.00:00:00")]
168                 public TimeSpan TimeToLive {
169                         get { return (TimeSpan) base ["timeToLive"]; }
170                         set { base ["timeToLive"] = value; }
171                 }
172
173                 [ConfigurationProperty ("useMsmqTracing",
174                          Options = ConfigurationPropertyOptions.None,
175                         DefaultValue = false)]
176                 public bool UseMsmqTracing {
177                         get { return (bool) base ["useMsmqTracing"]; }
178                         set { base ["useMsmqTracing"] = value; }
179                 }
180
181                 [ConfigurationProperty ("useSourceJournal",
182                          Options = ConfigurationPropertyOptions.None,
183                         DefaultValue = false)]
184                 public bool UseSourceJournal {
185                         get { return (bool) base ["useSourceJournal"]; }
186                         set { base ["useSourceJournal"] = value; }
187                 }
188
189                 public override void ApplyConfiguration (BindingElement bindingElement)
190                 {
191                         var b = (System.ServiceModel.Channels.MsmqBindingElementBase) bindingElement;
192                         base.ApplyConfiguration (b);
193                         b.CustomDeadLetterQueue = CustomDeadLetterQueue;
194                         b.DeadLetterQueue = DeadLetterQueue;
195                         b.Durable = Durable;
196                         b.ExactlyOnce = ExactlyOnce;
197                         b.MaxRetryCycles = MaxRetryCycles;
198                         b.ReceiveErrorHandling = ReceiveErrorHandling;
199                         b.ReceiveRetryCount = ReceiveRetryCount;
200                         b.RetryCycleDelay = RetryCycleDelay;
201                         b.TimeToLive = TimeToLive;
202                         b.UseMsmqTracing = UseMsmqTracing;
203                         b.UseSourceJournal = UseSourceJournal;
204
205                         var bs = b.MsmqTransportSecurity;
206                         var cs = MsmqTransportSecurity;
207                         bs.MsmqAuthenticationMode = cs.MsmqAuthenticationMode;
208                         bs.MsmqEncryptionAlgorithm = cs.MsmqEncryptionAlgorithm;
209                         bs.MsmqProtectionLevel = cs.MsmqProtectionLevel;
210                         bs.MsmqSecureHashAlgorithm = cs.MsmqSecureHashAlgorithm;
211                 }
212
213                 public override void CopyFrom (ServiceModelExtensionElement from)
214                 {
215                         var e = (MsmqElementBase) from;
216                         base.CopyFrom (from);
217                         CustomDeadLetterQueue = e.CustomDeadLetterQueue;
218                         DeadLetterQueue = e.DeadLetterQueue;
219                         Durable = e.Durable;
220                         ExactlyOnce = e.ExactlyOnce;
221                         MaxRetryCycles = e.MaxRetryCycles;
222                         ReceiveErrorHandling = e.ReceiveErrorHandling;
223                         ReceiveRetryCount = e.ReceiveRetryCount;
224                         RetryCycleDelay = e.RetryCycleDelay;
225                         TimeToLive = e.TimeToLive;
226                         UseMsmqTracing = e.UseMsmqTracing;
227                         UseSourceJournal = e.UseSourceJournal;
228
229                         var es = e.MsmqTransportSecurity;
230                         var cs = MsmqTransportSecurity;
231                         cs.MsmqAuthenticationMode = es.MsmqAuthenticationMode;
232                         cs.MsmqEncryptionAlgorithm = es.MsmqEncryptionAlgorithm;
233                         cs.MsmqProtectionLevel = es.MsmqProtectionLevel;
234                         cs.MsmqSecureHashAlgorithm = es.MsmqSecureHashAlgorithm;
235                 }
236
237                 protected internal override void InitializeFrom (BindingElement bindingElement)
238                 {
239                         var b = (System.ServiceModel.Channels.MsmqBindingElementBase) bindingElement;
240                         base.InitializeFrom (b);
241                         CustomDeadLetterQueue = b.CustomDeadLetterQueue;
242                         DeadLetterQueue = b.DeadLetterQueue;
243                         Durable = b.Durable;
244                         ExactlyOnce = b.ExactlyOnce;
245                         MaxRetryCycles = b.MaxRetryCycles;
246                         ReceiveErrorHandling = b.ReceiveErrorHandling;
247                         ReceiveRetryCount = b.ReceiveRetryCount;
248                         RetryCycleDelay = b.RetryCycleDelay;
249                         TimeToLive = b.TimeToLive;
250                         UseMsmqTracing = b.UseMsmqTracing;
251                         UseSourceJournal = b.UseSourceJournal;
252
253                         var bs = b.MsmqTransportSecurity;
254                         var cs = MsmqTransportSecurity;
255                         cs.MsmqAuthenticationMode = bs.MsmqAuthenticationMode;
256                         cs.MsmqEncryptionAlgorithm = bs.MsmqEncryptionAlgorithm;
257                         cs.MsmqProtectionLevel = bs.MsmqProtectionLevel;
258                         cs.MsmqSecureHashAlgorithm = bs.MsmqSecureHashAlgorithm;
259                 }
260         }
261
262 }