Esempio n. 1
0
        public override void ValidateTerminalData(ConfigSerializer serializer)
        {
            try
            {
                if (serializer != null)
                {
                    byte []     tlv = null;
                    RETURN_CODE rt  = IDT_Augusta.SharedController.emv_retrieveTerminalData(ref tlv);

                    if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
                    {
                        Debug.WriteLine("VALIDATE TERMINAL DATA ----------------------------------------------------------------------");

                        // Get Configuration File AID List
                        SortedDictionary <string, string> cfgTerminalData      = serializer.GetTerminalData(serialNumber, EMVKernelVer);
                        Dictionary <string, Dictionary <string, string> > dict = Common.processTLV(tlv);

                        bool update = false;

                        // TAGS from device
                        foreach (Dictionary <string, string> devCollection in dict.Where(x => x.Key.Equals("unencrypted")).Select(x => x.Value))
                        {
                            foreach (var devTag in devCollection)
                            {
                                string devTagName  = devTag.Key;
                                string cfgTagValue = "";
                                bool   tagfound    = false;
                                bool   tagmatch    = false;
                                foreach (var cfgTag in cfgTerminalData)
                                {
                                    // Matching TAGNAME: compare keys
                                    if (devTag.Key.Equals(cfgTag.Key, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        tagfound = true;
                                        //Debug.Write("key: " + devTag.Key);

                                        // Compare value
                                        if (cfgTag.Value.Equals(devTag.Value, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            tagmatch = true;
                                            //Debug.WriteLine(" matches value: {0}", (object) devTag.Value);
                                        }
                                        else
                                        {
                                            //Debug.WriteLine(" DOES NOT match value: {0}!={1}", devTag.Value, cfgTag.Value);
                                            cfgTagValue = cfgTag.Value;
                                            update      = true;
                                        }
                                        break;
                                    }
                                    if (tagfound)
                                    {
                                        break;
                                    }
                                }
                                if (tagfound)
                                {
                                    Debug.WriteLine("TAG: {0} FOUND AND IT {1}", devTagName.PadRight(6, ' '), (tagmatch ? "MATCHES" : "DOES NOT MATCH"));
                                    if (!tagmatch)
                                    {
                                        Debug.WriteLine("{0}!={1}", devTag.Value, cfgTagValue);
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine("TAG: {0} NOT FOUND", (object)devTagName.PadRight(6, ' '));
                                    update = true;
                                }
                            }
                        }

                        // Update Terminal Data
                        if (update)
                        {
                            TerminalSettings termsettings = serializer.GetTerminalSettings();
                            string           workerstr    = termsettings.MajorConfiguration;
                            string           majorcfgstr  = Regex.Replace(workerstr, "[^0-9.]", string.Empty);
                            int majorcfgint = 5;
                            if (Int32.TryParse(majorcfgstr, out majorcfgint))
                            {
                                rt = IDT_Augusta.SharedController.emv_setTerminalMajorConfiguration(majorcfgint);
                                if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS)
                                {
                                    try
                                    {
                                        List <byte[]> collection = new List <byte[]>();
                                        foreach (var item in cfgTerminalData)
                                        {
                                            byte [] bytes   = null;
                                            string  payload = string.Format("{0}{1:X2}{2}", item.Key, item.Value.Length / 2, item.Value).ToUpper();
                                            if (System.Text.RegularExpressions.Regex.IsMatch(item.Value, @"[g-zG-Z\x20\x2E]+"))
                                            {
                                                List <byte> byteArray = new List <byte>();
                                                byteArray.AddRange(Device_IDTech.HexStringToByteArray(item.Key));
                                                byte [] item1   = Encoding.ASCII.GetBytes(item.Value);
                                                byte    itemLen = Convert.ToByte(item1.Length);
                                                byte [] item2   = new byte[] { itemLen };
                                                byteArray.AddRange(item2);
                                                byteArray.AddRange(item1);
                                                bytes = new byte[byteArray.Count];
                                                byteArray.CopyTo(bytes);
                                                //Logger.debug( "device: ValidateTerminalData() DATA={0}", BitConverter.ToString(bytes).Replace("-", string.Empty));
                                            }
                                            else
                                            {
                                                bytes = Device_IDTech.HexStringToByteArray(payload);
                                            }
                                            collection.Add(bytes);
                                        }
                                        var     flattenedList = collection.SelectMany(bytes => bytes);
                                        byte [] terminalData  = flattenedList.ToArray();
                                        rt = IDT_Augusta.SharedController.emv_setTerminalData(terminalData);
                                        if (rt != RETURN_CODE.RETURN_CODE_DO_SUCCESS)
                                        {
                                            Debug.WriteLine("emv_setTerminalData() error: {0}", rt);
                                            Logger.error("device: ValidateTerminalData() error={0} DATA={1}", rt, BitConverter.ToString(terminalData).Replace("-", string.Empty));
                                        }
                                    }
                                    catch (Exception exp)
                                    {
                                        Debug.WriteLine("device: ValidateTerminalData() - exception={0}", (object)exp.Message);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("TERMINAL DATA: emv_retrieveTerminalData() - ERROR={0}", rt);
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine("device: ValidateTerminalData() - exception={0}", (object)exp.Message);
            }
        }