Exemplo n.º 1
0
        /// <summary>
        /// Starts running specific tests of the CertComplete Application.
        /// </summary>
        private async void debugCertCompleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String       str       = resultData.Text;
            InnowiDevice checkOutM = new InnowiDevice();

            if (str == null || str == "")
            {
                throw new Exception("Nothing to test");
            }
            else
            {
                //createListBoxItem(requestData.Text, count, res);

                if (PrintReceipt.Checked)
                {
                    string receipt = "";
                    if (NoSig.Checked)
                    {
                        receipt = await Task.Run(() => checkOutM.printEMVReceiptNoSig());

                        saveReceipts(receipt);
                    }
                    else
                    {
                        receipt = await Task.Run(() => checkOutM.printEMVReceipt());

                        Newtonsoft.Json.Linq.JObject ex  = Newtonsoft.Json.Linq.JObject.Parse(str);
                        Newtonsoft.Json.Linq.JArray  sig = (Newtonsoft.Json.Linq.JArray)ex.SelectToken("Signature", false);
                        saveReceipts(receipt, sig);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the test using the predifined parameters from the left text box with the
        /// appropriate device from the radio button selectors.
        /// </summary>
        private async void run_Click(object sender, EventArgs e)
        {
            /*
             * 1. Validate JSON request
             * 2. Initialize Payment Device
             * 3.
             */
            log.Write("runClicked");
            resultData.Text = "";
            Transaction transaction = new Transaction();

            source = new CancellationTokenSource();
            if (PAX_S300.Checked)
            {
                // Run the test on the PAX S300 Device
                Activity.Text = "Validating JSON";
                // Validate the JSON

                Activity.Text = "Initializing PAX S300";
                log.Write("Initializing PAX S300");
                // Initialize device with current settings
                PAXDevice s300 = new PAXDevice();
                if (!s300.initializeDevice(S300_DEVICE_CONFIG))
                {
                    log.Write("Device Initialization Failed");
                    Activity.Text = "Device initializaiton failed";
                }
                else
                {
                    bool errorCondition = false;
                    // Check Device Object Compatability
                    Activity.Text = "Checking Device Object Compatability";

                    // TO-DO: Check that all necessary fields are being sent to the respective device
                    //Newtonsoft.Json.Linq.JObject parameters = null;
                    //Newtonsoft.Json.Linq.JToken tests = null;
                    //Newtonsoft.Json.Linq.JToken[] testArray = null;
                    try
                    {
                        parameters = Newtonsoft.Json.Linq.JObject.Parse(requestData.Text);
                    }
                    catch (Exception parseException)
                    {
                        log.Write("Error: Invalid JSON: " + requestData.Text);
                        Activity.Text  = "Error: Invalid JSON";
                        errorCondition = true;
                    }
                    if (!errorCondition)
                    {
                        try
                        {
                            tests     = parameters.GetValue("TestSequenceData");
                            testArray = tests.ToArray();
                        }
                        catch (Exception noTestSequence)
                        {
                            log.Write("Error: No Test Sequenct Specified");
                            Activity.Text  = "Error: No Test Sequence Specified";
                            errorCondition = true;
                        }
                    }

                    int count           = 0;
                    int referenceNumber = 0;
                    while (!errorCondition && count < testArray.Length)
                    {
                        if (count > 0)
                        {
                            // Add the reference number to the request
                            Newtonsoft.Json.Linq.JObject to = (Newtonsoft.Json.Linq.JObject)testArray[count];
                            to.Add(new Newtonsoft.Json.Linq.JProperty("OrigRefNum", referenceNumber));
                        }
                        // Send Request to device
                        Activity.Text = "Sending Request to PAX S300 Device... Complete transaction on device";
                        string res = await Task.Run(() => s300.processTransaction(testArray[count]));

                        resultData.Text += res + Environment.NewLine + Environment.NewLine;

                        createListBoxItem(requestData.Text, count, res);

                        referenceNumber = s300.getOriginalReferenceNumber();

                        if (PrintReceipt.Checked)
                        {
                            string receipt = "";
                            if (NoSig.Checked)
                            {
                                receipt = await Task.Run(() => s300.printEMVReceiptNoSig());
                            }
                            else
                            {
                                receipt = await Task.Run(() => s300.printEMVReceipt());
                            }
                            saveReceipts(receipt);
                        }

                        count++;
                        Activity.Text = "Completed... Awaiting next command";
                        log.Write("Completed... Awaiting next command");
                    }
                }
            }
            else if (Innowi_ChecOut.Checked)
            {
                bool isAvailable = false;
                // Run the test on the PAX S300 Device
                Activity.Text = "Validating JSON";
                // Validate the JSON

                log.Write("Initializing Innowi ChecOutM Device");
                Activity.Text = "Initializing Innowi ChecOutM device";
                // Initialize device with current settings
                InnowiDevice checkOutM = new InnowiDevice();
                if (!checkOutM.initializeDevice(INNOWI_DEVICE_CONFIG))
                {
                    log.Write("Device Initialization Failed");
                    Activity.Text = "Device initializaiton failed";
                }
                else
                {
                    try
                    {
                        bool errorCondition = false;
                        // Check Device Object Compatability
                        Activity.Text = "Checking Device Object Compatability";

                        // TO-DO: Check that all necessary fields are being sent to the respective device

                        try
                        {
                            parameters = Newtonsoft.Json.Linq.JObject.Parse(requestData.Text);
                        }
                        catch (Exception parseException)
                        {
                            log.Write("Error: Invalid JSON: " + requestData.Text);
                            Activity.Text  = "Error: Invalid JSON";
                            errorCondition = true;
                        }
                        if (!errorCondition)
                        {
                            try
                            {
                                tests     = parameters.GetValue("TestSequenceData");
                                testArray = tests.ToArray();
                            }
                            catch (Exception noTestSequence)
                            {
                                log.Write("Error: No Test Sequence Specified");
                                Activity.Text  = "Error: No Test Sequence Specified";
                                errorCondition = true;
                            }
                        }
                        int count           = 0;
                        int referenceNumber = 0;
                        //Console.WriteLine("TestArray.Length: " + testArray.Length);
                        token = source.Token;
                        while (!errorCondition && count < testArray.Length && !token.IsCancellationRequested)
                        {
                            // Send Request to device
                            log.Write("Sending Request to Innowi ChecOut M Device...");
                            Activity.Text = "Sending Request to Innowi ChecOut M device...";
                            //Console.WriteLine("TestArray[count]: " + testArray[count]);

                            try
                            {
                                string res = await Task.Run(() => checkOutM.processTransaction(testArray[count]), token);

                                resultData.Text += res + Environment.NewLine + Environment.NewLine;
                                Activity.Text    = "Received Response from Innowi ChecOut M device";
                                log.Write("Received Response from Innowi Device: " + res);

                                createListBoxItem(requestData.Text, count, res);

                                if (PrintReceipt.Checked)
                                {
                                    string receipt = "";
                                    if (NoSig.Checked)
                                    {
                                        receipt = await Task.Run(() => checkOutM.printEMVReceiptNoSig());

                                        saveReceipts(receipt);
                                    }
                                    else
                                    {
                                        receipt = await Task.Run(() => checkOutM.printEMVReceipt());

                                        Newtonsoft.Json.Linq.JObject ex  = Newtonsoft.Json.Linq.JObject.Parse(res);
                                        Newtonsoft.Json.Linq.JArray  sig = (Newtonsoft.Json.Linq.JArray)ex.SelectToken("Signature", false);
                                        saveReceipts(receipt, sig);
                                    }
                                }
                                count++;
                                Activity.Text = "Completed... Awaiting next command";
                                log.Write("Completed... Awaiting next command");
                            }
                            catch (NullReferenceException nu)
                            {
                                errorCondition = true;
                                Activity.Text  = "Error: Connection lost to client... Awaiting next command";
                                log.Write("Error: Connection lost to client... Awaiting next command" + nu.StackTrace);
                            }
                            catch (OperationCanceledException cxl)
                            {
                                errorCondition = true;
                                Activity.Text  = "Operation Canceled... Awaiting next command";
                                log.Write("Operation Canceled... Awaiting next command");
                            }
                        }
                    }
                    catch (ArgumentNullException e1)
                    {
                        Console.WriteLine("ArgumentNullException: {0}", e1);
                        log.Write("ArgumentNullException: " + e1.ToString());
                    }
                    catch (SocketException e2)
                    {
                        Console.WriteLine("SocketException: {0}", e2);
                        log.Write("SocketException: " + e2.ToString());
                    }
                }
            }

            /*
             * Used for future device additions
             * Add additional device hooks here
             */
            else
            {
                Activity.Text = "Please select a device.";
            }
        }