Skip to content

Commit

Permalink
Decouple source generation from NHapi.Base
Browse files Browse the repository at this point in the history
* Create new project and move source generating source code to it
  • Loading branch information
milkshakeuk committed Dec 11, 2020
1 parent 78690d5 commit 4dad32d
Show file tree
Hide file tree
Showing 33 changed files with 3,855 additions and 3,809 deletions.
7 changes: 0 additions & 7 deletions Hl7Models.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHapi.NUnit", "tests\NHapi.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHapi.Model.V25", "src\NHapi.Model.V25\NHapi.Model.V25.csproj", "{BE6CDFAD-560E-44CC-B23B-87252DD4392C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelGenerator", "src\ModelGenerator\ModelGenerator.csproj", "{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHapi.Model.V22_ZSegments", "src\NHapi.Model.V22_ZSegments\NHapi.Model.V22_ZSegments.csproj", "{FFECB4DE-C192-4F95-9DC7-9D0A815D250A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHapi.Model.V251", "src\NHapi.Model.V251\NHapi.Model.V251.csproj", "{616C84EF-BE12-47A8-A524-D8230D572163}"
Expand Down Expand Up @@ -86,10 +84,6 @@ Global
{BE6CDFAD-560E-44CC-B23B-87252DD4392C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE6CDFAD-560E-44CC-B23B-87252DD4392C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE6CDFAD-560E-44CC-B23B-87252DD4392C}.Release|Any CPU.Build.0 = Release|Any CPU
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617}.Release|Any CPU.Build.0 = Release|Any CPU
{FFECB4DE-C192-4F95-9DC7-9D0A815D250A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFECB4DE-C192-4F95-9DC7-9D0A815D250A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFECB4DE-C192-4F95-9DC7-9D0A815D250A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -135,7 +129,6 @@ Global
{4B3417BA-0090-4FA0-B04B-BB19563FC11C} = {9FC71692-FA33-4213-8323-E53688BCA633}
{7C7C99F0-672B-4DB1-A125-5ED7A3ADF95E} = {65FE0FF9-296E-4C9B-A670-05D7AC663569}
{BE6CDFAD-560E-44CC-B23B-87252DD4392C} = {9FC71692-FA33-4213-8323-E53688BCA633}
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617} = {9FC71692-FA33-4213-8323-E53688BCA633}
{FFECB4DE-C192-4F95-9DC7-9D0A815D250A} = {9FC71692-FA33-4213-8323-E53688BCA633}
{616C84EF-BE12-47A8-A524-D8230D572163} = {9FC71692-FA33-4213-8323-E53688BCA633}
{A21B73C4-D18E-4BBA-BE6C-FD52A1F5F6C9} = {9FC71692-FA33-4213-8323-E53688BCA633}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This repository is now actively maintained as of 10/21/2020.

# nHapi
NHapi is a .NET port of the original Java project [HAPI](http://hl7api.sourceforge.net/).
NHapi is a .NET port of the original Java project [HAPI](https://github.com/hapifhir/hapi-hl7v2).

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.

Expand All @@ -20,7 +20,7 @@ This project is **NOT** affiliated with the HL7 organization. This software just

## Requirements

NHapi currently targets version 3.5 of the .NET Framework
NHapi currently targets version 3.5 of the .NET Framework and netstandard2.0

## Getting Started

Expand Down
7 changes: 7 additions & 0 deletions nHapi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHapi.SourceGeneration", "src\NHapi.SourceGeneration\NHapi.SourceGeneration.csproj", "{D9A637CE-C1B6-499C-B81B-82AE30580394}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,6 +40,10 @@ Global
{7216E533-4B1E-476B-9E9A-0982F166FECD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7216E533-4B1E-476B-9E9A-0982F166FECD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7216E533-4B1E-476B-9E9A-0982F166FECD}.Release|Any CPU.Build.0 = Release|Any CPU
{D9A637CE-C1B6-499C-B81B-82AE30580394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9A637CE-C1B6-499C-B81B-82AE30580394}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9A637CE-C1B6-499C-B81B-82AE30580394}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9A637CE-C1B6-499C-B81B-82AE30580394}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -46,6 +52,7 @@ Global
{5A080123-0597-46C3-AE78-2007EFB0DD68} = {D4B8E273-F9BA-459F-8489-87420B160690}
{EBB8E9C9-7FF2-49C4-96EF-C5B87E4C2617} = {D4B8E273-F9BA-459F-8489-87420B160690}
{7216E533-4B1E-476B-9E9A-0982F166FECD} = {3F799636-AB73-4BBF-BA54-66E3C0FF7849}
{D9A637CE-C1B6-499C-B81B-82AE30580394} = {D4B8E273-F9BA-459F-8489-87420B160690}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D05CB0C7-76FB-4E93-AFBD-16CF7ACD5F87}
Expand Down
Binary file removed nHapi.suo
Binary file not shown.
6 changes: 3 additions & 3 deletions src/ModelGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Configuration;
using NHapi.Base;
using NHapi.Base.SourceGeneration;
using ConfigurationSettings = NHapi.Base.ConfigurationSettings;
using NHapi.SourceGeneration;
using NHapi.SourceGeneration.Generators;
using ConfigurationSettings = NHapi.SourceGeneration.ConfigurationSettings;

namespace ModelGenerator
{
Expand Down
2 changes: 1 addition & 1 deletion src/ModelGenerator/ModelGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NHapi.Base\NHapi.Base.csproj" />
<ProjectReference Include="..\NHapi.SourceGeneration\NHapi.SourceGeneration.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
Expand Down
2 changes: 1 addition & 1 deletion src/NHapi.Base/HL7Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// 2001. All Rights Reserved.
/// Contributor(s): ______________________________________.
/// Alternatively, the contents of this file may be used under the terms of the
/// GNU General Public License (the GPL), in which case the provisions of the GPL are
/// GNU General Public License (the GPL), in which case the provisions of the GPL are
/// applicable instead of those above. If you wish to allow use of your version of this
/// file only under the terms of the GPL and not to allow others to use your version
/// of this file under the MPL, indicate your decision by deleting the provisions above
Expand Down
3 changes: 1 addition & 2 deletions src/NHapi.Base/NHapi.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Data.Odbc" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
Expand All @@ -27,7 +26,7 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/NHapi.Base/Parser/DefaultModelClassFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using NHapi.Base;
using NHapi.Base.Model;
using NHapi.Base.SourceGeneration;
using NHapi.Base.Log;
using NHapi.Base.Model.Configuration;

Expand Down
3 changes: 2 additions & 1 deletion src/NHapi.Base/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly: Guid("fb32b28b-416b-4145-992b-824afe2eb911")]
[assembly: Guid("fb32b28b-416b-4145-992b-824afe2eb911")]
[assembly: InternalsVisibleTo("NHapi.SourceGeneration")]
253 changes: 0 additions & 253 deletions src/NHapi.Base/SupportClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,259 +1971,6 @@ public static Object Pop(ArrayList stack)

/*******************************/

public class TransactionManager
{
public static ConnectionHashTable manager = new ConnectionHashTable();

public class ConnectionHashTable : Hashtable
{
public DbCommand CreateStatement(OdbcConnection connection)
{
DbCommand command = connection.CreateCommand();
DbTransaction transaction;
if (this[connection] != null)
{
ConnectionProperties Properties = ((ConnectionProperties) this[connection]);
transaction = Properties.Transaction;
command.Transaction = transaction;
command.CommandTimeout = 0;
}
else
{
ConnectionProperties TempProp = new ConnectionProperties();
TempProp.AutoCommit = true;
TempProp.TransactionLevel = 0;
command.Transaction = TempProp.Transaction;
command.CommandTimeout = 0;
Add(connection, TempProp);
}
return command;
}

public void Commit(OdbcConnection connection)
{
if (this[connection] != null && !((ConnectionProperties) this[connection]).AutoCommit)
{
ConnectionProperties Properties = ((ConnectionProperties) this[connection]);
DbTransaction transaction = Properties.Transaction;
transaction.Commit();
if (Properties.TransactionLevel == 0)
Properties.Transaction = connection.BeginTransaction();
else
Properties.Transaction = connection.BeginTransaction(Properties.TransactionLevel);
}
}

public void RollBack(OdbcConnection connection)
{
if (this[connection] != null && !((ConnectionProperties) this[connection]).AutoCommit)
{
ConnectionProperties Properties = ((ConnectionProperties) this[connection]);
DbTransaction transaction = Properties.Transaction;
transaction.Rollback();
if (Properties.TransactionLevel == 0)
Properties.Transaction = connection.BeginTransaction();
else
Properties.Transaction = connection.BeginTransaction(Properties.TransactionLevel);
}
}

public void SetAutoCommit(OdbcConnection connection, bool boolean)
{
if (this[connection] != null)
{
ConnectionProperties Properties = ((ConnectionProperties) this[connection]);
if (Properties.AutoCommit != boolean)
{
Properties.AutoCommit = boolean;
if (!boolean)
{
if (Properties.TransactionLevel == 0)
Properties.Transaction = connection.BeginTransaction();
else
Properties.Transaction = connection.BeginTransaction(Properties.TransactionLevel);
}
else
{
DbTransaction transaction = Properties.Transaction;
if (transaction != null)
{
transaction.Commit();
}
}
}
}
else
{
ConnectionProperties TempProp = new ConnectionProperties();
TempProp.AutoCommit = boolean;
TempProp.TransactionLevel = 0;
if (!boolean)
TempProp.Transaction = connection.BeginTransaction();
Add(connection, TempProp);
}
}

public DbCommand PrepareStatement(OdbcConnection connection, String sql)
{
DbCommand command = CreateStatement(connection);
command.CommandText = sql;
command.CommandTimeout = 0;
return command;
}

public DbCommand PrepareCall(OdbcConnection connection, String sql)
{
DbCommand command = CreateStatement(connection);
command.CommandText = sql;
command.CommandTimeout = 0;
return command;
}

public void SetTransactionIsolation(OdbcConnection connection, int level)
{
ConnectionProperties Properties;
if (level == (int) IsolationLevel.ReadCommitted)
SetAutoCommit(connection, false);
else if (level == (int) IsolationLevel.ReadUncommitted)
SetAutoCommit(connection, false);
else if (level == (int) IsolationLevel.RepeatableRead)
SetAutoCommit(connection, false);
else if (level == (int) IsolationLevel.Serializable)
SetAutoCommit(connection, false);

if (this[connection] != null)
{
Properties = ((ConnectionProperties) this[connection]);
Properties.TransactionLevel = (IsolationLevel) level;
}
else
{
Properties = new ConnectionProperties();
Properties.AutoCommit = true;
Properties.TransactionLevel = (IsolationLevel) level;
Add(connection, Properties);
}
}

public int GetTransactionIsolation(OdbcConnection connection)
{
if (this[connection] != null)
{
ConnectionProperties Properties = ((ConnectionProperties) this[connection]);
if (Properties.TransactionLevel != 0)
return (int) Properties.TransactionLevel;
else
return 2;
}
else
return 2;
}

public bool GetAutoCommit(OdbcConnection connection)
{
if (this[connection] != null)
return ((ConnectionProperties) this[connection]).AutoCommit;
else
return true;
}

/// <summary>
/// Sets the value of a parameter using any permitted object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
public void SetValue(DbCommand command, int parameterIndex, Object parameter)
{
if (command.Parameters.Count < parameterIndex)
command.Parameters.Add(command.CreateParameter());
command.Parameters[parameterIndex - 1].Value = parameter;
}

/// <summary>
/// Sets a parameter to SQL NULL.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="targetSqlType">The SQL type to be sent to the database.</param>
public void SetNull(DbCommand command, int parameterIndex, int sqlType)
{
if (command.Parameters.Count < parameterIndex)
command.Parameters.Add(command.CreateParameter());
command.Parameters[parameterIndex - 1].Value = Convert.DBNull;
command.Parameters[parameterIndex - 1].DbType = (DbType) sqlType;
}

/// <summary>
/// Sets the value of a parameter using an object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
/// <param name="targetSqlType">The SQL type to be sent to the database.</param>
public void SetObject(DbCommand command, int parameterIndex, Object parameter, int targetSqlType)
{
if (command.Parameters.Count < parameterIndex)
command.Parameters.Add(command.CreateParameter());
command.Parameters[parameterIndex - 1].Value = parameter;
command.Parameters[parameterIndex - 1].DbType = (DbType) targetSqlType;
}

/// <summary>
/// Sets the value of a parameter using an object. The given argument object will be converted to the
/// corresponding SQL type before being sent to the database.
/// </summary>
/// <param name="command">Command object to be changed.</param>
/// <param name="parameterIndex">One-based index of the parameter to be set.</param>
/// <param name="parameter">The object containing the input parameter value.</param>
public void SetObject(DbCommand command, int parameterIndex, Object parameter)
{
if (command.Parameters.Count < parameterIndex)
command.Parameters.Add(command.CreateParameter());
command.Parameters[parameterIndex - 1].Value = parameter;
}

/// <summary>
/// This method is for such prepared statements verify if the Conection is autoCommit for assing the transaction to the command.
/// </summary>
/// <param name="command">The command to be tested.</param>
/// <returns>The number of rows afected.</returns>
public int ExecuteUpdate(DbCommand command)
{
if (!(((ConnectionProperties) this[command.Connection]).AutoCommit))
{
command.Transaction = ((ConnectionProperties) this[command.Connection]).Transaction;
return command.ExecuteNonQuery();
}
else
return command.ExecuteNonQuery();
}

/// <summary>
/// This method Closes the connection, and if the property of autocommit is true make the comit operation
/// </summary>
/// <param name="command"> The command to be closed</param>
public void Close(OdbcConnection Connection)
{
if ((this[Connection] != null) && !(((ConnectionProperties) this[Connection]).AutoCommit))
{
Commit(Connection);
}
Connection.Close();
}

private class ConnectionProperties
{
public bool AutoCommit;
public DbTransaction Transaction;
public IsolationLevel TransactionLevel;
}
}
}

/*******************************/

/// <summary>
Expand Down
Loading

0 comments on commit 4dad32d

Please sign in to comment.