SshConnectionException.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. #if NETFRAMEWORK
  3. using System.Runtime.Serialization;
  4. #endif // NETFRAMEWORK
  5. using Renci.SshNet.Messages.Transport;
  6. namespace Renci.SshNet.Common
  7. {
  8. /// <summary>
  9. /// The exception that is thrown when connection was terminated.
  10. /// </summary>
  11. #if NETFRAMEWORK
  12. [Serializable]
  13. #endif // NETFRAMEWORK
  14. public class SshConnectionException : SshException
  15. {
  16. /// <summary>
  17. /// Gets the disconnect reason if provided by the server or client. Otherwise None.
  18. /// </summary>
  19. public DisconnectReason DisconnectReason { get; private set; }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  22. /// </summary>
  23. public SshConnectionException()
  24. {
  25. }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  28. /// </summary>
  29. /// <param name="message">The message.</param>
  30. public SshConnectionException(string message)
  31. : base(message)
  32. {
  33. DisconnectReason = DisconnectReason.None;
  34. }
  35. /// <summary>
  36. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  37. /// </summary>
  38. /// <param name="message">The message.</param>
  39. /// <param name="disconnectReasonCode">The disconnect reason code.</param>
  40. public SshConnectionException(string message, DisconnectReason disconnectReasonCode)
  41. : base(message)
  42. {
  43. DisconnectReason = disconnectReasonCode;
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  47. /// </summary>
  48. /// <param name="message">The message.</param>
  49. /// <param name="inner">The inner.</param>
  50. public SshConnectionException(string message, Exception inner)
  51. : base(message, inner)
  52. {
  53. DisconnectReason = DisconnectReason.None;
  54. }
  55. /// <summary>
  56. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  57. /// </summary>
  58. /// <param name="message">The message.</param>
  59. /// <param name="disconnectReasonCode">The disconnect reason code.</param>
  60. /// <param name="inner">The inner.</param>
  61. public SshConnectionException(string message, DisconnectReason disconnectReasonCode, Exception inner)
  62. : base(message, inner)
  63. {
  64. DisconnectReason = disconnectReasonCode;
  65. }
  66. #if NETFRAMEWORK
  67. /// <summary>
  68. /// Initializes a new instance of the <see cref="SshConnectionException"/> class.
  69. /// </summary>
  70. /// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
  71. /// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
  72. /// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
  73. /// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0). </exception>
  74. protected SshConnectionException(SerializationInfo info, StreamingContext context)
  75. : base(info, context)
  76. {
  77. }
  78. #endif // NETFRAMEWORK
  79. }
  80. }