Merge pull request #138 from eisnerd/bug-winforms-datagridview-resize-490247
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / LayeredCommunicationObject.cs
1 //
2 // SecurityReplyChannel.cs
3 //
4 // Author: Atsushi Enomoto (atsushi@ximian.com)
5 //
6 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
7 //
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:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
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.
26 //
27 using System;
28 using System.ServiceModel;
29
30 namespace System.ServiceModel.Channels
31 {
32         internal abstract class LayeredCommunicationObject : ICommunicationObject, IDisposable
33         {
34                 ICommunicationObject inner;
35
36                 protected LayeredCommunicationObject (ICommunicationObject source)
37                 {
38                         inner = source;
39                 }
40
41                 public abstract ChannelManagerBase ChannelManager { get; }
42
43                 IDefaultCommunicationTimeouts Timeouts {
44                         get { return (IDefaultCommunicationTimeouts) ChannelManager; }
45                 }
46
47                 // ICommunicationObject
48
49                 public virtual CommunicationState State {
50                         get { return inner.State; }
51                 }
52
53                 public virtual void Abort ()
54                 {
55                         inner.Abort ();
56                 }
57
58                 public IAsyncResult BeginClose (AsyncCallback callback, object state)
59                 {
60                         return BeginClose (Timeouts.CloseTimeout, callback, state);
61                 }
62
63                 public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
64                 {
65                         return OnBeginClose (timeout, callback, state);
66                 }
67
68                 protected virtual IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
69                 {
70                         return inner.BeginClose (timeout, callback, state);
71                 }
72
73                 public virtual void EndClose (IAsyncResult result)
74                 {
75                         OnEndClose (result);
76                 }
77
78                 protected void OnEndClose (IAsyncResult result)
79                 {
80                         inner.EndClose (result);
81                 }
82
83                 public void Close ()
84                 {
85                         Close (Timeouts.CloseTimeout);
86                 }
87
88                 public void Close (TimeSpan timeout)
89                 {
90                         OnClose (timeout);
91                 }
92
93                 protected virtual void OnClose (TimeSpan timeout)
94                 {
95                         inner.Close (timeout);
96                 }
97
98                 public void Dispose ()
99                 {
100                         Close ();
101                 }
102
103                 public IAsyncResult BeginOpen (AsyncCallback callback, object state)
104                 {
105                         return BeginOpen (Timeouts.OpenTimeout, callback, state);
106                 }
107
108                 public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
109                 {
110                         return OnBeginOpen (timeout, callback, state);
111                 }
112
113                 protected virtual IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
114                 {
115                         return inner.BeginOpen (timeout, callback, state);
116                 }
117
118                 public virtual void EndOpen (IAsyncResult result)
119                 {
120                         OnEndOpen (result);
121                 }
122
123                 protected virtual void OnEndOpen (IAsyncResult result)
124                 {
125                         inner.EndOpen (result);
126                 }
127
128                 public void Open ()
129                 {
130                         Open (Timeouts.OpenTimeout);
131                 }
132
133                 public void Open (TimeSpan timeout)
134                 {
135                         inner.Open (timeout);
136                 }
137
138                 protected virtual Type GetCommunicationObjectType ()
139                 {
140                         return GetType ();
141                 }
142
143                 protected void ThrowIfNotOpen ()
144                 {
145                         if (State != CommunicationState.Opened)
146                                 throw new InvalidOperationException (String.Format ("The communication object {0} must be at opened state.", GetCommunicationObjectType ()));
147                 }
148
149                 protected void ThrowIfImmutable ()
150                 {
151                         if (State != CommunicationState.Created)
152                                 throw new InvalidOperationException (String.Format ("The communication object {0} is being closed while it is not opened.", GetType ()));
153                 }
154
155                 public event EventHandler Closing {
156                         add { inner.Closing += value; }
157                         remove { inner.Closing -= value; }
158                 }
159
160                 public event EventHandler Closed {
161                         add { inner.Closed += value; }
162                         remove { inner.Closed -= value; }
163                 }
164
165                 public event EventHandler Opening {
166                         add { inner.Opening += value; }
167                         remove { inner.Opening -= value; }
168                 }
169
170                 public event EventHandler Opened {
171                         add { inner.Opened += value; }
172                         remove { inner.Opened -= value; }
173                 }
174
175                 public event EventHandler Faulted {
176                         add { inner.Faulted += value; }
177                         remove { inner.Faulted -= value; }
178                 }
179         }
180 }