SftpSymLinkRequest.cs 2.8 KB

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