2 // SecurityReplyChannel.cs
4 // Author: Atsushi Enomoto (atsushi@ximian.com)
6 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System
.ServiceModel
;
30 namespace System
.ServiceModel
.Channels
32 internal abstract class LayeredCommunicationObject
: ICommunicationObject
, IDisposable
34 ICommunicationObject inner
;
36 protected LayeredCommunicationObject (ICommunicationObject source
)
41 public abstract ChannelManagerBase ChannelManager { get; }
43 IDefaultCommunicationTimeouts Timeouts
{
44 get { return (IDefaultCommunicationTimeouts) ChannelManager; }
47 // ICommunicationObject
49 public virtual CommunicationState State
{
50 get { return inner.State; }
53 public virtual void Abort ()
58 public IAsyncResult
BeginClose (AsyncCallback callback
, object state
)
60 return BeginClose (Timeouts
.CloseTimeout
, callback
, state
);
63 public IAsyncResult
BeginClose (TimeSpan timeout
, AsyncCallback callback
, object state
)
65 return OnBeginClose (timeout
, callback
, state
);
68 protected virtual IAsyncResult
OnBeginClose (TimeSpan timeout
, AsyncCallback callback
, object state
)
70 return inner
.BeginClose (timeout
, callback
, state
);
73 public virtual void EndClose (IAsyncResult result
)
78 protected void OnEndClose (IAsyncResult result
)
80 inner
.EndClose (result
);
85 Close (Timeouts
.CloseTimeout
);
88 public void Close (TimeSpan timeout
)
93 protected virtual void OnClose (TimeSpan timeout
)
95 inner
.Close (timeout
);
98 public void Dispose ()
103 public IAsyncResult
BeginOpen (AsyncCallback callback
, object state
)
105 return BeginOpen (Timeouts
.OpenTimeout
, callback
, state
);
108 public IAsyncResult
BeginOpen (TimeSpan timeout
, AsyncCallback callback
, object state
)
110 return OnBeginOpen (timeout
, callback
, state
);
113 protected virtual IAsyncResult
OnBeginOpen (TimeSpan timeout
, AsyncCallback callback
, object state
)
115 return inner
.BeginOpen (timeout
, callback
, state
);
118 public virtual void EndOpen (IAsyncResult result
)
123 protected virtual void OnEndOpen (IAsyncResult result
)
125 inner
.EndOpen (result
);
130 Open (Timeouts
.OpenTimeout
);
133 public void Open (TimeSpan timeout
)
135 inner
.Open (timeout
);
138 protected virtual Type
GetCommunicationObjectType ()
143 protected void ThrowIfNotOpen ()
145 if (State
!= CommunicationState
.Opened
)
146 throw new InvalidOperationException (String
.Format ("The communication object {0} must be at opened state.", GetCommunicationObjectType ()));
149 protected void ThrowIfImmutable ()
151 if (State
!= CommunicationState
.Created
)
152 throw new InvalidOperationException (String
.Format ("The communication object {0} is being closed while it is not opened.", GetType ()));
155 public event EventHandler Closing
{
156 add { inner.Closing += value; }
157 remove { inner.Closing -= value; }
160 public event EventHandler Closed
{
161 add { inner.Closed += value; }
162 remove { inner.Closed -= value; }
165 public event EventHandler Opening
{
166 add { inner.Opening += value; }
167 remove { inner.Opening -= value; }
170 public event EventHandler Opened
{
171 add { inner.Opened += value; }
172 remove { inner.Opened -= value; }
175 public event EventHandler Faulted
{
176 add { inner.Faulted += value; }
177 remove { inner.Faulted -= value; }