private static List <string> GetSubfileRecords(IdentificationCard idCard, Version version, string input) { var offset = ParseSubfileOffset(idCard, version, input); var records = input.Substring(offset).Split(new[] { ParseDataElementSeparator(input), ParseSegmentTerminator(input) }, StringSplitOptions.RemoveEmptyEntries).ToList(); var firstRecord = records[0].Substring(0, 2); if (firstRecord == "DL" || firstRecord == "ID") { records[0] = records[0].Substring(2); } return(records); }
private static List <string> GetSubfileRecords(IdentificationCard idCard, Version version, string input) { int offset = 0; if (version == Version.Aamva2000) { offset = Convert.ToInt32(input.Substring(21, 4)); // South Carolina's offset is off by one byte which causes the parsing of the IdNumber to fail if (idCard.IssuerIdentificationNumber == IssuerIdentificationNumber.SouthCarolina && offset == 30) { offset--; } } else if (version >= Version.Aamva2003) { offset = Convert.ToInt32(input.Substring(23, 4)); } if (offset == 0) { // Some jurisdictions, like Ontario, have a zero offset, which is incorrect. // Set the offset to the start of the subfile type indicator. var subfileRegex = new Regex("[0-9]{8}[A-Z]{2}[D][A-Z]{2}"); var match = subfileRegex.Match(input); if (match.Success) { const int subfileTypeLength = 2; const int firstElementIdLength = 3; offset = match.Index + match.Length - subfileTypeLength - firstElementIdLength; } } var records = input.Substring(offset).Split(new[] { ParseDataElementSeparator(input), ParseSegmentTerminator(input) }, StringSplitOptions.RemoveEmptyEntries).ToList(); var firstRecord = records[0].Substring(0, 2); if (firstRecord == "DL" || firstRecord == "ID") { records[0] = records[0].Substring(2); } return(records); }
private static int ParseSubfileOffset(IdentificationCard idCard, Version version, string input) { var offset = 0; if (version == Version.Aamva2000) { offset = Convert.ToInt32(input.Substring(21, 4)); // South Carolina's offset is off by one byte which causes the parsing of the IdNumber to fail if (idCard.IssuerIdentificationNumber == IssuerIdentificationNumber.SouthCarolina && offset == 30) { offset--; } } else if (version >= Version.Aamva2003) { var offsetAsString = input.Substring(23, 4); // Alberta specifies characters, like "abac", in the place of the expected offset // which causes the parsing of the subfile records to fail if (offsetAsString.All(char.IsDigit)) { offset = Convert.ToInt32(offsetAsString); } } if (offset == 0) { // Some jurisdictions, like Ontario, have a zero offset, which is incorrect. // Set the offset to the start of the subfile type indicator. var subfileRegex = new Regex("(DL|ID)([\\d\\w]{3,8})(DL|ID|Z\\w)([DZ][A-Z]{2})"); var match = subfileRegex.Match(input); if (match.Success) { const int subfileTypeLength = 2; const int firstElementIdLength = 3; offset = match.Index + match.Length - subfileTypeLength - firstElementIdLength; } } return(offset); }
private static void PopulateIdCard(IdentificationCard idCard, Version version, Country?country, List <string> subfileRecords, Validation validationLevel) { foreach (var subfileRecord in subfileRecords) { if (subfileRecord.Length < 3) { continue; } var elementId = subfileRecord.Substring(0, 3); var data = subfileRecord.Substring(3).Trim(); if (elementId.StartsWith("Z") && !idCard.AdditionalJurisdictionElements.ContainsKey(elementId)) { idCard.AdditionalJurisdictionElements.Add(elementId, data); continue; } var parser = CreateParserInstance(elementId, version, country, idCard); if (validationLevel == Validation.None) { try { parser?.ParseAndSet(data); } catch (Exception) { } continue; } parser?.ParseAndSet(data); } }
private static AbstractParser CreateParserInstance(string elementId, Version version, Country?country, IdentificationCard idCard) { if (!Parsers.Value.TryGetValue(elementId, out var type)) { return(null); } var instance = Activator.CreateInstance(type, idCard, version, country) as AbstractParser; return(instance); }
/// <summary> /// /// </summary> /// <param name="txt"></param> public void ParseText(string[] txt) { try { string s = ""; for (int i = 0; i < txt.Count(); i++) { if (txt[i] == "\u001e") { s += System.Uri.UnescapeDataString(txt[i]) + "\r"; } else { s += txt[i] + "\n"; } } LaurelFormat l = new LaurelFormat(); //l.SetLaurelFormat(txt); IdParser.IdentificationCard idCard = IdParser.IdParser.Parse(s); l.FIRST_NAME = idCard.FirstName; if (idCard.MiddleName != "NONE") { l.MIDDLE_INITIAL = idCard.MiddleName.Substring(0, 1); } l.LAST_NAME = idCard.LastName; l.NAME_SUFFIX = idCard.NameSuffix; l.STREET_ADDRESS = (idCard.StreetLine1 + ' ' + idCard.StreetLine2).Trim(); //l.PO_BOX = ""; l.CITY = idCard.City; l.STATE = idCard.JurisdictionCode; l.ZIP_CODE = idCard.PostalCode; l.FRN = null; l.SSN = null; l.E_MAIL = null; l.TELEPHONE = null; bool updated = false; //look for a match on the name first and ask about updating foreach (LaurelFormat ll in lst) { if (ll.FIRST_NAME.ToUpper() == l.FIRST_NAME && ll.LAST_NAME.ToUpper() == l.LAST_NAME) { DialogResult dr = MessageBox.Show("Would you like to update the existing record", "", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { ll.FIRST_NAME = idCard.FirstName; ll.MIDDLE_INITIAL = idCard.MiddleName.Substring(0, 1); ll.LAST_NAME = idCard.LastName; ll.NAME_SUFFIX = idCard.NameSuffix; ll.STREET_ADDRESS = (idCard.StreetLine1 + ' ' + idCard.StreetLine2).Trim(); //l.PO_BOX = ""; ll.CITY = idCard.City; ll.STATE = idCard.JurisdictionCode; ll.ZIP_CODE = idCard.PostalCode; updated = true; dataGridView1.Refresh(); } break; } } if (!updated) { lst.Add(l); } //dataGridView1.DataSource = lst.ToList(); return; } catch (Exception e2) { MessageBox.Show(e2.Message); } }