Ejemplo n.º 1
0
        public void ParseDataNoData()
        {
            // Arrange
            var data = new List <byte>();

            data.AddRange(Message.ConvertShortToBytes(20));
            data.AddRange(Message.ConvertShortToBytes(10));
            data.AddRange(Message.ConvertShortToBytes(0));
            data.AddRange(new byte[] { });

            // Act
            var pivData = PIVData.ParseData(data.ToArray());

            // Assert
            Assert.AreEqual(20, pivData.WholeMessageLength);
            Assert.AreEqual(10, pivData.Offset);
            Assert.AreEqual(0, pivData.LengthOfFragment);
            Assert.AreEqual(new byte[] { }, pivData.Data);
        }
Ejemplo n.º 2
0
        internal virtual void OnReplyReceived(Reply reply)
        {
            {
                var handler = ReplyReceived;
                handler?.Invoke(this, new ReplyEventArgs {
                    Reply = reply
                });
            }

            switch (reply.Type)
            {
            case ReplyType.Nak:
            {
                var handler = NakReplyReceived;
                handler?.Invoke(this,
                                new NakReplyEventArgs(reply.ConnectionId, reply.Address,
                                                      Nak.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.LocalStatusReport:
            {
                var handler = LocalStatusReportReplyReceived;
                handler?.Invoke(this,
                                new LocalStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                    Model.ReplyData.LocalStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.InputStatusReport:
            {
                var handler = InputStatusReportReplyReceived;
                handler?.Invoke(this,
                                new InputStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                    Model.ReplyData.InputStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.OutputStatusReport:
            {
                var handler = OutputStatusReportReplyReceived;
                handler?.Invoke(this,
                                new OutputStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                     Model.ReplyData.OutputStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ReaderStatusReport:
            {
                var handler = ReaderStatusReportReplyReceived;
                handler?.Invoke(this,
                                new ReaderStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                     Model.ReplyData.ReaderStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.RawReaderData:
            {
                var handler = RawCardDataReplyReceived;
                handler?.Invoke(this,
                                new RawCardDataReplyEventArgs(reply.ConnectionId, reply.Address,
                                                              RawCardData.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ManufactureSpecific:
            {
                var handler = ManufacturerSpecificReplyReceived;
                handler?.Invoke(this,
                                new ManufacturerSpecificReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                       ManufacturerSpecific.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ExtendedRead:
            {
                var handler = ExtendedReadReplyReceived;
                handler?.Invoke(this,
                                new ExtendedReadReplyEventArgs(reply.ConnectionId, reply.Address,
                                                               ExtendedRead.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.PIVData:
            {
                var handler = PIVDataReplyReceived;
                handler?.Invoke(this,
                                new PIVDataReplyEventArgs(reply.ConnectionId, reply.Address,
                                                          PIVData.ParseData(reply.ExtractReplyData)));
                break;
            }
            }
        }