Skip to content

Commit

Permalink
Adding HL7Fuse to Github
Browse files Browse the repository at this point in the history
This version (0.9) is almost out of beta
  • Loading branch information
dib0 committed Nov 19, 2014
1 parent 7d3bc19 commit ac5b91f
Show file tree
Hide file tree
Showing 82 changed files with 368,856 additions and 0 deletions.
116 changes: 116 additions & 0 deletions HL7Fuse.Hub/Configuration/EndPointConfigurationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Xml;
using HL7Fuse.Hub.EndPoints;
using System.Reflection;

namespace HL7Fuse.Hub.Configuration
{
class EndPointConfigurationHandler : IConfigurationSectionHandler
{
#region Public methods
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
Dictionary<string, IEndPoint> result = new Dictionary<string, IEndPoint>();

foreach (XmlNode node in section.ChildNodes)
{
if (node.Name != "#comment")
{
switch (node.Name)
{
case "MLLPClientEndPoint":
result.Add(node.Attributes["name"].Value, GetMLLPClientEndPoint(node));
break;
case "FileEndpoint":
result.Add(node.Attributes["name"].Value, GetFileEndPoint(node));
break;
case "HttpEndPoint":
result.Add(node.Attributes["name"].Value, GetHttpEndPoint(node));
break;
case "SSLEndPoint":
result.Add(node.Attributes["name"].Value, GetSSLEndPoint(node));
break;
case "CustomEndPoint":
result.Add(node.Attributes["name"].Value, GetCustomEndPoint(node));
break;
default:
throw new Exception("Invalid endpoint name in Endpoints section.");
}
}
}

return result;
}
#endregion

#region Private methods
private IEndPoint GetMLLPClientEndPoint(XmlNode node)
{
string host = node.Attributes["host"].Value;
int port = int.Parse(node.Attributes["port"].Value);
string serverCommunicationName = node.Attributes["serverCommunicationName"].Value;
string serverEnvironment = node.Attributes["serverEnvironment"].Value;

return new MLLPClientEndPoint(host, port, serverCommunicationName, serverEnvironment);
}

private IEndPoint GetFileEndPoint(XmlNode node)
{
string target = node.Attributes["targetDirectory"].Value;

return new FileEndPoint(target);
}

private IEndPoint GetHttpEndPoint(XmlNode node)
{
string host = node.Attributes["serverUri"].Value;
string serverCommunicationName = node.Attributes["serverCommunicationName"].Value;
string serverEnvironment = node.Attributes["serverEnvironment"].Value;
bool ignoreSSLErrors = false;
if (!bool.TryParse(node.Attributes["acceptAllSSlCertificates"].Value, out ignoreSSLErrors))
ignoreSSLErrors = false;

return new HttpEndPoint(host, serverCommunicationName, serverEnvironment, ignoreSSLErrors);
}

private IEndPoint GetSSLEndPoint(XmlNode node)
{
string host = node.Attributes["host"].Value;
int port = int.Parse(node.Attributes["port"].Value);
string serverCommunicationName = node.Attributes["serverCommunicationName"].Value;
string serverEnvironment = node.Attributes["serverEnvironment"].Value;

string pathToCertificate = node.Attributes["clientSideCertificatePath"].Value;
string certPassword = node.Attributes["clientSideCertificatePassword"].Value;

SSLClientEndPoint result = null;
if (string.IsNullOrEmpty(pathToCertificate) && string.IsNullOrEmpty(certPassword))
result = new SSLClientEndPoint(host, port, serverCommunicationName, serverEnvironment);
else
result = new SSLClientEndPoint(host, port, serverCommunicationName, serverEnvironment, pathToCertificate, certPassword);

return result;
}

private IEndPoint GetCustomEndPoint(XmlNode node)
{
string customType = node.Attributes["type"].Value;
string[] cType = customType.Split(',');

if (cType.Count() != 2)
throw new Exception("Invalid type definition for custom end point in the configuration file.");

CustomEndPoint result = (CustomEndPoint) Activator.CreateInstance(cType[1], cType[0]).Unwrap();
// Run the setup
result.Setup(node.ChildNodes);

return result;
}
#endregion
}
}
41 changes: 41 additions & 0 deletions HL7Fuse.Hub/Configuration/HL7RoutingRulesConfigurationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Xml;
using HL7Fuse.Hub.EndPoints;

namespace HL7Fuse.Hub.Configuration
{
class HL7RoutingRulesConfigurationHandler : IConfigurationSectionHandler
{
#region Public methods
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
List<RoutingRuleSet> result = new List<RoutingRuleSet>();

foreach (XmlNode node in section.ChildNodes)
{
if (node.Name.ToLower() == "rule")
{
result.Add(GetRoutingRule(node));
}
}

return result;
}
#endregion

#region Private methods
private RoutingRuleSet GetRoutingRule(XmlNode node)
{
RoutingRuleSet rule = new RoutingRuleSet(node.ChildNodes);
rule.EndPoint = node.Attributes["endpoint"].Value;

return rule;
}
#endregion
}
}
69 changes: 69 additions & 0 deletions HL7Fuse.Hub/Configuration/RoutingRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NHapi.Base.Model;

namespace HL7Fuse.Hub.Configuration
{
class RoutingRule
{
#region Public properties
public string Hl7Version
{
get;
set;
}

public string Structurename
{
get;
set;
}

public bool Include
{
get;
set;
}
#endregion

#region Public methods
public bool Match(IMessage message)
{
bool result = false;

result = Compare(Hl7Version, message.Version);
if (result)
result = Compare(Structurename, message.GetStructureName());

return result;
}
#endregion

#region Private methods
private bool Compare(string pattern, string compareTo)
{
bool result = false;
if (pattern.Contains('*') || pattern.Contains('?'))
result = WildcardStringCompare(pattern, compareTo);
else
result = (pattern == compareTo);

return result;
}

public bool WildcardStringCompare(string pattern, string compareTo)
{
string patt = "^" + Regex.Escape(pattern).
Replace(@"\*", ".*").
Replace(@"\?", ".") + "$";
Regex regex = new Regex(patt);

return regex.IsMatch(compareTo);
}
#endregion
}
}
72 changes: 72 additions & 0 deletions HL7Fuse.Hub/Configuration/RoutingRuleSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using NHapi.Base.Model;

namespace HL7Fuse.Hub.Configuration
{
class RoutingRuleSet
{
#region Private properties
private List<RoutingRule> rules;
#endregion

#region Public properties
public string EndPoint
{
get;
set;
}
#endregion

#region Constructor
public RoutingRuleSet(XmlNodeList childnodes)
{
rules = new List<RoutingRule>();

foreach (XmlNode node in childnodes)
{
RoutingRule rule = new RoutingRule();
rule.Include = (node.Name == "include");
rule.Hl7Version = node.Attributes["hl7Version"].Value;
rule.Structurename = node.Attributes["structurename"].Value;
rules.Add(rule);

}
}
#endregion

#region Public methods
public bool IncludeEndpoint(IMessage message)
{
bool result = true;

// Run include rules
List<RoutingRule> incRules = rules.Where(r => r.Include).ToList();
foreach (RoutingRule rule in incRules)
{
// If any include rules match, this endpoint is applicable
if (rule.Match(message))
result = true;
}

if (result)
{
// Run exclude rules
List<RoutingRule> exclRules = rules.Where(r => !r.Include).ToList();
foreach (RoutingRule rule in exclRules)
{
// If any exclude rules match, this endpoint is not applicable
if (rule.Match(message))
result = false;
}
}

return result;
}
#endregion
}
}
Loading

0 comments on commit ac5b91f

Please sign in to comment.