Ejemplo n.º 1
0
        /**
         * Removes a reliable request from the retry list. Does nothing if null is passed
         * or if the message id is not known to the retry list.
         *
         * @param a Message id of the request to remove.
         */
        internal void removeRequest(EbXmlMessage a)
        {
            if (a == null)
            {
                return;
            }
            string m = a.getMessageId();

            if (requests.ContainsKey(m))
            {
                requests.Remove(m);
                depersist(a);
            }
        }
Ejemplo n.º 2
0
        /**
         * Assembles an ebXML acknowledgment.
         */
        private string makeEbXmlAck(EbXmlMessage msg, bool replaceCpaId)
        {
            StringBuilder sb = new StringBuilder(ebxmlacktemplate);

            sb.Replace("__FROM_PARTY_ID__", msg.Header.FromPartyKey);
            //sb.Replace("__FROM_PARTY_ID__", msg.Header.ToPartyKey);
            string mp = ConnectionManager.getInstance().SdsConnection.MyPartyKey;

            sb.Replace("__TO_PARTY_ID__", mp);
            sb.Replace("__ORIGINAL_MESSAGE_ID__", msg.getMessageId());
            sb.Replace("__CONVERSATION_ID__", msg.Header.ConversationId);
            if (replaceCpaId)
            {
                sb.Replace("__CPA_ID__", msg.Header.CpaId);
            }
            sb.Replace("__ACK_MESSAGE_ID__", System.Guid.NewGuid().ToString().ToUpper());
            sb.Replace("__ACK_TIMESTAMP__", DateTime.Now.ToString(EbXmlHeader.ISO8601DATEFORMAT));
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        private void depersist(EbXmlMessage a)
        {
            string pfile = messageDirectory + a.getOdsCode() + "_" + a.getMessageId();

            try
            {
                if (File.Exists(pfile))
                {
                    File.Delete(pfile);
                }
            }
            catch (Exception e)
            {
                EventLog logger = new EventLog("Application");
                logger.Source = LOGSOURCE;
                StringBuilder sbe = new StringBuilder("Unexpected error ");
                sbe.Append(e.ToString());
                sbe.Append(" de-persisting message ");
                sbe.Append(pfile);
                logger.WriteEntry(sbe.ToString(), EventLogEntryType.Error);
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
 private void depersist(EbXmlMessage a)
 {
     string pfile = messageDirectory + a.getOdsCode() + "_" + a.getMessageId();
     try
     {
         if (File.Exists(pfile))
             File.Delete(pfile);
     }
     catch (Exception e)
     {
         EventLog logger = new EventLog("Application");
         logger.Source = LOGSOURCE;
         StringBuilder sbe = new StringBuilder("Unexpected error ");
         sbe.Append(e.ToString());
         sbe.Append(" de-persisting message ");
         sbe.Append(pfile);
         logger.WriteEntry(sbe.ToString(), EventLogEntryType.Error);
     }
 }
 /**
  * Removes a reliable request from the retry list. Does nothing if null is passed
  * or if the message id is not known to the retry list.
  *
  * @param a Message id of the request to remove.
  */
 internal void removeRequest(EbXmlMessage a)
 {
     if (a == null)
         return;
     string m = a.getMessageId();
     if (requests.ContainsKey(m))
     {
         requests.Remove(m);
         depersist(a);
     }
 }
        /** 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);
                }
            }
        }