public void ReceiveDataSet(ICommand command, byte presentationContextID, Action <Stream> dataSetReader) { if ((_pendingCommand == null) || (_pendingPresentationContext == 0)) { throw new InvalidOperationException("No pending data set"); } if (command != _pendingCommand) { throw new ArgumentException($"{command} does not match pending command {_pendingCommand}"); } if (presentationContextID != _pendingPresentationContext) { throw new ArgumentException($"{presentationContextID} does not match pending presentation context {_pendingPresentationContext}"); } if (Input.Position == EndOfDataTransferPDUPosition) { ReadNextDataTransferPDU(); } using (var stream = new PresentationContextInputStream(this, FragmentType.DataSet)) { if (stream.PresentationContextID != presentationContextID) { throw new IOException($"Expected PCID {presentationContextID} but got {stream.PresentationContextID}"); } dataSetReader.Invoke(stream); stream.SkipToEnd(); } _pendingCommand = null; _pendingPresentationContext = 0; }
private ICommand ReadCommandFrom(PresentationContextInputStream stream) { var input = new BufferedStreamReader(stream); var command = CommandSerialization.ReadFrom(input); if (command is IMayHaveDataSet mayHaveDataSet) { if (command.IsFollowedByDataSet()) { _pendingCommand = command; _pendingPresentationContext = stream.PresentationContextID; } else if (mayHaveDataSet.IsDataSetRequired()) { throw new IOException($"{command} must be followed by a data set"); } } else if (command.IsFollowedByDataSet()) { throw new IOException($"Unexpected data set received for command {command}"); } stream.SkipToEnd(); if (TraceWriter != null) { NetUtils.TraceOutput(TraceWriter, $"PC {stream.PresentationContextID} received ", command); } return(command); }
public ICommand ReceiveCommand(byte presentationContextID) { EnsureNoPendingDataSet(); ReadNextPDU(DataUnitType.DataTransferPDU); using (var stream = new PresentationContextInputStream(this, FragmentType.Command)) { if (stream.PresentationContextID != presentationContextID) { throw new IOException($"Expected PCID {presentationContextID} but got {stream.PresentationContextID}"); } return(ReadCommandFrom(stream)); } }
public bool TryReceiveCommand(out byte presentationContextID, out ICommand command) { EnsureNoPendingDataSet(); if (ReadNextPDU(DataUnitType.DataTransferPDU, DataUnitType.ReleaseRequestPDU) is DataTransferPDUHeader) { using (var stream = new PresentationContextInputStream(this, FragmentType.Command)) { presentationContextID = stream.PresentationContextID; command = ReadCommandFrom(stream); } return(true); } else { presentationContextID = 0; command = null; return(false); } }