SftpSetStatRequest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Text;
  3. using Renci.SshNet.Sftp.Responses;
  4. namespace Renci.SshNet.Sftp.Requests
  5. {
  6. internal class SftpSetStatRequest : SftpRequest
  7. {
  8. #if TUNING
  9. private byte[] _path;
  10. private byte[] _attributesBytes;
  11. #endif
  12. public override SftpMessageTypes SftpMessageType
  13. {
  14. get { return SftpMessageTypes.SetStat; }
  15. }
  16. #if TUNING
  17. public string Path
  18. {
  19. get { return Encoding.GetString(_path, 0, _path.Length); }
  20. private set { _path = Encoding.GetBytes(value); }
  21. }
  22. #else
  23. public string Path { get; private set; }
  24. #endif
  25. public Encoding Encoding { get; private set; }
  26. #if TUNING
  27. private SftpFileAttributes Attributes { get; set; }
  28. private byte[] AttributesBytes
  29. {
  30. get
  31. {
  32. if (_attributesBytes == null)
  33. {
  34. _attributesBytes = Attributes.GetBytes();
  35. }
  36. return _attributesBytes;
  37. }
  38. }
  39. #else
  40. public SftpFileAttributes Attributes { get; private set; }
  41. #endif
  42. #if TUNING
  43. /// <summary>
  44. /// Gets the size of the message in bytes.
  45. /// </summary>
  46. /// <value>
  47. /// The size of the messages in bytes.
  48. /// </value>
  49. protected override int BufferCapacity
  50. {
  51. get
  52. {
  53. var capacity = base.BufferCapacity;
  54. capacity += 4; // Path length
  55. capacity += _path.Length; // Path
  56. capacity += AttributesBytes.Length; // Attributes
  57. return capacity;
  58. }
  59. }
  60. #endif
  61. public SftpSetStatRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, SftpFileAttributes attributes, Action<SftpStatusResponse> statusAction)
  62. : base(protocolVersion, requestId, statusAction)
  63. {
  64. this.Encoding = encoding;
  65. this.Path = path;
  66. this.Attributes = attributes;
  67. }
  68. protected override void LoadData()
  69. {
  70. base.LoadData();
  71. #if TUNING
  72. _path = ReadBinary();
  73. #else
  74. this.Path = this.ReadString(this.Encoding);
  75. #endif
  76. this.Attributes = this.ReadAttributes();
  77. }
  78. protected override void SaveData()
  79. {
  80. base.SaveData();
  81. #if TUNING
  82. WriteBinaryString(_path);
  83. Write(AttributesBytes);
  84. #else
  85. this.Write(this.Path, this.Encoding);
  86. this.Write(this.Attributes);
  87. #endif
  88. }
  89. }
  90. }