/// <summary> Returns a Connection to the given address, opening this /// Connection if necessary. The given Parser will only be used if a new Connection /// is opened, so there is no guarantee that the Connection returnd will be using the /// Parser you provide. If you need explicit access to the Parser the Connection /// is using, call <code>Connection.getParser()</code>. /// </summary> public virtual NuGenConnection attach(System.String host, int port, Parser parser, System.Type llpClass) { NuGenConnection conn = getExisting(host, port, parser.GetType(), llpClass); if (conn == null) { try { //Parser p = (Parser) parserClass.newInstance(); LowerLayerProtocol llp = (LowerLayerProtocol) System.Activator.CreateInstance(llpClass); conn = connect(host, port, parser, llp); } catch (System.InvalidCastException e) { //Log.tryToLog(, "Problem opening new connection to " + host + " port " + port); throw new NuGenHL7Exception("ClassCastException - need a LowerLayerProtocol class to get an Inititator", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e); } catch (System.Exception e) { //Log.tryToLog(e, "Problem opening new connection to " + host + " port " + port); throw new NuGenHL7Exception("Can't connect to " + host + " port " + port + ": " + e.GetType().FullName + ": " + e.Message, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e); } } incrementRefs(conn); return conn; }
/// <summary> Creates an instance that uses the given <code>Parser</code></summary> /// <param name="theParser">parser to use for parsing and encoding messages /// </param> /// <param name="theProcessor">the <code>Processor</code> used to communicate /// with the remote system /// </param> public NuGenInitiatorImpl(Parser theParser, NuGenProcessor theProcessor) { myMetadataFields = new System.Collections.ArrayList(20); myParser = theParser; myProcessor = theProcessor; init(); }
/// <seealso cref="Genetibase.NuGenHL7.protocol.Initiator.sendAndReceive(Genetibase.NuGenHL7.model.Message)"> /// </seealso> public virtual Message sendAndReceive(Message theMessage) { Terser t = new Terser(theMessage); System.String appAckNeeded = t.get_Renamed("/MSH-16"); System.String msgId = t.get_Renamed("/MSH-10"); System.String messageText = Parser.encode(theMessage); System.Collections.IDictionary metadata = getMetadata(theMessage); NuGenTransportable out_Renamed = new NuGenTransportableImpl(messageText, metadata); if (needAck(appAckNeeded)) { myProcessor.reserve(msgId, ReceiveTimeout); } myProcessor.send(out_Renamed, MaxRetries, RetryInterval); Message in_Renamed = null; if (needAck(appAckNeeded)) { NuGenTransportable received = myProcessor.receive(msgId, ReceiveTimeout); if (received != null && received.Message != null) { in_Renamed = Parser.parse(received.Message); } } return(in_Renamed); }
/// <summary> Creates an instance that uses a <code>GenericParser</code></summary> /// <param name="theProcessor">the <code>Processor</code> used to communicate /// with the remote system /// </param> public NuGenInitiatorImpl(NuGenProcessor theProcessor) { myMetadataFields = new System.Collections.ArrayList(20); myMetadataFields.Add("MSH-18"); //add character set by default myParser = new GenericParser(); myProcessor = theProcessor; init(); }
/// <summary>Common initialization tasks </summary> private void init(Parser parser) { this.parser = parser; sockets = new System.Collections.ArrayList(); receipts = new System.Collections.Hashtable(); receivers = new System.Collections.ArrayList(); responder = new NuGenResponder(parser); }
/// <summary> Opens a connection to the given address, and stores it in the /// connections Hash. /// </summary> private NuGenConnection connect(System.String host, int port, Parser parser, LowerLayerProtocol llp) { System.Net.Sockets.TcpClient s = new System.Net.Sockets.TcpClient(host, port); NuGenConnection i = new NuGenConnection(parser, llp, s); connections[makeHashKey(host, port, parser.GetType(), llp.GetType())] = i; sockets[makeHashKey(host, port, parser.GetType(), llp.GetType())] = s; return(i); }
/// <summary> Creates a new instance of Connection, with inbound and outbound /// communication on a single port. /// </summary> public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient bidirectional) { init(parser); ackWriter = llp.getWriter(bidirectional.GetStream()); sendWriter = ackWriter; sockets.Add(bidirectional); NuGenReceiver r = new NuGenReceiver(this, llp.getReader(bidirectional.GetStream())); r.start(); receivers.Add(r); this.initiator = new NuGenInitiator(this); }
/// <summary> Performs common constructor tasks.</summary> private void init(Parser parser, bool checkParse) { this.parser = parser; apps = new System.Collections.ArrayList(10); try { if (checkParse) { checkWriter = new System.IO.StreamWriter(new System.IO.StreamWriter(Genetibase.NuGenHL7.util.NuGenHome.getHomeDirectory().FullName + "/parse_check.txt", true, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(Genetibase.NuGenHL7.util.NuGenHome.getHomeDirectory().FullName + "/parse_check.txt", true, System.Text.Encoding.Default).Encoding); } } catch (System.IO.IOException) { } }
/// <summary> Creates a new instance of Connection, with inbound communication on one /// port and outbound on another. /// </summary> public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient inbound, System.Net.Sockets.TcpClient outbound) { init(parser); ackWriter = llp.getWriter(inbound.GetStream()); sendWriter = llp.getWriter(outbound.GetStream()); sockets.Add(outbound); //always add outbound first ... see getRemoteAddress() sockets.Add(inbound); NuGenReceiver inRec = new NuGenReceiver(this, llp.getReader(inbound.GetStream())); NuGenReceiver outRec = new NuGenReceiver(this, llp.getReader(outbound.GetStream())); inRec.start(); outRec.start(); receivers.Add(inRec); receivers.Add(outRec); this.initiator = new NuGenInitiator(this); }
/// <summary> Encodes the given message and compares it to the given string. Any differences /// are noted in the file [hapi.home]/parse_check.txt. Ignores extra field delimiters. /// </summary> public static void checkParse(System.String originalMessageText, Message parsedMessage, Parser parser) { System.String newMessageText = parser.encode(parsedMessage); if (!originalMessageText.Equals(newMessageText)) { //check each segment SupportClass.Tokenizer tok = new SupportClass.Tokenizer(originalMessageText, "\r"); System.Collections.ArrayList one = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) one.Add(seg); } tok = new SupportClass.Tokenizer(newMessageText, "\r"); System.Collections.ArrayList two = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) two.Add(stripExtraDelimiters(seg, seg[3])); } if (one.Count != two.Count) { } else { //check each segment for (int i = 0; i < one.Count; i++) { System.String origSeg = (System.String) one[i]; System.String newSeg = (System.String) two[i]; if (!origSeg.Equals(newSeg)) { } } } } else { } }
/// <summary> Returns the path to the base package for model elements of the given version /// - e.g. "ca/uhn/hl7v2/model/v24/". /// This package should have the packages datatype, segment, group, and message /// under it. The path ends in with a slash. /// </summary> public static System.String getVersionPackagePath(System.String ver) { if (Parser.validVersion(ver) == false) { throw new NuGenHL7Exception("The HL7 version " + ver + " is not recognized", NuGenHL7Exception.UNSUPPORTED_VERSION_ID); } System.Text.StringBuilder path = new System.Text.StringBuilder("Genetibase/NuGenHL7/model/v"); char[] versionChars = new char[ver.Length]; SupportClass.GetCharsFromString(ver, 0, ver.Length, versionChars, 0); for (int i = 0; i < versionChars.Length; i++) { if (versionChars[i] != '.') { path.Append(versionChars[i]); } } path.Append('/'); return(path.ToString()); }
/// <summary> Encodes the given message and compares it to the given string. Any differences /// are noted in the file [hapi.home]/parse_check.txt. Ignores extra field delimiters. /// </summary> private void checkParse(System.String originalMessageText, Message parsedMessage, Parser parser) { System.String newMessageText = parser.encode(parsedMessage); checkWriter.Write("******************* Comparing Messages ****************\r\n"); checkWriter.Write("Original: " + originalMessageText + "\r\n"); checkWriter.Write("Parsed and Encoded: " + newMessageText + "\r\n"); if (!originalMessageText.Equals(newMessageText)) { //check each segment SupportClass.Tokenizer tok = new SupportClass.Tokenizer(originalMessageText, "\r"); System.Collections.ArrayList one = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) { one.Add(seg); } } tok = new SupportClass.Tokenizer(newMessageText, "\r"); System.Collections.ArrayList two = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) { two.Add(stripExtraDelimiters(seg, seg[3])); } } if (one.Count != two.Count) { checkWriter.Write("Warning: inbound and parsed messages have different numbers of segments: \r\n"); checkWriter.Write("Original: " + originalMessageText + "\r\n"); checkWriter.Write("Parsed: " + newMessageText + "\r\n"); } else { //check each segment for (int i = 0; i < one.Count; i++) { System.String origSeg = (System.String)one[i]; System.String newSeg = (System.String)two[i]; if (!origSeg.Equals(newSeg)) { checkWriter.Write("Warning: inbound and parsed message segment differs: \r\n"); checkWriter.Write("Original: " + origSeg + "\r\n"); checkWriter.Write("Parsed: " + newSeg + "\r\n"); } } } } else { checkWriter.Write("No differences found\r\n"); } checkWriter.Write("******************** End Comparison ******************\r\n"); checkWriter.Flush(); }
/// <summary> Opens a connection to the given address, and stores it in the /// connections Hash. /// </summary> private NuGenConnection connect(System.String host, int port, Parser parser, LowerLayerProtocol llp) { System.Net.Sockets.TcpClient s = new System.Net.Sockets.TcpClient(host, port); NuGenConnection i = new NuGenConnection(parser, llp, s); connections[makeHashKey(host, port, parser.GetType(), llp.GetType())] = i; sockets[makeHashKey(host, port, parser.GetType(), llp.GetType())] = s; return i; }
/// <summary> Creates a new instance of Responder that optionally validates parsing of incoming /// messages using a system property. If the system property /// <code>Genetibase.NuGenHL7.app.checkparse</code> equals "true", parse integrity is checked, /// i.e. each message is re-encoded and differences between the received message text /// and the re-encoded text are written to the file <hapi.home>/parse_check.txt. /// </summary> public NuGenResponder(Parser parser) { init(parser, false); }
/// <summary> Creates a new instance of Responder that optionally validates parsing of incoming messages.</summary> /// <param name="validate">if true, encodes each incoming message after parsing it, compares /// the result to the original message string, and prints differences to the file /// "<hapi.home>/parse_check.txt" in the working directory. This process is slow and should /// only be used during testing. /// </param> public NuGenResponder(Parser parser, bool checkParse) { init(parser, checkParse); }
/// <summary> Creates an instance that uses the specified <code>Parser</code>. </summary> /// <param name="theParser">the parser used for converting between Message and /// Transportable /// </param> public NuGenApplicationRouterImpl(Parser theParser) { init(theParser); }
/// <summary> Logs the given exception and creates an error message to send to the /// remote system. /// /// </summary> /// <param name="encoding">The encoding for the error message. If <code>null</code>, uses default encoding /// </param> public static System.String logAndMakeErrorMessage(System.Exception e, Segment inHeader, Parser p, System.String encoding) { // create error message ... System.String errorMessage = null; try { Message out_Renamed = NuGenDefaultApplication.makeACK(inHeader); Terser t = new Terser(out_Renamed); //copy required data from incoming message ... try { t.set_Renamed("/MSH-10", MessageIDGenerator.Instance.NewID); } catch (System.IO.IOException ioe) { throw new NuGenHL7Exception("Problem creating error message ID: " + ioe.Message); } //populate MSA ... t.set_Renamed("/MSA-1", "AE"); //should this come from HL7Exception constructor? t.set_Renamed("/MSA-2", Terser.get_Renamed(inHeader, 10, 0, 1, 1)); System.String excepMessage = e.Message; if (excepMessage != null) t.set_Renamed("/MSA-3", excepMessage.Substring(0, (System.Math.Min(80, excepMessage.Length)) - (0))); /* Some earlier ACKs don't have ERRs, but I think we'll change this within HAPI so that there is a single ACK for each version (with an ERR). */ //see if it's an HL7Exception (so we can get specific information) ... if (e.GetType().Equals(typeof(NuGenHL7Exception))) { Segment err = (Segment) out_Renamed.get_Renamed("ERR"); ((NuGenHL7Exception) e).populate(err); } else { t.set_Renamed("/ERR-1-4-1", "207"); t.set_Renamed("/ERR-1-4-2", "Application Internal Error"); t.set_Renamed("/ERR-1-4-3", "HL70357"); } if (encoding != null) { errorMessage = p.encode(out_Renamed, encoding); } else { errorMessage = p.encode(out_Renamed); } } catch (System.IO.IOException ioe) { throw new NuGenHL7Exception("IOException creating error response message: " + ioe.Message, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR); } return errorMessage; }
/// <summary> Logs the given exception and creates an error message to send to the /// remote system. /// /// </summary> /// <param name="encoding">The encoding for the error message. If <code>null</code>, uses default encoding /// </param> public static System.String logAndMakeErrorMessage(System.Exception e, Segment inHeader, Parser p, System.String encoding) { // create error message ... System.String errorMessage = null; try { Message out_Renamed = NuGenDefaultApplication.makeACK(inHeader); Terser t = new Terser(out_Renamed); //copy required data from incoming message ... try { t.set_Renamed("/MSH-10", MessageIDGenerator.Instance.NewID); } catch (System.IO.IOException ioe) { throw new NuGenHL7Exception("Problem creating error message ID: " + ioe.Message); } //populate MSA ... t.set_Renamed("/MSA-1", "AE"); //should this come from HL7Exception constructor? t.set_Renamed("/MSA-2", Terser.get_Renamed(inHeader, 10, 0, 1, 1)); System.String excepMessage = e.Message; if (excepMessage != null) { t.set_Renamed("/MSA-3", excepMessage.Substring(0, (System.Math.Min(80, excepMessage.Length)) - (0))); } /* Some earlier ACKs don't have ERRs, but I think we'll change this within HAPI * so that there is a single ACK for each version (with an ERR). */ //see if it's an HL7Exception (so we can get specific information) ... if (e.GetType().Equals(typeof(NuGenHL7Exception))) { Segment err = (Segment)out_Renamed.get_Renamed("ERR"); ((NuGenHL7Exception)e).populate(err); } else { t.set_Renamed("/ERR-1-4-1", "207"); t.set_Renamed("/ERR-1-4-2", "Application Internal Error"); t.set_Renamed("/ERR-1-4-3", "HL70357"); } if (encoding != null) { errorMessage = p.encode(out_Renamed, encoding); } else { errorMessage = p.encode(out_Renamed); } } catch (System.IO.IOException ioe) { throw new NuGenHL7Exception("IOException creating error response message: " + ioe.Message, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR); } return(errorMessage); }
private void init(Parser theParser) { myBindings = new System.Collections.ArrayList(20); myParser = theParser; }
private void InitBlock(Genetibase.NuGenHL7.parser.NuGenParser parser, System.String outText, Genetibase.NuGenHL7.app.NuGenInitiator initiator) { this.parser = parser; this.outText = outText; this.initiator = initiator; }
/// <summary> Creates a new instance of SimpleServer that listens /// </summary> public NuGenSimpleServer(int port, LowerLayerProtocol llp, Parser parser):base(parser, llp) { this.port = port; }
/// <summary> Encodes the given message and compares it to the given string. Any differences /// are noted in the file [hapi.home]/parse_check.txt. Ignores extra field delimiters. /// </summary> private void checkParse(System.String originalMessageText, Message parsedMessage, Parser parser) { System.String newMessageText = parser.encode(parsedMessage); checkWriter.Write("******************* Comparing Messages ****************\r\n"); checkWriter.Write("Original: " + originalMessageText + "\r\n"); checkWriter.Write("Parsed and Encoded: " + newMessageText + "\r\n"); if (!originalMessageText.Equals(newMessageText)) { //check each segment SupportClass.Tokenizer tok = new SupportClass.Tokenizer(originalMessageText, "\r"); System.Collections.ArrayList one = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) one.Add(seg); } tok = new SupportClass.Tokenizer(newMessageText, "\r"); System.Collections.ArrayList two = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) two.Add(stripExtraDelimiters(seg, seg[3])); } if (one.Count != two.Count) { checkWriter.Write("Warning: inbound and parsed messages have different numbers of segments: \r\n"); checkWriter.Write("Original: " + originalMessageText + "\r\n"); checkWriter.Write("Parsed: " + newMessageText + "\r\n"); } else { //check each segment for (int i = 0; i < one.Count; i++) { System.String origSeg = (System.String) one[i]; System.String newSeg = (System.String) two[i]; if (!origSeg.Equals(newSeg)) { checkWriter.Write("Warning: inbound and parsed message segment differs: \r\n"); checkWriter.Write("Original: " + origSeg + "\r\n"); checkWriter.Write("Parsed: " + newSeg + "\r\n"); } } } } else { checkWriter.Write("No differences found\r\n"); } checkWriter.Write("******************** End Comparison ******************\r\n"); checkWriter.Flush(); }
/// <summary> Creates a new instance of SimpleServer that listens /// </summary> public NuGenSimpleServer(int port, LowerLayerProtocol llp, Parser parser) : base(parser, llp) { this.port = port; }
/// <summary> Encodes the given message and compares it to the given string. Any differences /// are noted in the file [hapi.home]/parse_check.txt. Ignores extra field delimiters. /// </summary> public static void checkParse(System.String originalMessageText, Message parsedMessage, Parser parser) { System.String newMessageText = parser.encode(parsedMessage); if (!originalMessageText.Equals(newMessageText)) { //check each segment SupportClass.Tokenizer tok = new SupportClass.Tokenizer(originalMessageText, "\r"); System.Collections.ArrayList one = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) { one.Add(seg); } } tok = new SupportClass.Tokenizer(newMessageText, "\r"); System.Collections.ArrayList two = new System.Collections.ArrayList(); while (tok.HasMoreTokens()) { System.String seg = tok.NextToken(); if (seg.Length > 4) { two.Add(stripExtraDelimiters(seg, seg[3])); } } if (one.Count != two.Count) { } else { //check each segment for (int i = 0; i < one.Count; i++) { System.String origSeg = (System.String)one[i]; System.String newSeg = (System.String)two[i]; if (!origSeg.Equals(newSeg)) { } } } } else { } }
public AnonymousClassRunnable(Genetibase.NuGenHL7.parser.NuGenParser parser, System.String outText, Genetibase.NuGenHL7.app.NuGenInitiator initiator) { InitBlock(parser, outText, initiator); }