SftpMkDirRequest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Text;
  3. using Renci.SshNet.Sftp.Responses;
  4. namespace Renci.SshNet.Sftp.Requests
  5. {
  6. internal class SftpMkDirRequest : 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.MkDir; }
  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 SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpStatusResponse> statusAction)
  62. #if TUNING
  63. : this(protocolVersion, requestId, path, encoding, SftpFileAttributes.Empty, statusAction)
  64. #else
  65. : this(protocolVersion, requestId, path, encoding, null, statusAction)
  66. #endif
  67. {
  68. }
  69. private SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, SftpFileAttributes attributes, Action<SftpStatusResponse> statusAction)
  70. : base(protocolVersion, requestId, statusAction)
  71. {
  72. Encoding = encoding;
  73. this.Path = path;
  74. Attributes = attributes;
  75. }
  76. protected override void LoadData()
  77. {
  78. base.LoadData();
  79. #if TUNING
  80. _path = ReadBinary();
  81. #else
  82. this.Path = this.ReadString(this.Encoding);
  83. #endif
  84. this.Attributes = this.ReadAttributes();
  85. }
  86. protected override void SaveData()
  87. {
  88. base.SaveData();
  89. #if TUNING
  90. WriteBinaryString(_path);
  91. Write(AttributesBytes);
  92. #else
  93. this.Write(this.Path, this.Encoding);
  94. this.Write(this.Attributes);
  95. #endif
  96. }
  97. }
  98. }