ExecRequestInfo.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Text;
  3. namespace Renci.SshNet.Messages.Connection
  4. {
  5. /// <summary>
  6. /// Represents "exec" type channel request information
  7. /// </summary>
  8. internal class ExecRequestInfo : RequestInfo
  9. {
  10. /// <summary>
  11. /// Channel request name
  12. /// </summary>
  13. public const string NAME = "exec";
  14. /// <summary>
  15. /// Gets the name of the request.
  16. /// </summary>
  17. /// <value>
  18. /// The name of the request.
  19. /// </value>
  20. public override string RequestName
  21. {
  22. get { return NAME; }
  23. }
  24. /// <summary>
  25. /// Gets command to execute.
  26. /// </summary>
  27. /// <value>
  28. /// The command.
  29. /// </value>
  30. public string Command { get; private set; }
  31. /// <summary>
  32. /// Gets the encoding.
  33. /// </summary>
  34. /// <value>
  35. /// The encoding.
  36. /// </value>
  37. public Encoding Encoding { get; private set; }
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="ExecRequestInfo"/> class.
  40. /// </summary>
  41. public ExecRequestInfo()
  42. {
  43. WantReply = true;
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="ExecRequestInfo"/> class.
  47. /// </summary>
  48. /// <param name="command">The command.</param>
  49. /// <param name="encoding">The character encoding to use.</param>
  50. /// <exception cref="System.ArgumentNullException"><paramref name="command"/> or <paramref name="encoding"/> is null.</exception>
  51. public ExecRequestInfo(string command, Encoding encoding)
  52. : this()
  53. {
  54. if (command == null)
  55. throw new ArgumentNullException("command");
  56. if (encoding == null)
  57. throw new ArgumentNullException("encoding");
  58. Command = command;
  59. Encoding = encoding;
  60. }
  61. /// <summary>
  62. /// Called when type specific data need to be loaded.
  63. /// </summary>
  64. protected override void LoadData()
  65. {
  66. base.LoadData();
  67. Command = ReadString();
  68. }
  69. /// <summary>
  70. /// Called when type specific data need to be saved.
  71. /// </summary>
  72. protected override void SaveData()
  73. {
  74. base.SaveData();
  75. Write(Command, Encoding);
  76. }
  77. }
  78. }