| | | 1 | | using System; |
| | | 2 | | using Renci.SshNet.Sftp.Responses; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Sftp.Requests |
| | | 5 | | { |
| | | 6 | | internal abstract class SftpRequest : SftpMessage |
| | | 7 | | { |
| | | 8 | | private readonly Action<SftpStatusResponse> _statusAction; |
| | | 9 | | |
| | 63252 | 10 | | public uint RequestId { get; } |
| | | 11 | | |
| | 75 | 12 | | public uint ProtocolVersion { get; } |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the size of the message in bytes. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <value> |
| | | 18 | | /// The size of the messages in bytes. |
| | | 19 | | /// </value> |
| | | 20 | | protected override int BufferCapacity |
| | | 21 | | { |
| | | 22 | | get |
| | 31656 | 23 | | { |
| | 31656 | 24 | | var capacity = base.BufferCapacity; |
| | 31656 | 25 | | capacity += 4; // RequestId |
| | 31656 | 26 | | return capacity; |
| | 31656 | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | 31842 | 30 | | protected SftpRequest(uint protocolVersion, uint requestId, Action<SftpStatusResponse> statusAction) |
| | 31842 | 31 | | { |
| | 31842 | 32 | | RequestId = requestId; |
| | 31842 | 33 | | ProtocolVersion = protocolVersion; |
| | 31842 | 34 | | _statusAction = statusAction; |
| | 31842 | 35 | | } |
| | | 36 | | |
| | | 37 | | public virtual void Complete(SftpResponse response) |
| | 15176 | 38 | | { |
| | 15176 | 39 | | if (response is SftpStatusResponse statusResponse) |
| | 15176 | 40 | | { |
| | 15176 | 41 | | _statusAction(statusResponse); |
| | 15176 | 42 | | } |
| | | 43 | | else |
| | 0 | 44 | | { |
| | 0 | 45 | | throw new InvalidOperationException(string.Format("Response of type '{0}' is not expected.", response.Ge |
| | | 46 | | } |
| | 15176 | 47 | | } |
| | | 48 | | |
| | | 49 | | protected override void LoadData() |
| | 0 | 50 | | { |
| | 0 | 51 | | throw new InvalidOperationException("Request cannot be saved."); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | protected override void SaveData() |
| | 31656 | 55 | | { |
| | 31656 | 56 | | base.SaveData(); |
| | | 57 | | |
| | 31656 | 58 | | Write(RequestId); |
| | 31656 | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |