40 private readonly
int _maximumFileSize;
42 private byte[] _buffer;
43 private int _highWaterMark;
54 if (maximumFileSize <= 0)
56 throw new ArgumentOutOfRangeException(nameof(maximumFileSize), maximumFileSize,
57 "The maximum file size must be greater than zero.");
60 _maximumFileSize = maximumFileSize;
71 public bool IsComplete => _buffer !=
null && _highWaterMark >= _buffer.Length;
120 if (fragment ==
null)
throw new ArgumentNullException(nameof(fragment));
123 var fragmentData = data.DataFragment ?? [];
126 if (data.TotalSize < 0 || data.Offset < 0 || data.TotalSize > _maximumFileSize ||
127 data.Offset > data.TotalSize || data.FragmentSize > data.TotalSize - data.Offset ||
128 data.FragmentSize > fragmentData.Length)
136 if (data.Offset == 0)
138 _buffer =
new byte[data.TotalSize];
142 else if (_buffer ==
null)
149 if (data.TotalSize != _buffer.Length || fragment.
Type !=
FileType)
157 if (data.Offset > _highWaterMark)
163 if (data.FragmentSize > 0)
165 Array.Copy(fragmentData, 0, _buffer, data.Offset, data.FragmentSize);
166 _highWaterMark = Math.Max(_highWaterMark, data.Offset + data.FragmentSize);
183 throw new InvalidOperationException(
184 "The file transfer has not completed, so the assembled contents are not available.");
187 return (
byte[])_buffer.Clone();
byte[] GetFile()
Returns a copy of the assembled file.
byte FileType
Gets the file transfer type declared by the ACU, or zero when no transfer is in progress.
const int DefaultMaximumFileSize
Largest file accepted when the caller does not specify a limit.
FileTransferStatus AcceptFragment(FileTransferFragment fragment)
Accepts one file transfer fragment and produces the status reply to send back to the ACU.
bool IsComplete
Gets a value indicating whether every byte of the current transfer has been received.
bool IsTransferInProgress
Gets a value indicating whether a transfer has been started and has not yet been reset.
int ReceivedSize
Gets the number of contiguous bytes received so far.
FileTransferStatus.ControlFlags Action
Gets or sets the control flags reported to the ACU with every status reply.
ushort RequestedDelay
Gets or sets the delay in milliseconds the ACU is asked to wait before sending the next osdp_FILETRAN...
ushort UpdateMessageMaximum
Gets or sets the alternate maximum fragment size reported to the ACU.
int TotalSize
Gets the total size of the file being transferred, or zero when no transfer is in progress.
FileTransferReceiver(int maximumFileSize=DefaultMaximumFileSize)
Initializes a new instance of the FileTransferReceiver class.
void Reset()
Discards any transfer in progress and returns the receiver to its initial state.
Command data to send a data fragment of a file to a PD.
MessageDataFragment Fragment
Get the message data fragment.
byte Type
Get the file transfer type.
The PD file transfer status sent as a reply.
ControlFlags
Control Flags.
StatusDetail
Status Detail.