Exemplo n.º 1
0
        /**
         * Checks to see if the given EbXmlMessage is acknowledged asynchronously, and just returns
         * if not. Otherwise, constructs an EbXMLAcknowledgment addressed to the sender of "msg",
         * and calls the ConnectionManager to send it.
         *
         * @param EbXmlMessage to acknowledge
         */
        private void doAsynchronousAck(EbXmlMessage msg)
        {
            if (msg == null)
            {
                return;
            }
            if (!msg.Header.DuplicateElimination)
            {
                return;
            }
            if (msg.Header.SyncReply)
            {
                return;
            }

            StringBuilder                 a          = new StringBuilder(makeEbXmlAck(msg, false));
            ConnectionManager             cm         = ConnectionManager.getInstance();
            SDSconnection                 sds        = cm.SdsConnection;
            string                        ods        = msg.Header.FromPartyKey.Substring(0, msg.Header.FromPartyKey.IndexOf("-"));
            List <SdsTransmissionDetails> sdsdetails = sds.getTransmissionDetails(ACKSERVICE, ods, null, msg.Header.FromPartyKey);

            a.Replace("__CPA_ID__", sdsdetails[0].CPAid);
            EbXmlAcknowledgment ack = new EbXmlAcknowledgment(a.ToString());

            ack.setHost(sdsdetails[0].Url);
            cm.send(ack, sdsdetails[0]);
        }
Exemplo n.º 2
0
        /** Called at start-up if the system needs to load any persisted, reliable messages
         * for sending. This applies the persist duration for the message type to the declared
         * timestamp, and will run the expire() method on anything that has expired whilst
         * the MHS was down.
         */
        public void loadPersistedMessages()
        {
            string[]     files = Directory.GetFiles(messageDirectory);
            EbXmlMessage ebxml = null;

            foreach (String f in files)
            {
                using (FileStream fs = new FileStream(f, FileMode.Open))
                {
                    try
                    {
                        ebxml = new EbXmlMessage(fs);

                        // "f" is now of the form "odscode_messageid" so get the ods code and set it here.
                        string ods = f.Substring(0, f.IndexOf("_")).Substring(f.LastIndexOf("\\") + 1);
                        ebxml.setOdsCode(ods);

                        // Do an SDS lookup and populate retry interval, persist duration
                        // and retry cound in ebxml.

                        List <SdsTransmissionDetails> sdsdetails = sdsConnection.getTransmissionDetails(ebxml.Header.SvcIA, ods, ebxml.HL7Message.ToAsid, ebxml.Header.ToPartyKey);
                        if (sdsdetails.Count == 0)
                        {
                            throw new Exception("Cannot resolve SDS details for persisted message: " + f);
                        }
                        if (sdsdetails.Count > 1)
                        {
                            throw new Exception("Ambiguous SDS details for persisted message: " + f);
                        }

                        SdsTransmissionDetails sds = sdsdetails[0];
                        ebxml.PersistDuration = sds.PersistDuration;
                        ebxml.RetryCount      = sds.Retries;
                        ebxml.RetryInterval   = sds.RetryInterval;
                    }
                    catch (Exception e)
                    {
                        EventLog logger = new EventLog("Application");
                        logger.Source = LOGSOURCE;
                        StringBuilder sbe = new StringBuilder("Failed to load persisted ebXml message ");
                        sbe.Append(f);
                        sbe.Append(" due to exception ");
                        sbe.Append(e.Message);
                        sbe.Append(" at ");
                        sbe.Append(e.StackTrace);
                        logger.WriteEntry(sbe.ToString(), EventLogEntryType.FailureAudit);
                        continue;
                    }
                }
                DateTime check      = DateTime.Now;
                TimeSpan pd         = getPersistDuration(ebxml.Header.SvcIA);
                DateTime expiryTime = ebxml.Started.Add(pd);
                if (expiryTime.CompareTo(check) < 0)
                {
                    depersist(ebxml);
                    ebxml.Expire();
                }
                else
                {
                    requests.Add(ebxml.getMessageId(), ebxml);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ConnectionManager cm = ConnectionManager.getInstance();
            SDSconnection     c  = cm.SdsConnection;

            cm.listen();
            // cm.loadPersistedMessages();

//           List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:pdsquery:QUPA_IN000008UK02", "YES", null, null);
// /            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:pdsquery:QUPA_IN020000UK31", "YEA", "631955299542", null);
//            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:mm:PORX_IN020101UK31", "YEA", "631955299542", null);

            /*          string qstring = null;
             *        using (StreamReader rdr = File.OpenText(@"c:\test\data\query.txt"))
             *        {
             *            qstring = rdr.ReadToEnd();
             *        }
             *        // SpineHL7Message msg = new SpineHL7Message("QUPA_IN020000UK31", qstring);
             *        //SpineHL7Message msg = new SpineHL7Message("PORX_IN020101UK31", qstring);
             *        SpineHL7Message msg = new SpineHL7Message("QUPA_IN000008UK02", qstring);
             *        SpineSOAPRequest req = new SpineSOAPRequest(sdsdetails[0], msg);
             *        msg.ToAsid = sdsdetails[0].Asid[0];
             *        msg.MyAsid = c.MyAsid;
             *        msg.IsQuery = true;
             *        //EbXmlMessage eb = new EbXmlMessage(sdsdetails[0], msg, c);
             *
             *        MemoryStream ms = new MemoryStream();
             *         req.write(ms);
             *        //eb.write(ms);
             *        ms.Seek(0, SeekOrigin.Begin);
             *        StreamReader sr = new StreamReader(ms);
             *        string s = sr.ReadToEnd();
             *
             *        cm.send(req, sdsdetails[0]);
             */
            //cm.listen();
//            while (true) ;

//            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:pdsquery:QUPA_IN000008UK02", "YES", null, null);
//            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:pdsquery:QUPA_IN040000UK32", "YES", null, null);
//            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:mm:PORX_IN132004UK30", "YES", null, null);
            List <SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:psis:REPC_IN150015UK05", "YES", null, null);

//            List<SdsTransmissionDetails> sdsdetails = c.getTransmissionDetails("urn:nhs:names:services:pdsquery:QUPA_IN000006UK02", "YES", null, null);
            int i = sdsdetails.Count;

            cm.listen();
            string qstring = null;

            using (StreamReader rdr = File.OpenText(@"c:\test\data\REPC_IN150015UK05_mhstest.xml"))
            {
                qstring = rdr.ReadToEnd();
            }
            SpineHL7Message msg = new SpineHL7Message("REPC_IN150015UK05", qstring);

            msg.ToAsid     = sdsdetails[0].Asid[0];
            msg.MyAsid     = c.MyAsid;
            msg.AuthorRole = "S0080:G0450:R5080";
            msg.AuthorUid  = "687227875014";
            msg.AuthorUrp  = "012345678901";

            EbXmlMessage eb = new EbXmlMessage(sdsdetails[0], msg);
            //          eb.Attachments.Add(deattachment);
            MemoryStream ms = new MemoryStream();

            eb.write(ms);
            ms.Seek(0, SeekOrigin.Begin);
            StreamReader sr = new StreamReader(ms);
            string       s  = sr.ReadToEnd();

            cm.send(eb, sdsdetails[0]);
        }