ClientChannelStub.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
  45. }
  46. protected override void OnClose()
  47. {
  48. base.OnClose();
  49. if (OnCloseException != null)
  50. throw OnCloseException;
  51. }
  52. protected override void OnData(byte[] data)
  53. {
  54. base.OnData(data);
  55. if (OnDataException != null)
  56. throw OnDataException;
  57. }
  58. protected override void OnDisconnected()
  59. {
  60. base.OnDisconnected();
  61. if (OnDisconnectedException != null)
  62. throw OnDisconnectedException;
  63. }
  64. protected override void OnEof()
  65. {
  66. base.OnEof();
  67. if (OnEofException != null)
  68. throw OnEofException;
  69. }
  70. protected override void OnExtendedData(byte[] data, uint dataTypeCode)
  71. {
  72. base.OnExtendedData(data, dataTypeCode);
  73. if (OnExtendedDataException != null)
  74. throw OnExtendedDataException;
  75. }
  76. protected override void OnErrorOccured(Exception exp)
  77. {
  78. OnErrorOccurredInvocations.Add(exp);
  79. if (OnErrorOccurredException != null)
  80. throw OnErrorOccurredException;
  81. }
  82. protected override void OnFailure()
  83. {
  84. base.OnFailure();
  85. if (OnFailureException != null)
  86. throw OnFailureException;
  87. }
  88. protected override void OnRequest(RequestInfo info)
  89. {
  90. base.OnRequest(info);
  91. if (OnRequestException != null)
  92. throw OnRequestException;
  93. }
  94. protected override void OnSuccess()
  95. {
  96. base.OnSuccess();
  97. if (OnSuccessException != null)
  98. throw OnSuccessException;
  99. }
  100. protected override void OnWindowAdjust(uint bytesToAdd)
  101. {
  102. base.OnWindowAdjust(bytesToAdd);
  103. if (OnWindowAdjustException != null)
  104. throw OnWindowAdjustException;
  105. }
  106. protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize)
  107. {
  108. base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize);
  109. if (OnOpenConfirmationException != null)
  110. throw OnOpenConfirmationException;
  111. }
  112. protected override void OnOpenFailure(uint reasonCode, string description, string language)
  113. {
  114. base.OnOpenFailure(reasonCode, description, language);
  115. if (OnOpenFailureException != null)
  116. throw OnOpenFailureException;
  117. }
  118. }
  119. }