Beispiel #1
0
        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;
        }
Beispiel #2
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);
        }