IBaseClient.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Renci.SshNet.Common;
  2. using System;
  3. using System.Net.Sockets;
  4. using System.Threading;
  5. #if FEATURE_TAP
  6. using System.Threading.Tasks;
  7. #endif
  8. namespace Renci.SshNet
  9. {
  10. /// <summary>
  11. /// Serves as base class for client implementations, provides common client functionality.
  12. /// </summary>
  13. public interface IBaseClient
  14. {
  15. /// <summary>
  16. /// Gets the connection info.
  17. /// </summary>
  18. /// <value>
  19. /// The connection info.
  20. /// </value>
  21. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  22. ConnectionInfo ConnectionInfo { get; }
  23. /// <summary>
  24. /// Gets a value indicating whether this client is connected to the server.
  25. /// </summary>
  26. /// <value>
  27. /// <c>true</c> if this client is connected; otherwise, <c>false</c>.
  28. /// </value>
  29. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  30. bool IsConnected { get; }
  31. /// <summary>
  32. /// Gets or sets the keep-alive interval.
  33. /// </summary>
  34. /// <value>
  35. /// The keep-alive interval. Specify negative one (-1) milliseconds to disable the
  36. /// keep-alive. This is the default value.
  37. /// </value>
  38. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  39. TimeSpan KeepAliveInterval { get; set; }
  40. /// <summary>
  41. /// Occurs when an error occurred.
  42. /// </summary>
  43. /// <example>
  44. /// <code source="..\..\src\Renci.SshNet.Tests\Classes\SshClientTest.cs" region="Example SshClient Connect ErrorOccurred" language="C#" title="Handle ErrorOccurred event" />
  45. /// </example>
  46. event EventHandler<ExceptionEventArgs> ErrorOccurred;
  47. /// <summary>
  48. /// Occurs when host key received.
  49. /// </summary>
  50. /// <example>
  51. /// <code source="..\..\src\Renci.SshNet.Tests\Classes\SshClientTest.cs" region="Example SshClient Connect HostKeyReceived" language="C#" title="Handle HostKeyReceived event" />
  52. /// </example>
  53. event EventHandler<HostKeyEventArgs> HostKeyReceived;
  54. /// <summary>
  55. /// Connects client to the server.
  56. /// </summary>
  57. /// <exception cref="InvalidOperationException">The client is already connected.</exception>
  58. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  59. /// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
  60. /// <exception cref="SshConnectionException">SSH session could not be established.</exception>
  61. /// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
  62. /// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
  63. void Connect();
  64. #if FEATURE_TAP
  65. /// <summary>
  66. /// Asynchronously connects client to the server.
  67. /// </summary>
  68. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  69. /// <returns>A <see cref="Task"/> that represents the asynchronous connect operation.
  70. /// </returns>
  71. /// <exception cref="InvalidOperationException">The client is already connected.</exception>
  72. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  73. /// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
  74. /// <exception cref="SshConnectionException">SSH session could not be established.</exception>
  75. /// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
  76. /// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
  77. Task ConnectAsync(CancellationToken cancellationToken);
  78. #endif
  79. /// <summary>
  80. /// Disconnects client from the server.
  81. /// </summary>
  82. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  83. void Disconnect();
  84. /// <summary>
  85. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  86. /// </summary>
  87. void Dispose();
  88. /// <summary>
  89. /// Sends a keep-alive message to the server.
  90. /// </summary>
  91. /// <remarks>
  92. /// Use <see cref="KeepAliveInterval"/> to configure the client to send a keep-alive at regular
  93. /// intervals.
  94. /// </remarks>
  95. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  96. void SendKeepAlive();
  97. }
  98. }