2008-11-01 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / ServiceRuntimeChannel.cs
1 //
2 // ServiceRuntimeChannel.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 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.Channels;
32 using System.ServiceModel.Description;
33 using System.ServiceModel.Dispatcher;
34
35 namespace System.ServiceModel
36 {
37         internal class ServiceRuntimeChannel : CommunicationObject, IContextChannel, IClientChannel
38         {
39                 IExtensionCollection<IContextChannel> extensions;
40                 readonly IChannel channel;              
41                 bool _allowInitializationUI;
42                 Uri _via;
43                 readonly TimeSpan _openTimeout;
44                 readonly TimeSpan _closeTimeout;
45
46                 public ServiceRuntimeChannel (IChannel channel, TimeSpan openTimeout, TimeSpan closeTimeout)
47                 {
48                         this.channel = channel;
49                         this._openTimeout = openTimeout;
50                         this._closeTimeout = closeTimeout;
51                 }
52
53                 #region IContextChannel
54
55                 [MonoTODO]
56                 public bool AllowOutputBatching {
57                         get { throw new NotImplementedException (); }
58                         set { throw new NotImplementedException (); }
59                 }
60
61                 public IInputSession InputSession {
62                         get {
63                                 if (channel is IInputSessionChannel)
64                                         return ((IInputSessionChannel) channel).Session;
65                                 return null;
66                         }
67                 }
68
69                 public EndpointAddress LocalAddress {
70                         get {
71                                 if (channel is IReplyChannel)
72                                         return ((IReplyChannel) channel).LocalAddress;
73                                 if (channel is IInputChannel)
74                                         return ((IInputChannel) channel).LocalAddress;
75                                 return null;
76                         }
77                 }
78
79                 [MonoTODO]
80                 public TimeSpan OperationTimeout {
81                         get { throw new NotImplementedException (); }
82                         set { throw new NotImplementedException (); }
83                 }
84
85                 public IOutputSession OutputSession {
86                         get {
87                                 if (channel is IOutputSessionChannel)
88                                         return ((IOutputSessionChannel) channel).Session;
89                                 return null;
90                         }
91                 }
92
93                 public EndpointAddress RemoteAddress {
94                         get {
95                                 if (channel is IRequestChannel)
96                                         return ((IRequestChannel) channel).RemoteAddress;
97                                 if (channel is IOutputChannel)
98                                         return ((IOutputChannel) channel).RemoteAddress;
99                                 return null;
100                         }
101                 }
102
103                 public string SessionId {
104                         get { return InputSession != null ? InputSession.Id : null; }
105                 }
106
107                 #endregion
108
109                 // CommunicationObject
110                 protected internal override TimeSpan DefaultOpenTimeout {
111                         get { return _openTimeout; }
112                 }
113
114                 protected internal override TimeSpan DefaultCloseTimeout {
115                         get { return _closeTimeout; }
116                 }
117
118                 protected override void OnAbort ()
119                 {
120                         channel.Abort ();
121                 }
122
123                 protected override IAsyncResult OnBeginClose (
124                         TimeSpan timeout, AsyncCallback callback, object state)
125                 {
126                         return channel.BeginClose (timeout, callback, state);
127                 }
128
129                 protected override void OnEndClose (IAsyncResult result)
130                 {
131                         channel.EndClose (result);
132                 }
133
134                 protected override void OnClose (TimeSpan timeout)
135                 {
136                         channel.Close (timeout);
137                 }
138
139                 protected override IAsyncResult OnBeginOpen (
140                         TimeSpan timeout, AsyncCallback callback, object state)
141                 {
142                         return channel.BeginOpen (timeout, callback, state);
143                 }
144
145                 protected override void OnEndOpen (IAsyncResult result)
146                 {
147                         channel.EndOpen (result);
148                 }
149
150                 protected override void OnOpen (TimeSpan timeout)
151                 {
152                         channel.Open (timeout);
153                 }
154
155                 // IChannel
156                 public T GetProperty<T> () where T : class
157                 {
158                         return channel.GetProperty<T> ();
159                 }
160
161                 // IExtensibleObject<IContextChannel>
162                 public IExtensionCollection<IContextChannel> Extensions {
163                         get {
164                                 if (extensions == null)
165                                         extensions = new ExtensionCollection<IContextChannel> (this);
166                                 return extensions;
167                         }
168                 }
169
170
171                 #region IClientChannel Members
172
173                 public bool AllowInitializationUI {
174                         get {
175                                 return _allowInitializationUI;
176                         }
177                         set {
178                                 _allowInitializationUI = value;
179                         }
180                 }
181
182                 public bool DidInteractiveInitialization {
183                         get { throw new NotImplementedException (); }
184                 }
185
186                 public Uri Via {
187                         get { return _via; }
188                 }
189
190                 public IAsyncResult BeginDisplayInitializationUI (AsyncCallback callback, object state) {
191                         throw new NotImplementedException ();
192                 }
193
194                 public void EndDisplayInitializationUI (IAsyncResult result) {
195                         throw new NotImplementedException ();
196                 }
197
198                 public void DisplayInitializationUI () {
199                         throw new NotImplementedException ();
200                 }
201
202                 public event EventHandler<UnknownMessageReceivedEventArgs> UnknownMessageReceived;
203
204                 #endregion
205
206                 #region IDisposable Members
207
208                 public void Dispose () {
209                         throw new NotImplementedException ();
210                 }
211
212                 #endregion
213         }
214 }