ExecRequestInfo.cs 2.3 KB

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