ChannelStub.cs 4.1 KB

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