ServiceRequestMessage.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. namespace Renci.SshNet.Messages.Transport
  3. {
  4. /// <summary>
  5. /// Represents SSH_MSG_SERVICE_REQUEST message.
  6. /// </summary>
  7. [Message("SSH_MSG_SERVICE_REQUEST", 5)]
  8. public class ServiceRequestMessage : Message
  9. {
  10. /// <summary>
  11. /// Gets the name of the service.
  12. /// </summary>
  13. /// <value>
  14. /// The name of the service.
  15. /// </value>
  16. public ServiceName ServiceName { get; private set; }
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="ServiceRequestMessage"/> class.
  19. /// </summary>
  20. /// <param name="serviceName">Name of the service.</param>
  21. public ServiceRequestMessage(ServiceName serviceName)
  22. {
  23. this.ServiceName = serviceName;
  24. }
  25. /// <summary>
  26. /// Called when type specific data need to be loaded.
  27. /// </summary>
  28. protected override void LoadData()
  29. {
  30. throw new InvalidOperationException("Load data is not supported.");
  31. }
  32. /// <summary>
  33. /// Called when type specific data need to be saved.
  34. /// </summary>
  35. protected override void SaveData()
  36. {
  37. switch (this.ServiceName)
  38. {
  39. case ServiceName.UserAuthentication:
  40. this.WriteAscii("ssh-userauth");
  41. break;
  42. case ServiceName.Connection:
  43. this.WriteAscii("ssh-connection");
  44. break;
  45. default:
  46. throw new NotSupportedException("Not supported service name");
  47. }
  48. }
  49. }
  50. }