Skip to content

Commit 3cb34b7

Browse files
committed
Change the way disctionary values are set in lookups when combined with ContainsKey
1 parent bda1520 commit 3cb34b7

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ All notable changes to this project will be documented in this file.
88
## Previous Releases
99
###
1010

11-
## [3.0.3] - 2021-08-09
11+
## [3.0.4] - 2021-08-11
12+
This change is to prevent the following Exception:
13+
14+
> System.ArgumentException - An item with the same key has already been added.
15+
16+
In cases where dictionaries / hashtables are used for lookups such as `Escape.cs` when there multiple threads trying to add to them at the same time.
17+
18+
Instead of using `Add(key, value)` which only allows 1 items with a given key to be added to the dictionary / hashtable, we are using the index accessor to set or update the value in a last one wins scenario, but only when its combined with `ContainsKey` which has indicated that an item with that key shouldn't exist.
19+
## [3.0.3] - 2021-08-10
1220
This change updates the `PipeParser` Version check when obtaining encoding characters from a message object in order to encode it to HL7; `string.CompareOrdinal` is now used instead of `System.Version` which is more forgiving when a version contains non numerical characters.
1321

1422
## [3.0.2] - 2021-08-09

build/nHapi.v3.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>nhapi</id>
5-
<version>3.0.3</version>
5+
<version>3.0.4</version>
66
<authors>Chad Chenoweth,Duane Edwards,Jake Aitchison</authors>
77
<license type="expression">MPL-2.0</license>
88
<projectUrl>https://github.com/nHapiNET/nHapi</projectUrl>
@@ -13,7 +13,7 @@
1313
NHapi allows Microsoft .NET developers to easily use an HL7 2.x object model. This object model allows for parsing and encoding HL7 2.x data to/from Pipe Delimited or XML formats. A very handy program for use in the health care industry.
1414

1515
This project is NOT affiliated with the HL7 organization. This software just conforms to the HL7 2.x specifications.</description>
16-
<releaseNotes>https://github.com/nHapiNET/nHapi/releases/tag/v3.0.3</releaseNotes>
16+
<releaseNotes>https://github.com/nHapiNET/nHapi/releases/tag/v3.0.4</releaseNotes>
1717
<tags>HL7 parsing healthcare HAPI xml</tags>
1818
<readme>docs\README.md</readme>
1919
<dependencies>

src/NHapi.Base/Model/GenericMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Type GetGenericMessageClass(string version)
7272

7373
if (c != null)
7474
{
75-
GenericMessages.Add(version, c);
75+
GenericMessages[version] = c;
7676
}
7777
}
7878

src/NHapi.Base/NHapi.Base.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<TargetFrameworks>net35;netstandard2.0</TargetFrameworks>
55
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
66
<PackageId>nhapi.base</PackageId>
7-
<PackageVersion>3.0.3</PackageVersion>
7+
<PackageVersion>3.0.4</PackageVersion>
88
<Authors>Chad Chenoweth;Duane Edwards;Jake Aitchison</Authors>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1010
<PackageProjectUrl>https://github.com/nHapiNET/nHapi</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/nHapiNET/nHapi.git</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<Description>The core components for parsing/encoding HL7 messages. Contains the base classes and interfaces for datatypes, segments, and messages.</Description>
1414
<PackageTags>HL7;parsing;healthcare;HAPI;xml</PackageTags>
15-
<PackageReleaseNotes>https://github.com/nHapiNET/nHapi/releases/tag/v3.0.3</PackageReleaseNotes>
15+
<PackageReleaseNotes>https://github.com/nHapiNET/nHapi/releases/tag/v3.0.4</PackageReleaseNotes>
1616
<PackageReadmeFile>docs\README.md</PackageReadmeFile>
1717
<AssemblyOriginatorKeyFile>..\..\NHapi.snk</AssemblyOriginatorKeyFile>
1818
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

src/NHapi.Base/Parser/Escape.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private static EncodingLookups BuildEncodingLookups(EncodingCharacters encChars)
252252
if (!VariousEncChars.ContainsKey(encChars))
253253
{
254254
// this means we haven't got the sequences for these encoding characters yet - let's make them
255-
VariousEncChars.Add(encChars, new EncodingLookups(encChars));
255+
VariousEncChars[encChars] = new EncodingLookups(encChars);
256256
}
257257

258258
return VariousEncChars[encChars];
@@ -323,7 +323,7 @@ private void TryAddEscapeSequence(char key, string value)
323323
{
324324
if (!EscapeSequences.ContainsKey(key))
325325
{
326-
EscapeSequences.Add(key, value);
326+
EscapeSequences[key] = value;
327327
}
328328
}
329329
}

src/NHapi.Base/Parser/PipeParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ private IStructureDefinition GetStructureDefinition(IMessage theMessage)
921921
{ theMessage.GetStructureName(), retVal },
922922
};
923923

924-
structureDefinitions.Add(messageType, dictionary);
924+
structureDefinitions[messageType] = dictionary;
925925

926926
return retVal;
927927
}

src/NHapi.Base/SupportClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ private void DoParsing()
14851485
stackNameSpace.Push(name);
14861486
Stack namespaceStack = new Stack();
14871487
namespaceStack.Push(prefixName);
1488-
prefixes.Add(namespaceURI, namespaceStack);
1488+
prefixes[namespaceURI] = namespaceStack;
14891489
if (callBackHandler != null)
14901490
{
14911491
((IXmlSaxContentHandler)callBackHandler).startPrefixMapping(prefixName, namespaceTemp);

0 commit comments

Comments
 (0)