ChannelStub.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 ChannelStub : Channel
  8. {
  9. /// <summary>
  10. /// Initializes a new <see cref="ChannelStub"/> 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 ChannelStub(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 void SetIsOpen(bool value)
  37. {
  38. IsOpen = value;
  39. }
  40. public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize)
  41. {
  42. InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
  43. }
  44. protected override void OnClose()
  45. {
  46. base.OnClose();
  47. if (OnCloseException != null)
  48. {
  49. throw OnCloseException;
  50. }
  51. }
  52. protected override void OnData(ArraySegment<byte> data)
  53. {
  54. base.OnData(data);
  55. if (OnDataException != null)
  56. {
  57. throw OnDataException;
  58. }
  59. }
  60. protected override void OnDisconnected()
  61. {
  62. base.OnDisconnected();
  63. if (OnDisconnectedException != null)
  64. {
  65. throw OnDisconnectedException;
  66. }
  67. }
  68. protected override void OnEof()
  69. {
  70. base.OnEof();
  71. if (OnEofException != null)
  72. {
  73. throw OnEofException;
  74. }
  75. }
  76. protected override void OnExtendedData(byte[] data, uint dataTypeCode)
  77. {
  78. base.OnExtendedData(data, dataTypeCode);
  79. if (OnExtendedDataException != null)
  80. {
  81. throw OnExtendedDataException;
  82. }
  83. }
  84. protected override void OnErrorOccured(Exception exp)
  85. {
  86. OnErrorOccurredInvocations.Add(exp);
  87. if (OnErrorOccurredException != null)
  88. {
  89. throw OnErrorOccurredException;
  90. }
  91. }
  92. protected override void OnFailure()
  93. {
  94. base.OnFailure();
  95. if (OnFailureException != null)
  96. {
  97. throw OnFailureException;
  98. }
  99. }
  100. protected override void OnRequest(RequestInfo info)
  101. {
  102. base.OnRequest(info);
  103. if (OnRequestException != null)
  104. {
  105. throw OnRequestException;
  106. }
  107. }
  108. protected override void OnSuccess()
  109. {
  110. base.OnSuccess();
  111. if (OnSuccessException != null)
  112. {
  113. throw OnSuccessException;
  114. }
  115. }
  116. protected override void OnWindowAdjust(uint bytesToAdd)
  117. {
  118. base.OnWindowAdjust(bytesToAdd);
  119. if (OnWindowAdjustException != null)
  120. {
  121. throw OnWindowAdjustException;
  122. }
  123. }
  124. }
  125. }