Skip to content

Commit

Permalink
Fixed a bug in the removing of incorrect line endings and added the .…
Browse files Browse the repository at this point in the history
…NET 2.0 dll to the pacakge
  • Loading branch information
c0shea committed Oct 16, 2016
1 parent d4ed3bd commit 4b3120c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 24 deletions.
4 changes: 2 additions & 2 deletions IdParser.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
30 changes: 30 additions & 0 deletions IdParser.Tests/DriversLicenseTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
#if !NET20
using System.Linq;
#endif
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IdParser.Tests {
Expand All @@ -14,7 +16,11 @@ public void TestMA2009License() {
Assert.AreEqual("ROBERT", idCard.FirstName);
Assert.AreEqual("LOWNEY", idCard.MiddleName);
Assert.AreEqual("SMITH", idCard.LastName);
#if NET20
Assert.AreEqual("MA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual(new DateTime(2016, 06, 29), idCard.IssueDate);
Assert.AreEqual(new DateTime(1977, 07, 07), idCard.DateOfBirth);
Assert.AreEqual(Country.USA, idCard.Country);
Expand All @@ -30,13 +36,19 @@ public void TestMA2016License() {
Assert.AreEqual("SAMPLE", idCard.LastName);
Assert.AreEqual(new DateTime(1971, 12, 31), idCard.DateOfBirth);

#if NET20
Assert.AreEqual("MA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual("S12345678", idCard.IdNumber);
Assert.AreEqual(new DateTime(2016, 08, 09), idCard.IssueDate);
Assert.AreEqual(Country.USA, idCard.Country);

Assert.AreEqual("24 BEACON STREET", idCard.StreetLine1);
#if !NET20
Assert.AreEqual("MA504", idCard.AdditionalJurisdictionElements.Single(e => e.Key == "ZMZ").Value);
#endif
Assert.AreEqual("02133-0000", idCard.FormattedPostalCode);

if (idCard is DriversLicense) {
Expand All @@ -57,8 +69,13 @@ public void TestNYLicense() {
Assert.AreEqual("Michael", license.LastName);
Assert.AreEqual(new DateTime(2013, 08, 31), license.DateOfBirth);

#if NET20
Assert.AreEqual("New York", IdParser.GetDescription(license.IssuerIdentificationNumber));
Assert.AreEqual("NY", IdParser.GetAbbreviation(license.IssuerIdentificationNumber));
#else
Assert.AreEqual("New York", license.IssuerIdentificationNumber.GetDescription());
Assert.AreEqual("NY", license.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual(new DateTime(2013, 08, 31), license.IssueDate);
Assert.AreEqual(new DateTime(2013, 08, 31), license.ExpirationDate);
Assert.AreEqual(Country.USA, license.Country);
Expand All @@ -77,7 +94,11 @@ public void TestVALicense() {
Assert.AreEqual("MAURY", idCard.LastName);
Assert.AreEqual(new DateTime(1958, 07, 15), idCard.DateOfBirth);

#if NET20
Assert.AreEqual("VA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
Assert.AreEqual("VA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual(new DateTime(2009, 08, 14), idCard.IssueDate);
Assert.AreEqual(new DateTime(2017, 08, 14), idCard.ExpirationDate);
Assert.AreEqual(Country.USA, idCard.Country);
Expand Down Expand Up @@ -108,8 +129,13 @@ public void TestGALicense() {
Assert.AreEqual("ANYTOWN", idCard.City);
Assert.AreEqual("303340000", idCard.PostalCode);

#if NET20
Assert.AreEqual("Georgia", IdParser.GetDescription(idCard.IssuerIdentificationNumber));
Assert.AreEqual("GA", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
Assert.AreEqual("Georgia", idCard.IssuerIdentificationNumber.GetDescription());
Assert.AreEqual("GA", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual(new DateTime(2006, 07, 01), idCard.IssueDate);
Assert.AreEqual(Country.USA, idCard.Country);

Expand Down Expand Up @@ -140,7 +166,11 @@ public void TestCTLicense() {
Assert.AreEqual("WETHERSFIELD", idCard.City);
Assert.AreEqual("061091896", idCard.PostalCode);

#if NET20
Assert.AreEqual("CT", IdParser.GetAbbreviation(idCard.IssuerIdentificationNumber));
#else
Assert.AreEqual("CT", idCard.IssuerIdentificationNumber.GetAbbreviation());
#endif
Assert.AreEqual("990000001", idCard.IdNumber);
Assert.AreEqual(new DateTime(2015, 01, 01), idCard.ExpirationDate);
Assert.AreEqual(Country.USA, idCard.Country);
Expand Down
12 changes: 6 additions & 6 deletions IdParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Global
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.Release|x86.Build.0 = Release|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.ActiveCfg = ReleaseNET46|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.Build.0 = ReleaseNET46|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET20|x86.Build.0 = ReleaseNET20|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{342DBA23-D9AD-4A5F-91B9-EBB08107C903}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|Any CPU
Expand All @@ -65,8 +65,8 @@ Global
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.Release|x86.Build.0 = Release|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.ActiveCfg = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.Build.0 = ReleaseNET46|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET20|x86.Build.0 = ReleaseNET20|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{8F0FFE69-6B8E-43AD-9E86-B2195ABE8A3D}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|Any CPU
Expand All @@ -93,8 +93,8 @@ Global
{FA949E77-9931-476C-BF93-DE61F5290CE7}.Release|x86.Build.0 = Release|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|Any CPU.ActiveCfg = ReleaseNET20|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|Any CPU.Build.0 = ReleaseNET20|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.ActiveCfg = ReleaseNET46|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.Build.0 = ReleaseNET46|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.ActiveCfg = ReleaseNET20|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET20|x86.Build.0 = ReleaseNET20|x86
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|Any CPU.ActiveCfg = ReleaseNET35|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|Any CPU.Build.0 = ReleaseNET35|Any CPU
{FA949E77-9931-476C-BF93-DE61F5290CE7}.ReleaseNET35|x86.ActiveCfg = ReleaseNET35|x86
Expand Down
46 changes: 41 additions & 5 deletions IdParser/IdParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
#if !NET20
using System.Linq;
#endif

namespace IdParser {
public static class IdParser {
Expand Down Expand Up @@ -94,13 +96,16 @@ private static void ValidateFormat(string input) {
// HID keyboard emulation (and some other methods) tend to replace the \r with \r\n
// which is invalid and doesn't conform to the AAMVA standard. This fixes it before attempting to parse the fields.
private static string RemoveIncorrectCarriageReturns(string input) {
if (input.Length < 5) {
return input;
var crLf = ExpectedCarriageReturn.ToString() + ExpectedLineFeed.ToString();
var doesInputContainCrLf = input.IndexOf(crLf, StringComparison.Ordinal) >= 0;

if (doesInputContainCrLf) {
var replacedString = input.Replace(ExpectedCarriageReturn.ToString(), string.Empty);

return replacedString.Substring(0, 3) + ExpectedCarriageReturn + replacedString.Substring(4);
}

var replacedString = input.Replace(ExpectedCarriageReturn.ToString(), string.Empty);

return replacedString.Substring(0, 3) + ExpectedCarriageReturn + replacedString.Substring(4);
return input;
}

/// <summary>
Expand Down Expand Up @@ -182,7 +187,11 @@ private static List<string> GetSubfileRecords(Version version, string input) {
offset = Convert.ToInt32(input.Substring(23, 4));
}

#if NET20
var records = new List<string>(input.Substring(offset).Split(new[] { ParseDataElementSeparator(input), ParseSegmentTerminator(input) }, StringSplitOptions.RemoveEmptyEntries));
#else
var records = input.Substring(offset).Split(new[] { ParseDataElementSeparator(input), ParseSegmentTerminator(input) }, StringSplitOptions.RemoveEmptyEntries).ToList();
#endif
var firstRecord = records[0].Substring(0, 2);
if (firstRecord == "DL" || firstRecord == "ID") {
records[0] = records[0].Substring(2);
Expand All @@ -191,6 +200,32 @@ private static List<string> GetSubfileRecords(Version version, string input) {
return records;
}

// Extension methods are not supported in .NET 2.0
#if NET20
public static string GetDescription(Enum value) {
var field = value.GetType().GetField(value.ToString());

var attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;

return attribute == null ? value.ToString() : attribute.Description;
}

public static string GetAbbreviation(Enum value) {
var field = value.GetType().GetField(value.ToString());

var attribute = Attribute.GetCustomAttribute(field, typeof(AbbreviationAttribute)) as AbbreviationAttribute;

return attribute == null ? value.ToString() : attribute.Abbreviation;
}

public static Country GetCountry(Enum value) {
var field = value.GetType().GetField(value.ToString());

var attribute = Attribute.GetCustomAttribute(field, typeof(CountryAttribute)) as CountryAttribute;

return attribute == null ? Country.Unknown : attribute.Country;
}
#else
public static string GetDescription(this Enum value) {
var field = value.GetType().GetField(value.ToString());

Expand All @@ -214,5 +249,6 @@ public static Country GetCountry(this Enum value) {

return attribute == null ? Country.Unknown : attribute.Country;
}
#endif
}
}
6 changes: 3 additions & 3 deletions IdParser/IdParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Core" Condition="'$(TargetFrameworkVersion)' == 'v3.5' Or '$(TargetFrameworkVersion)' == 'v4.0' Or '$(TargetFrameworkVersion)' == 'v4.5' Or '$(TargetFrameworkVersion)' == 'v4.6'" />
<Reference Include="System.Xml.Linq" Condition="'$(TargetFrameworkVersion)' == 'v3.5' Or '$(TargetFrameworkVersion)' == 'v4.0' Or '$(TargetFrameworkVersion)' == 'v4.5' Or '$(TargetFrameworkVersion)' == 'v4.6'" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFrameworkVersion)' == 'v4.0' Or '$(TargetFrameworkVersion)' == 'v4.5' Or '$(TargetFrameworkVersion)' == 'v4.6'" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" Condition="'$(TargetFrameworkVersion)' == 'v4.0' Or '$(TargetFrameworkVersion)' == 'v4.5' Or '$(TargetFrameworkVersion)' == 'v4.6'" />
<Reference Include="System.Net.Http" Condition="'$(TargetFrameworkVersion)' == 'v4.5' Or '$(TargetFrameworkVersion)' == 'v4.6'" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions IdParser/IdParser.nuspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<id>IdParser</id>
<version>2.0.1</version>
<title>ID Parser</title>
<authors>Connor O'Shea</authors>
<owners>Connor O'Shea</owners>
<licenseUrl>https://github.com/c0shea/IdParser/blob/master/LICENSE.md</licenseUrl>
<projectUrl>https://github.com/c0shea/IdParser</projectUrl>
<iconUrl>https://raw.githubusercontent.com/c0shea/IdParser/master/NuGet%20Package%20Icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Fixed bugs in name and date parsing, improved country parsing, implemented IComparable and IEquatable for Height class, and deprecated old Parse method.</releaseNotes>
<description>Parses AAMVA-compliant driver's licenses and ID cards</description>
<releaseNotes>Fixed a bug in removing incorrect line endings and added .NET 2.0 assembly to package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>Drivers License Identification Parser PDF417 AAMVA</tags>
</metadata>
<files>
<file src="bin\Release\net20\*.*" target="lib\net20\" />
<file src="bin\Release\net20\*.*" target="lib\net20\" />
<file src="bin\Release\net35\*.*" target="lib\net35\" />
<file src="bin\Release\net40\*.*" target="lib\net40\" />
<file src="bin\Release\net45\*.*" target="lib\net45\" />
Expand Down
4 changes: 4 additions & 0 deletions IdParser/IdentificationCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ internal IdentificationCard(Version version, Country country, string input, List
AamvaVersionNumber = version;

// The country is needed before we parse the subfile records so that dates can be interpreted correctly
#if NET20
Country = country == Country.Unknown ? IdParser.GetCountry(IssuerIdentificationNumber) : country;
#else
Country = country == Country.Unknown ? IssuerIdentificationNumber.GetCountry() : country;
#endif

if (version == Version.Aamva2000) {
JurisdictionVersionNumber = 0;
Expand Down
4 changes: 2 additions & 2 deletions IdParser/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]

0 comments on commit 4b3120c

Please sign in to comment.