ClientChannelStub.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using Renci.SshNet.Channels;
  4. using Renci.SshNet.Messages.Connection;
  5. namespace Renci.SshNet.Tests.Classes.Channels
  6. {
  7. internal class ClientChannelStub : ClientChannel
  8. {
  9. /// <summary>
  10. /// Initializes a new <see cref="ClientChannelStub"/> instance.
  11. /// </summary>
  12. /// <param name="session">The session.</param>
  13. /// <param name="localChannelNumber">The local channel number.</param>
  14. /// <param name="localWindowSize">Size of the window.</param>
  15. /// <param name="localPacketSize">Size of the packet.</param>
  16. public ClientChannelStub(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize)
  17. : base(session, localChannelNumber, localWindowSize, localPacketSize)
  18. {
  19. OnErrorOccurredInvocations = new List<Exception>();
  20. }
  21. public override ChannelTypes ChannelType
  22. {
  23. get { return ChannelTypes.X11; }
  24. }
  25. public IList<Exception> OnErrorOccurredInvocations { get; private set; }
  26. public Exception OnCloseException { get; set; }
  27. public Exception OnDataException { get; set; }
  28. public Exception OnDisconnectedException { get; set; }
  29. public Exception OnEofException { get; set; }
  30. public Exception OnErrorOccurredException { get; set; }
  31. public Exception OnExtendedDataException { get; set; }
  32. public Exception OnFailureException { get; set; }
  33. public Exception OnRequestException { get; set; }
  34. public Exception OnSuccessException { get; set; }
  35. public Exception OnWindowAdjustException { get; set; }
  36. public Exception OnOpenConfirmationException { get; set; }
  37. public Exception OnOpenFailureException { get; set; }
  38. public void SetIsOpen(bool value)
  39. {
  40. IsOpen = value;
  41. }
  42. public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize)
  43. {
  44. InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
  45. }
  46. protected override void OnClose()
  47. {
  48. base.OnClose();
  49. if (OnCloseException != null)
  50. {
  51. throw OnCloseException;
  52. }
  53. }
  54. protected override void OnData(ArraySegment<byte> data)
  55. {
  56. base.OnData(data);
  57. if (OnDataException != null)
  58. {
  59. throw OnDataException;
  60. }
  61. }
  62. protected override void OnDisconnected()
  63. {
  64. base.OnDisconnected();
  65. if (OnDisconnectedException != null)
  66. {
  67. throw OnDisconnectedException;
  68. }
  69. }
  70. protected override void OnEof()
  71. {
  72. base.OnEof();
  73. if (OnEofException != null)
  74. {
  75. throw OnEofException;
  76. }
  77. }
  78. protected override void OnExtendedData(byte[] data, uint dataTypeCode)
  79. {
  80. base.OnExtendedData(data, dataTypeCode);
  81. if (OnExtendedDataException != null)
  82. {
  83. throw OnExtendedDataException;
  84. }
  85. }
  86. protected override void OnErrorOccurred(Exception exp)
  87. {
  88. OnErrorOccurredInvocations.Add(exp);
  89. if (OnErrorOccurredException != null)
  90. {
  91. throw OnErrorOccurredException;
  92. }
  93. }
  94. protected override void OnFailure()
  95. {
  96. base.OnFailure();
  97. if (OnFailureException != null)
  98. {
  99. throw OnFailureException;
  100. }
  101. }
  102. protected override void OnRequest(RequestInfo info)
  103. {
  104. base.OnRequest(info);
  105. if (OnRequestException != null)
  106. {
  107. throw OnRequestException;
  108. }
  109. }
  110. protected override void OnSuccess()
  111. {
  112. base.OnSuccess();
  113. if (OnSuccessException != null)
  114. {
  115. throw OnSuccessException;
  116. }
  117. }
  118. protected override void OnWindowAdjust(uint bytesToAdd)
  119. {
  120. base.OnWindowAdjust(bytesToAdd);
  121. if (OnWindowAdjustException != null)
  122. {
  123. throw OnWindowAdjustException;
  124. }
  125. }
  126. protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize)
  127. {
  128. base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize);
  129. if (OnOpenConfirmationException != null)
  130. {
  131. throw OnOpenConfirmationException;
  132. }
  133. }
  134. protected override void OnOpenFailure(uint reasonCode, string description, string language)
  135. {
  136. base.OnOpenFailure(reasonCode, description, language);
  137. if (OnOpenFailureException != null)
  138. {
  139. throw OnOpenFailureException;
  140. }
  141. }
  142. }
  143. }