コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: NuGenInitiator.cs プロジェクト: carlhuth/GenXSource
            public virtual void  Run()
            {
                try
                {
                    //get message ID
                    System.String ID          = MessageIDGenerator.Instance.NewID;
                    Message       out_Renamed = parser.parse(outText);
                    Terser        tOut        = new Terser(out_Renamed);
                    tOut.set_Renamed("/MSH-10", ID);

                    //send, get response
                    Message in_Renamed = initiator.sendAndReceive(out_Renamed);

                    //get ACK ID
                    Terser        tIn   = new Terser(in_Renamed);
                    System.String ackID = tIn.get_Renamed("/MSA-2");
                    if (ID.Equals(ackID))
                    {
                        System.Console.Out.WriteLine("OK - ack ID matches");
                    }
                    else
                    {
                        throw new System.SystemException("Ack ID for message " + ID + " is " + ackID);
                    }
                }
                catch (System.Exception e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
コード例 #3
0
ファイル: NuGenResponder.cs プロジェクト: carlhuth/GenXSource
        /// <summary> Processes an incoming message string and returns the response message string.
        /// Message processing consists of parsing the message, finding an appropriate
        /// Application and processing the message with it, and encoding the response.
        /// Applications are chosen from among those registered using
        /// <code>registerApplication</code>.  The Parser is obtained from the Connection
        /// associated with this Responder.
        /// </summary>
        protected internal virtual System.String processMessage(System.String incomingMessageString)
        {
            Message incomingMessageObject = null;

            System.String outgoingMessageString = null;
            try
            {
                incomingMessageObject = parser.parse(incomingMessageString);
            }
            catch (NuGenHL7Exception e)
            {
                outgoingMessageString = logAndMakeErrorMessage(e, parser.getCriticalResponseData(incomingMessageString), parser, parser.getEncoding(incomingMessageString));
            }

            if (outgoingMessageString == null)
            {
                try
                {
                    //optionally check integrity of parse
                    try
                    {
                        if (checkWriter != null)
                        {
                            checkParse(incomingMessageString, incomingMessageObject, parser);
                        }
                    }
                    catch (System.IO.IOException)
                    {
                    }

                    //message validation (in terms of optionality, cardinality) would go here ***

                    NuGenApplication app      = findApplication(incomingMessageObject);
                    Message          response = app.processMessage(incomingMessageObject);

                    //Here we explicitly use the same encoding as that of the inbound message - this is important with GenericParser, which might use a different encoding by default
                    outgoingMessageString = parser.encode(response, parser.getEncoding(incomingMessageString));
                }
                catch (System.Exception e)
                {
                    outgoingMessageString = logAndMakeErrorMessage(e, (Segment)incomingMessageObject.get_Renamed("MSH"), parser, parser.getEncoding(incomingMessageString));
                }
            }

            return(outgoingMessageString);
        }
コード例 #4
0
        /// <summary> Processes an incoming message string and returns the response message string.
        /// Message processing consists of parsing the message, finding an appropriate
        /// Application and processing the message with it, and encoding the response.
        /// Applications are chosen from among those registered using
        /// <code>bindApplication</code>.
        ///
        /// </summary>
        /// <returns> {text, charset}
        /// </returns>
        private System.String[] processMessage(System.String incomingMessageString, System.Collections.IDictionary theMetadata)
        {
            ;

            Message incomingMessageObject = null;

            System.String outgoingMessageString  = null;
            System.String outgoingMessageCharset = null;
            try
            {
                incomingMessageObject = myParser.parse(incomingMessageString);
            }
            catch (NuGenHL7Exception e)
            {
                outgoingMessageString = Responder.logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString));
            }

            if (outgoingMessageString == null)
            {
                try
                {
                    //message validation (in terms of optionality, cardinality) would go here ***

                    NuGenReceivingApplication app = findApplication(incomingMessageObject);
                    theMetadata[RAW_MESSAGE_KEY] = incomingMessageString;
                    Message response = app.processMessage(incomingMessageObject, theMetadata);

                    //Here we explicitly use the same encoding as that of the inbound message - this is important with GenericParser, which might use a different encoding by default
                    outgoingMessageString = myParser.encode(response, myParser.getEncoding(incomingMessageString));

                    Terser t = new Terser(response);
                    outgoingMessageCharset = t.get_Renamed("MSH-18");
                }
                catch (System.Exception e)
                {
                    outgoingMessageString = Responder.logAndMakeErrorMessage(e, (Segment)incomingMessageObject.get_Renamed("MSH"), myParser, myParser.getEncoding(incomingMessageString));
                }
            }

            return(new System.String[] { outgoingMessageString, outgoingMessageCharset });
        }