public override void ValidateAidList(ConfigSerializer serializer) { try { if (serializer != null) { byte [][] keys = null; RETURN_CODE rt = IDT_Augusta.SharedController.emv_retrieveAIDList(ref keys); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { Debug.WriteLine("VALIDATE AID LIST ----------------------------------------------------------------------"); // Get Configuration File AID List AIDList aid = serializer.GetAIDList(); List <Aid> AidList = new List <Aid>(); foreach (byte[] aidName in keys) { bool delete = true; bool found = false; bool update = false; KeyValuePair <string, Dictionary <string, string> > cfgCurrentItem = new KeyValuePair <string, Dictionary <string, string> >(); string devAidName = BitConverter.ToString(aidName).Replace("-", string.Empty); Debug.WriteLine("AID: {0} ===============================================", (object)devAidName); // Is this item in the approved list? foreach (var cfgItem in aid.Aid) { cfgCurrentItem = cfgItem; if (cfgItem.Key.Equals(devAidName, StringComparison.CurrentCultureIgnoreCase)) { found = true; byte[] value = null; rt = IDT_Augusta.SharedController.emv_retrieveApplicationData(aidName, ref value); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { Dictionary <string, Dictionary <string, string> > dict = Common.processTLV(value); // Compare values and replace if not the same foreach (Dictionary <string, string> devCollection in dict.Where(x => x.Key.Equals("unencrypted")).Select(x => x.Value)) { foreach (var cfgTag in cfgItem.Value) { bool tagfound = false; string cfgTagName = cfgTag.Key; string cfgTagValue = cfgTag.Value; foreach (var devTag in devCollection) { // Matching TAGNAME: compare keys if (devTag.Key.Equals(cfgTag.Key, StringComparison.CurrentCultureIgnoreCase)) { tagfound = true; //Debug.Write("key: " + devTag.Key); update = !cfgTag.Value.Equals(devTag.Value, StringComparison.CurrentCultureIgnoreCase); // Compare value and fix it if mismatched if (cfgTag.Value.Equals(devTag.Value, StringComparison.CurrentCultureIgnoreCase)) { //Debug.WriteLine("TAG: {0} FOUND AND IT MATCHES", (object) cfgTagName.PadRight(6,' ')); //Debug.WriteLine(" matches value: {0}", (object) devTag.Value); } else { Debug.WriteLine("TAG: {0} FOUND AND IT DOES NOT match value: {1}!={2}", cfgTagName.PadRight(6, ' '), cfgTag.Value, devTag.Value); } break; } } // No need to continue validating the remaing tags if (!tagfound || update) { break; } } } } delete = false; if (update) { byte[] tagCfgName = Device_IDTech.HexStringToByteArray(cfgCurrentItem.Key); List <byte[]> collection = new List <byte[]>(); foreach (var item in cfgCurrentItem.Value) { string payload = string.Format("{0}{1:X2}{2}", item.Key, item.Value.Length / 2, item.Value).ToUpper(); byte [] bytes = Device_IDTech.HexStringToByteArray(payload); collection.Add(bytes); } var flattenedList = collection.SelectMany(bytes => bytes); byte [] tagCfgValue = flattenedList.ToArray(); Aid cfgAid = new Aid(tagCfgName, tagCfgValue); AidList.Add(cfgAid); } } } // DELETE THIS AID if (delete) { Debug.WriteLine("AID: {0} - DELETE (NOT FOUND)", (object)devAidName.PadRight(14, ' ')); byte[] tagName = Device_IDTech.HexStringToByteArray(devAidName); rt = IDT_Augusta.SharedController.emv_removeApplicationData(tagName); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { Debug.WriteLine("AID: {0} DELETED", (object)devAidName.PadRight(6, ' ')); } } else if (!found) { byte[] tagCfgName = Device_IDTech.HexStringToByteArray(cfgCurrentItem.Key); List <byte[]> collection = new List <byte[]>(); foreach (var item in cfgCurrentItem.Value) { string payload = string.Format("{0}{1:X2}{2}", item.Key, item.Value.Length / 2, item.Value).ToUpper(); byte [] bytes = Device_IDTech.HexStringToByteArray(payload); collection.Add(bytes); } var flattenedList = collection.SelectMany(bytes => bytes); byte [] tagCfgValue = flattenedList.ToArray(); Aid cfgAid = new Aid(tagCfgName, tagCfgValue); AidList.Add(cfgAid); } } // Add missing AID(s) foreach (var aidElement in AidList) { byte [] aidName = aidElement.GetAidName(); byte [] aidValue = aidElement.GetAidValue(); rt = IDT_Augusta.SharedController.emv_setApplicationData(aidName, aidValue); if (rt == RETURN_CODE.RETURN_CODE_DO_SUCCESS) { string cfgTagName = BitConverter.ToString(aidName).Replace("-", string.Empty); string cfgTagValue = BitConverter.ToString(aidValue).Replace("-", string.Empty); Debug.WriteLine("AID: {0} UPDATED WITH VALUE: {1}", cfgTagName.PadRight(6, ' '), cfgTagValue); } } } else { Debug.WriteLine("TERMINAL DATA: emv_retrieveAIDList() - ERROR={0}", rt); } } } catch (Exception exp) { Debug.WriteLine("device: ValidateAidList() - exception={0}", (object)exp.Message); } }