Beispiel #1
0
        public void SerialiseString()
        {
            var command = new ReadRawDataCommand("ee6d592b-483c-4c22-98ef-1070e290bf4f", new ReadRawDataCommand.PayloadData(5000, true, true, true, true, true, true, true, true, true, true, true, true, true, true));

            string result = command.Serialise();

            AreEqual(@"{""payload"":{""track1"":true,""track2"":true,""track3"":true,""chip"":true,""security"":true,""fluxInactive"":true,""watermark"":true,""memoryChip"":true,""track1Front"":true,""frontImage"":true,""backImage"":true,""track1JIS"":true,""track3JIS"":true,""ddi"":true,""timeout"":5000},""headers"":{""name"":""CardReader.ReadRawData"",""requestId"":""ee6d592b-483c-4c22-98ef-1070e290bf4f"",""type"":""command""}}", result);
        }
Beispiel #2
0
        private async void AcceptCard_Click(object sender, EventArgs e)
        {
            var cardReader = new XFS4IoTClient.ClientConnection(new Uri($"{textBoxCardReader.Text}"));

            try
            {
                await cardReader.ConnectAsync();
            }
            catch (Exception)
            {
                return;
            }

            var readRawDataCmd = new ReadRawDataCommand(
                Guid.NewGuid().ToString(),
                new ReadRawDataCommand.PayloadData(
                    Timeout: CommandTimeout,
                    Track1: true,
                    Track2: true,
                    Track3: true,
                    Chip: false,
                    Security: false,
                    FluxInactive: false,
                    Watermark: false,
                    MemoryChip: false,
                    Track1Front: false,
                    FrontImage: false,
                    BackImage: false,
                    Track1JIS: false,
                    Track3JIS: false,
                    Ddi: false));

            textBoxCommand.Text = readRawDataCmd.Serialise();

            await cardReader.SendCommandAsync(readRawDataCmd);

            textBoxResponse.Text = string.Empty;
            textBoxEvent.Text    = string.Empty;

            for (; ;)
            {
                object cmdResponse = await cardReader.ReceiveMessageAsync();

                if (cmdResponse is ReadRawDataCompletion response)
                {
                    textBoxResponse.Text = response.Serialise();
                    break;
                }
                else if (cmdResponse is XFS4IoT.CardReader.Events.MediaInsertedEvent insertedEv)
                {
                    textBoxEvent.Text = insertedEv.Serialise();
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #3
0
        private static async Task DoAcceptCard()
        {
            // Create the connection object. This doesn't start anything...
            var cardReader = new XFS4IoTClient.ClientConnection(
                EndPoint: CardReaderUri ?? throw new NullReferenceException()
                );

            // Open the actual network connection
            cardReader.ConnectAsync().Wait(1000);

            Logger.WriteLine($"Sending {nameof(ReadRawDataCommand)} command");

            //MessageBox((IntPtr)0, "Send CardReader ReadRawData command to read chip card", "XFS4IoT Test Client", 0);
            // Create a new command and send it to the device
            var command = new ReadRawDataCommand(Guid.NewGuid().ToString(), new ReadRawDataCommand.PayloadData(60000, true, true, true, true, true, true, true, true, true, true, true, true, true, true));
            await cardReader.SendCommandAsync(command);

            // Wait for a response from the device.
            Logger.WriteLine("Waiting for response... ");

            for (; ;)
            {
                object cmdResponse = await cardReader.ReceiveMessageAsync();

                if (cmdResponse is null)
                {
                    Logger.WriteLine($"Invalid response. {nameof(ReadRawDataCompletion)}");
                    break;
                }

                if (cmdResponse.GetType() != typeof(ReadRawDataCompletion))
                {
                    if (cmdResponse.GetType() == typeof(XFS4IoT.CardReader.Events.MediaInsertedEvent))
                    {
                        Logger.WriteLine($"Execute event received. {nameof(XFS4IoT.CardReader.Events.MediaInsertedEvent)}");
                        continue;
                    }
                    else
                    {
                        Logger.WriteLine($"Unexpected type of response. {nameof(ReadRawDataCompletion)}");
                    }
                }

                ReadRawDataCompletion response = cmdResponse as ReadRawDataCompletion;
                if (response is null)
                {
                    Logger.WriteLine($"Invalid type of response. {nameof(ReadRawDataCompletion)}");
                }
                else
                {
                    Logger.WriteLine($"Response received. {nameof(ReadRawDataCompletion)}");
                }

                break;
            }
        }
Beispiel #4
0
        public void UnserialiseStringToObject()
        {
            var ReadCardJSON = @"{
                ""headers"":{
                    ""name"":""CardReader.ReadRawData"",
                    ""requestId"":""b34800d0-9dd2-4d50-89ea-92d1b13df54b"",
                    ""type"":""command""
                },
                ""payload"":{
                    ""timeout"":5000,
                    ""track1"":true,
                    ""track2"": true,
                    ""track3"":true,
                    ""chip"":true,
                    ""security"":true,
                    ""fluxInactive"":true,
                    ""watermark"":true,
                    ""memoryChip"":true,
                    ""track1Front"":true,
                    ""frontImage"":true,
                    ""backImage"":true,
                    ""track1JIS"":true,
                    ""track3JIS"":true,
                    ""ddi"":true
                 }
            }";

            var assemblyName = Assembly.GetAssembly(typeof(ReadRawDataCommand))?.GetName();

            IsNotNull(assemblyName);

            var decoder = new MessageDecoder(MessageDecoder.AutoPopulateType.Command, assemblyName)
            {
                { typeof(ReadRawDataCommand) }
            };

            bool rc = decoder.TryUnserialise(ReadCardJSON, out object resultMessage);

            IsTrue(rc);
            IsNotNull(resultMessage);

            Command <ReadRawDataCommand.PayloadData> result = resultMessage as Command <ReadRawDataCommand.PayloadData> ?? throw new Exception();

            IsNotNull(result);

            IsInstanceOfType(result, typeof(ReadRawDataCommand));
            ReadRawDataCommand readCardCommand = result as ReadRawDataCommand;

            IsNotNull(readCardCommand);
            IsNotNull(readCardCommand.Payload);
            ReadRawDataCommand.PayloadData readCardPayload = readCardCommand.Payload as ReadRawDataCommand.PayloadData;
            IsNotNull(readCardPayload);
            AreEqual(true, readCardPayload.Track1);
        }
Beispiel #5
0
        public void Constructor()
        {
            var command = new ReadRawDataCommand(Guid.NewGuid().ToString(), new ReadRawDataCommand.PayloadData(1000, true, true, true, true, true, true, true, true, true, true, true, true, true, true));

            Assert.AreEqual(1000, command.Payload.Timeout);
        }