コード例 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal static async Task <S101Message> ReadFromAsync(
            ReadBuffer readBuffer, CancellationToken cancellationToken)
        {
            if (!await readBuffer.ReadAsync(cancellationToken))
            {
                return(null);
            }

            var         slot = readBuffer[readBuffer.Index++];
            byte        messageType;
            S101Command command;

            try
            {
                await readBuffer.FillAsync(1, cancellationToken);

                messageType = GetMessageType(readBuffer);
                command     = await S101Command.ReadFromAsync(readBuffer, cancellationToken);
            }
            catch (EndOfStreamException ex)
            {
                throw new S101Exception("Unexpected end of stream.", ex);
            }

            return(new S101Message(slot, messageType, command));
        }
コード例 #2
0
 /// <summary>Initializes a new instance of the <see cref="S101Message"/> class.</summary>
 /// <exception cref="ArgumentNullException"><paramref name="command"/> equals <c>null</c>.</exception>
 public S101Message(byte slot, S101Command command)
     : this(slot, MessageType.Ember, command)
 {
     if (command == null)
     {
         throw new ArgumentNullException(nameof(command));
     }
 }
コード例 #3
0
        private bool ReadCore()
        {
            while (this.logReader.IsStartElement(LogNames.Event))
            {
                switch (this.eventType = this.logReader.GetAttribute(LogNames.Type))
                {
                case LogNames.Message:
                    this.timeUtc   = this.ReadTime();
                    this.direction = this.logReader.GetAttribute(LogNames.Direction);
                    this.number    = int.Parse(
                        this.logReader.GetAttribute(LogNames.Number),
                        NumberStyles.None,
                        CultureInfo.InvariantCulture);
                    this.logReader.ReadStartElement(LogNames.Event);
                    this.logReader.ReadStartElement(LogNames.Slot);
                    var slot = ParseHex(this.logReader.ReadContentAsString());
                    this.logReader.ReadEndElement();
                    this.logReader.ReadStartElement(LogNames.Command);
                    var command = S101Command.Parse(this.logReader.ReadContentAsString());
                    this.logReader.ReadEndElement();
                    this.message = new S101Message(slot, command);

                    if (!this.logReader.IsStartElement(LogNames.Payload))
                    {
                        throw new XmlException("The Payload element is missing.");
                    }

                    this.payload = this.GetLogPayload();
                    return(true);

                case LogNames.OutOfFrameByte:
                    this.timeUtc   = this.ReadTime();
                    this.direction = this.logReader.GetAttribute(LogNames.Direction);
                    this.number    = 0;
                    this.message   = null;
                    this.logReader.ReadStartElement(LogNames.Event);
                    this.payload = new[] { ParseHex(this.logReader.ReadContentAsString()) };
                    this.logReader.ReadEndElement();
                    return(true);

                default:
                    this.logReader.Skip();
                    break;
                }
            }

            this.logReader.ReadEndElement();
            this.Clear();
            return(false);
        }
コード例 #4
0
 private S101Message(byte slot, byte messageType, S101Command command)
 {
     this.Slot        = slot;
     this.messageType = messageType;
     this.Command     = command;
 }