| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Text;
- using Renci.SshNet.Sftp.Responses;
- namespace Renci.SshNet.Sftp.Requests
- {
- internal class SftpOpenRequest : SftpRequest
- {
- #if TUNING
- private byte[] _fileName;
- private byte[] _attributes;
- #endif
- public override SftpMessageTypes SftpMessageType
- {
- get { return SftpMessageTypes.Open; }
- }
- #if TUNING
- public string Filename
- {
- get { return Encoding.GetString(_fileName, 0, _fileName.Length); }
- private set { _fileName = Encoding.GetBytes(value); }
- }
- #else
- public string Filename { get; private set; }
- #endif
- public Flags Flags { get; private set; }
- #if TUNING
- public SftpFileAttributes Attributes
- {
- get { return SftpFileAttributes.FromBytes(_attributes); }
- private set { _attributes = value.GetBytes(); }
- }
- #else
- public SftpFileAttributes Attributes { get; private set; }
- #endif
- public Encoding Encoding { get; private set; }
- #if TUNING
- /// <summary>
- /// Gets the size of the message in bytes.
- /// </summary>
- /// <value>
- /// The size of the messages in bytes.
- /// </value>
- protected override int BufferCapacity
- {
- get
- {
- var capacity = base.BufferCapacity;
- capacity += 4; // FileName length
- capacity += _fileName.Length; // FileName
- capacity += 4; // Flags
- capacity += _attributes.Length; // Attributes
- return capacity;
- }
- }
- #endif
- public SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, Action<SftpHandleResponse> handleAction, Action<SftpStatusResponse> statusAction)
- : this(protocolVersion, requestId, fileName, encoding, flags, SftpFileAttributes.Empty, handleAction, statusAction)
- {
- }
- private SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, SftpFileAttributes attributes, Action<SftpHandleResponse> handleAction, Action<SftpStatusResponse> statusAction)
- : base(protocolVersion, requestId, statusAction)
- {
- Encoding = encoding;
- Filename = fileName;
- Flags = flags;
- Attributes = attributes;
- SetAction(handleAction);
- }
- protected override void LoadData()
- {
- base.LoadData();
- throw new NotSupportedException();
- }
- protected override void SaveData()
- {
- base.SaveData();
- #if TUNING
- WriteBinaryString(_fileName);
- #else
- Write(Filename, Encoding);
- #endif
- Write((uint)Flags);
- #if TUNING
- Write(_attributes);
- #else
- Write(Attributes);
- #endif
- }
- }
- }
|