Merge pull request #799 from kebby/master
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / ClientOperation.cs
1 //
2 // ClientOperation.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 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.Collections.ObjectModel;
31 using System.Reflection;
32 using System.ServiceModel;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35 using System.Text;
36
37 namespace System.ServiceModel.Dispatcher
38 {
39         public sealed class ClientOperation
40         {
41                 internal class ClientOperationCollection :
42 #if NET_2_1
43                         KeyedCollection<string, ClientOperation>
44 #else
45                         SynchronizedKeyedCollection<string, ClientOperation>
46 #endif
47                 {
48                         protected override string GetKeyForItem (ClientOperation o)
49                         {
50                                 return o.Name;
51                         }
52                 }
53
54                 ClientRuntime parent;
55                 string name, action, reply_action;
56                 MethodInfo sync_method, begin_method, end_method;
57                 bool deserialize_reply = true, serialize_request = true;
58                 bool is_initiating, is_terminating, is_oneway;
59                 IClientMessageFormatter formatter;
60                 SynchronizedCollection<IParameterInspector> inspectors
61                         = new SynchronizedCollection<IParameterInspector> ();
62                 SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
63
64                 public ClientOperation (ClientRuntime parent,
65                         string name, string action)
66                 {
67                         this.parent = parent;
68                         this.name = name;
69                         this.action = action;
70                 }
71
72                 public ClientOperation (ClientRuntime parent,
73                         string name, string action, string replyAction)
74                 {
75                         this.parent = parent;
76                         this.name = name;
77                         this.action = action;
78                         this.reply_action = replyAction;
79                 }
80
81                 public string Action {
82                         get { return action; }
83                 }
84
85                 public string ReplyAction {
86                         get { return reply_action; }
87                 }
88
89                 public MethodInfo BeginMethod {
90                         get { return begin_method; }
91                         set {
92                                 ThrowIfOpened ();
93                                 begin_method = value;
94                         }
95                 }
96
97                 public bool DeserializeReply {
98                         get { return deserialize_reply; }
99                         set {
100                                 ThrowIfOpened ();
101                                 deserialize_reply = value;
102                         }
103                 }
104
105                 public MethodInfo EndMethod {
106                         get { return end_method; }
107                         set {
108                                 ThrowIfOpened ();
109                                 end_method = value;
110                         }
111                 }
112
113                 public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
114                         get { return fault_contract_infos; }
115                 }
116
117                 public IClientMessageFormatter Formatter {
118                         get { return formatter; }
119                         set {
120                                 ThrowIfOpened ();
121                                 formatter = value;
122                         }
123                 }
124
125                 public bool IsInitiating {
126                         get { return is_initiating; }
127                         set {
128                                 ThrowIfOpened ();
129                                 is_initiating = value;
130                         }
131                 }
132
133                 public bool IsOneWay {
134                         get { return is_oneway; }
135                         set {
136                                 ThrowIfOpened ();
137                                 is_oneway = value;
138                         }
139                 }
140
141                 public bool IsTerminating {
142                         get { return is_terminating; }
143                         set {
144                                 ThrowIfOpened ();
145                                 is_terminating = value;
146                         }
147                 }
148
149                 public string Name {
150                         get { return name; }
151                 }
152
153                 public SynchronizedCollection<IParameterInspector> ParameterInspectors {
154                         get { return inspectors; }
155                 }
156
157                 public ClientRuntime Parent {
158                         get { return parent; }
159                 }
160
161                 public bool SerializeRequest {
162                         get { return serialize_request; }
163                         set {
164                                 ThrowIfOpened ();
165                                 serialize_request = value;
166                         }
167                 }
168
169                 public MethodInfo SyncMethod {
170                         get { return sync_method; }
171                         set {
172                                 ThrowIfOpened ();
173                                 sync_method = value;
174                         }
175                 }
176
177                 void ThrowIfOpened ()
178                 {
179                         // FIXME: get correct state
180                         var state = CommunicationState.Created;
181                         switch (state) {
182                         case CommunicationState.Created:
183                         case CommunicationState.Opening:
184                                 return;
185                         }
186                         throw new InvalidOperationException ("Cannot change this property after the service host is opened");
187                 }
188
189 #if NET_4_5
190                 [MonoTODO]
191                 public ICollection<IParameterInspector> ClientParameterInspectors {
192                         get { throw new NotImplementedException (); }
193                 }
194
195                 [MonoTODO]
196                 public MethodInfo TaskMethod {
197                         get { throw new NotImplementedException (); }
198                         set { throw new NotImplementedException (); }
199                 }
200
201                 [MonoTODO]
202                 public Type TaskTResult {
203                         get { throw new NotImplementedException (); }
204                         set { throw new NotImplementedException (); }
205                 }
206 #endif
207                 
208         }
209 }