LayeredCommunicationObject.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // SecurityReplyChannel.cs
  3. //
  4. // Author: Atsushi Enomoto ([email protected])
  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. namespace System.ServiceModel.Channels
  30. {
  31. internal abstract class LayeredCommunicationObject : ICommunicationObject, IDisposable
  32. {
  33. ICommunicationObject inner;
  34. protected LayeredCommunicationObject (ICommunicationObject source)
  35. {
  36. inner = source;
  37. }
  38. public abstract ChannelManagerBase ChannelManager { get; }
  39. IDefaultCommunicationTimeouts Timeouts {
  40. get { return (IDefaultCommunicationTimeouts) ChannelManager; }
  41. }
  42. // ICommunicationObject
  43. public virtual CommunicationState State {
  44. get { return inner.State; }
  45. }
  46. public virtual void Abort ()
  47. {
  48. inner.Abort ();
  49. }
  50. public IAsyncResult BeginClose (AsyncCallback callback, object state)
  51. {
  52. return BeginClose (Timeouts.CloseTimeout, callback, state);
  53. }
  54. public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  55. {
  56. return OnBeginClose (timeout, callback, state);
  57. }
  58. protected virtual IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  59. {
  60. return inner.BeginClose (timeout, callback, state);
  61. }
  62. public virtual void EndClose (IAsyncResult result)
  63. {
  64. OnEndClose (result);
  65. }
  66. protected void OnEndClose (IAsyncResult result)
  67. {
  68. inner.EndClose (result);
  69. }
  70. public void Close ()
  71. {
  72. Close (Timeouts.CloseTimeout);
  73. }
  74. public void Close (TimeSpan timeout)
  75. {
  76. OnClose (timeout);
  77. }
  78. protected virtual void OnClose (TimeSpan timeout)
  79. {
  80. inner.Close (timeout);
  81. }
  82. public void Dispose ()
  83. {
  84. Close ();
  85. }
  86. public IAsyncResult BeginOpen (AsyncCallback callback, object state)
  87. {
  88. return BeginOpen (Timeouts.OpenTimeout, callback, state);
  89. }
  90. public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
  91. {
  92. return OnBeginOpen (timeout, callback, state);
  93. }
  94. protected virtual IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
  95. {
  96. return inner.BeginOpen (timeout, callback, state);
  97. }
  98. public virtual void EndOpen (IAsyncResult result)
  99. {
  100. OnEndOpen (result);
  101. }
  102. protected virtual void OnEndOpen (IAsyncResult result)
  103. {
  104. inner.EndOpen (result);
  105. }
  106. public void Open ()
  107. {
  108. Open (Timeouts.OpenTimeout);
  109. }
  110. public void Open (TimeSpan timeout)
  111. {
  112. inner.Open (timeout);
  113. }
  114. protected virtual Type GetCommunicationObjectType ()
  115. {
  116. return GetType ();
  117. }
  118. protected void ThrowIfNotOpen ()
  119. {
  120. if (State != CommunicationState.Opened)
  121. throw new InvalidOperationException (String.Format ("The communication object {0} must be at opened state.", GetCommunicationObjectType ()));
  122. }
  123. protected void ThrowIfImmutable ()
  124. {
  125. if (State != CommunicationState.Created)
  126. throw new InvalidOperationException (String.Format ("The communication object {0} is being closed while it is not opened.", GetType ()));
  127. }
  128. public event EventHandler Closing {
  129. add { inner.Closing += value; }
  130. remove { inner.Closing -= value; }
  131. }
  132. public event EventHandler Closed {
  133. add { inner.Closed += value; }
  134. remove { inner.Closed -= value; }
  135. }
  136. public event EventHandler Opening {
  137. add { inner.Opening += value; }
  138. remove { inner.Opening -= value; }
  139. }
  140. public event EventHandler Opened {
  141. add { inner.Opened += value; }
  142. remove { inner.Opened -= value; }
  143. }
  144. public event EventHandler Faulted {
  145. add { inner.Faulted += value; }
  146. remove { inner.Faulted -= value; }
  147. }
  148. }
  149. }