SftpFSetStatRequest.cs 2.3 KB

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