ExecRequestInfo.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 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. /// <param name="encoding">The character encoding to use.</param>
  49. /// <exception cref="System.ArgumentNullException"><paramref name="command"/> or <paramref name="encoding"/> is null.</exception>
  50. public ExecRequestInfo(string command, Encoding encoding)
  51. : this()
  52. {
  53. if (command == null)
  54. throw new System.ArgumentNullException("command");
  55. if (encoding == null)
  56. throw new System.ArgumentNullException("encoding");
  57. this.Command = command;
  58. this.Encoding = encoding;
  59. }
  60. /// <summary>
  61. /// Called when type specific data need to be loaded.
  62. /// </summary>
  63. protected override void LoadData()
  64. {
  65. base.LoadData();
  66. this.Command = this.ReadString();
  67. }
  68. /// <summary>
  69. /// Called when type specific data need to be saved.
  70. /// </summary>
  71. protected override void SaveData()
  72. {
  73. base.SaveData();
  74. this.Write(this.Command, this.Encoding);
  75. }
  76. }
  77. }