Merge pull request #1870 from saper/langinfo_h
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / DispatchOperation.cs
1 //
2 // DispatchOperation.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005-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 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
34 using System.Text;
35
36 namespace System.ServiceModel.Dispatcher
37 {
38         public sealed class DispatchOperation
39         {
40                 internal class DispatchOperationCollection :
41                         SynchronizedKeyedCollection<string, DispatchOperation>
42                 {
43                         protected override string GetKeyForItem (DispatchOperation o)
44                         {
45                                 return o.Name;
46                         }
47                 }
48
49                 DispatchRuntime parent;
50                 string name, action, reply_action;
51                 bool serialize_reply = true, deserialize_request = true,
52                         is_oneway, is_terminating,
53                         release_after_call, release_before_call,
54                         tx_auto_complete, tx_required,
55                         auto_dispose_params = true;
56                 IDispatchMessageFormatter formatter;
57 #if !NET_2_1
58                 ImpersonationOption impersonation;
59                 IOperationInvoker invoker;
60                 SynchronizedCollection<IParameterInspector> inspectors
61                         = new SynchronizedCollection<IParameterInspector> ();
62                 SynchronizedCollection<FaultContractInfo> fault_contract_infos
63                         = new SynchronizedCollection<FaultContractInfo> ();
64                 SynchronizedCollection<ICallContextInitializer> ctx_initializers
65                         = new SynchronizedCollection<ICallContextInitializer> ();
66 #endif
67
68                 public DispatchOperation (DispatchRuntime parent,
69                         string name, string action)
70                 {
71                         if (parent == null)
72                                 throw new ArgumentNullException ("parent");
73                         if (name == null)
74                                 throw new ArgumentNullException ("name");
75                         // action could be null
76
77                         is_oneway = true;
78                         this.parent = parent;
79                         this.name = name;
80                         this.action = action;
81                 }
82
83                 public DispatchOperation (DispatchRuntime parent,
84                         string name, string action, string replyAction)
85                         : this (parent, name, action)
86                 {
87                         // replyAction could be null
88                         is_oneway = false;
89                         reply_action = replyAction;
90                 }
91
92                 public string Action {
93                         get { return action; }
94                 }
95
96 #if !NET_2_1
97                 public SynchronizedCollection<ICallContextInitializer> CallContextInitializers {
98                         get { return ctx_initializers; }
99                 }
100
101                 public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
102                         get { return fault_contract_infos; }
103                 }
104
105                 [MonoTODO ("not considered")]
106                 public ImpersonationOption Impersonation {
107                         get { return impersonation; }
108                         set {
109                                 ThrowIfOpened ();
110                                 impersonation = value;
111                         }
112                 }
113
114                 public IOperationInvoker Invoker {
115                         get { return invoker; }
116                         set {
117                                 ThrowIfOpened ();
118                                 invoker = value;
119                         }
120                 }
121
122                 public bool IsTerminating {
123                         get { return is_terminating; }
124                         set {
125                                 ThrowIfOpened ();
126                                 is_terminating = value;
127                         }
128                 }
129
130                 public SynchronizedCollection<IParameterInspector> ParameterInspectors {
131                         get { return inspectors; }
132                 }
133
134                 public bool ReleaseInstanceAfterCall {
135                         get { return release_after_call; }
136                         set {
137                                 ThrowIfOpened ();
138                                 release_after_call = value;
139                         }
140                 }
141
142                 public bool ReleaseInstanceBeforeCall {
143                         get { return release_before_call; }
144                         set {
145                                 ThrowIfOpened ();
146                                 release_before_call = value;
147                         }
148                 }
149
150                 public string ReplyAction {
151                         get { return reply_action; }
152                 }
153
154                 public bool TransactionAutoComplete {
155                         get { return tx_auto_complete; }
156                         set {
157                                 ThrowIfOpened ();
158                                 tx_auto_complete = value;
159                         }
160                 }
161
162                 public bool TransactionRequired {
163                         get { return tx_required; }
164                         set {
165                                 ThrowIfOpened ();
166                                 tx_required = value;
167                         }
168                 }
169 #endif
170
171                 public bool AutoDisposeParameters {
172                         get { return auto_dispose_params; }
173                         set {
174                                 ThrowIfOpened ();
175                                 auto_dispose_params = value;
176                         }
177                 }
178
179                 public bool DeserializeRequest {
180                         get { return deserialize_request; }
181                         set {
182                                 ThrowIfOpened ();
183                                 deserialize_request = value;
184                         }
185                 }
186
187                 public IDispatchMessageFormatter Formatter {
188                         get { return formatter; }
189                         set {
190                                 ThrowIfOpened ();
191                                 formatter = value;
192                         }
193                 }
194
195                 public bool IsOneWay {
196                         get { return is_oneway; }
197                 }
198
199                 public string Name {
200                         get { return name; }
201                 }
202
203                 public DispatchRuntime Parent {
204                         get { return parent; }
205                 }
206
207                 public bool SerializeReply {
208                         get { return serialize_reply; }
209                         set {
210                                 ThrowIfOpened ();
211                                 serialize_reply = value;
212                         }
213                 }
214
215                 void ThrowIfOpened ()
216                 {
217 #if !NET_2_1 && !XAMMAC_4_5
218                         // FIXME: get callback client runtime status when ChannelDispatcher is not available.
219                         var state = Parent.ChannelDispatcher != null ? Parent.ChannelDispatcher.State : CommunicationState.Created; // Parent.CallbackClientRuntime.ChannelFactory.State;
220                         switch (state) {
221                         case CommunicationState.Created:
222                         case CommunicationState.Opening:
223                                 return;
224                         }
225                         throw new InvalidOperationException ("Cannot change this property after the service host is opened");
226 #endif
227                 }
228
229         }
230 }