Exemple #1
0
 public override bool SendMessage(HYS.IM.Messaging.Objects.Message message)
 {
     //if (_subscriber != null)
     if (_receiver != null)
     {
         bool   result;
         string id = message.Header.ID.ToString();
         _log.Write("LPCNotifier start sending a message to subscriber. Subscriber ID: " + _parameter.ReceiverEntityID + " Message ID=" + id);
         try
         {
             //_subscriber.ReceiveMessage(Channel, message);
             _receiver.ReceiveMessage(message);
             result = true;
         }
         catch (LPCException err)
         {
             _log.Write(err);
             result = false;
         }
         _log.Write("LPCNotifier finish sending a message to subscriber. Subscriber ID: " + _parameter.ReceiverEntityID + " Message ID=" + id);
         return(result);
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
        public bool ProcessSubscribedMessage(IPushRoute route, MSG.Message msg)
        {
            if (msg == null || msg.Header == null)
            {
                return(false);
            }
            string msgId = msg.Header.ID.ToString();

            bool res = false;

            _entity.Context.Log.Write(string.Format("Begin processing message. ID: {0}", msgId));

            MSG.Message csbMsg = TransformToCSBDataSetSchemedXDSGWMessage(msg, msgId);
            if (csbMsg != null)
            {
                DataSet ds = GenerateCSBrokerDataSet(csbMsg.Body);
                if (ds != null)
                {
                    res = InsertIntoCSBrokerDatabase(route, ds);
                }
            }

            if (!res)
            {
                DumpErrorMessage(msg, msgId);
            }
            _entity.Context.Log.Write(string.Format("Finish processing message. ID: {0}, Result: {1}.\r\n", msgId, res));
            return(res);
        }
Exemple #3
0
        private MSG.Message TransformToCSBDataSetSchemedXDSGWMessage(MSG.Message msg, string msgID)
        {
            if (!_entity.Context.ConfigMgr.Config.EnableXMLTransform)
            {
                return(msg);
            }

            _entity.Context.Log.Write("Begin transforming XDSGW message.");
            string         file = ConfigHelper.GetFullPath(_entity.Context.AppArgument.ConfigFilePath, _entity.Context.ConfigMgr.Config.XSLTFilePath);
            XMLTransformer t    = XMLTransformer.CreateFromFileWithCache(file, _entity.Context.Log);

            if (t == null)
            {
                return(null);
            }

            string csbMsgXml   = "";
            string otherMsgXml = msg.ToXMLString();

            if (!t.TransformString(otherMsgXml, ref csbMsgXml, XSLTExtensionTypes.None))
            {
                return(null);
            }

            MSG.Message csbMsg = XObjectManager.CreateObject <MSG.Message>(csbMsgXml);
            if (csbMsg == null)
            {
                _entity.Context.Log.Write(LogType.Error, "Cannot deserialize the transformed XML into XDSGW message.");
                string fname = string.Format("{0}_transformed", msgID);
                DumpErrorMessage(csbMsgXml, fname);
            }

            _entity.Context.Log.Write("Finish transforming XDSGW message.");
            return(csbMsg);
        }
Exemple #4
0
        private bool WriteHL7v2XmlLMessage(HYS.IM.Messaging.Objects.Message msg)
        {
            try
            {
                string hl7Msg = string.Empty;
                if (_transformer.TransformXmlToHL7v2(msg.Body, out hl7Msg))
                {
                    _context.Log.Write("Transform xml to hl7 v2 text success.");
                }
                else
                {
                    _context.Log.Write("Transform xml to hl7 v2 text failure.");
                    return(false);
                }

                string relativePath = PathHelper.GetRelativePathByMode(_context.ConfigMgr.Config.OrganizationMode);
                string filePath     = _context.ConfigMgr.Config.OutputFileFolder;
                if (!string.IsNullOrEmpty(relativePath))
                {
                    filePath = Path.Combine(filePath, relativePath);
                }
                filePath = Path.Combine(filePath, msg.Header.ID.ToString() + _context.ConfigMgr.Config.FileExtension);

                FileHelper.WriteFile(filePath, hl7Msg, _context.ConfigMgr.Config.CodePageName);
                _context.Log.Write(string.Format("Write message to file {0} success.", filePath));
                return(true);
            }
            catch (Exception err)
            {
                _context.Log.Write(err);
                return(false);
            }
        }
Exemple #5
0
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            string xml = _ctrlCSBMsg.GetXmlString();

            if (string.IsNullOrEmpty(xml))
            {
                return;
            }

            MSG.Message msg = XObjectManager.CreateObject <MSG.Message>(xml);
            if (msg == null)
            {
                MessageBox.Show(this, "Deserialize CSB DataSet Message failed. See the log file for details.", this.Text);
                return;
            }

            try
            {
                DataSet     ds = new DataSet();
                XmlReadMode m  = ds.ReadXml(XmlReader.Create(new StringReader(msg.Body)));
                this.dataGridViewDS.DataSource = ds.Tables[0];
            }
            catch (Exception err)
            {
                Program.Context.Log.Write(err);
                MessageBox.Show(this, "Deserialize DataSet XML failed. See the log file for details.\r\n\r\nMessage: " + err.Message, this.Text);
            }
        }
Exemple #6
0
        internal void AddMessageToTheList(MSG.Message msg)
        {
            AddMessageToTheListHandler dlg = delegate(MSG.Message m)
            {
                this.listBoxMsg.Items.Add(m);
            };

            this.listBoxMsg.Invoke(dlg, msg);
        }
Exemple #7
0
        private void buttonReceive_Click(object sender, EventArgs e)
        {
            MSG.Message notify = new MSG.Message();
            //notify.Header.Type = MessageRegistry.HL7V2_NotificationMessageType;
            notify.Header.Type = MessageRegistry.GENERIC_NotificationMessageType;
            notify.Body        = this.textBoxMessageContent.Text;

            _controler.ProcessSubscribedMessage(notify);
        }
Exemple #8
0
        public static string GetMessageLabel(HYS.IM.Messaging.Objects.Message message)
        {
            if (message == null)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(message.Header.Type.ToString()).Append(" ").Append(message.Header.ID);
            return(sb.ToString());
        }
Exemple #9
0
        private bool WriteHL7v2TextMessage(HYS.IM.Messaging.Objects.Message msg)
        {
            try
            {
                string payload  = HL7MessageHelper.GetHL7V2PayLoad(msg);
                string filePath = Path.Combine(_context.ConfigMgr.Config.OutputFileFolder, PathHelper.GetRelativePathByMode(_context.ConfigMgr.Config.OrganizationMode));
                filePath = Path.Combine(filePath, msg.Header.ID.ToString() + _context.ConfigMgr.Config.FileExtension);

                FileHelper.WriteFile(filePath, payload, _context.ConfigMgr.Config.CodePageName);
                _context.Log.Write(string.Format("Write message to file {0}", filePath));
                return(true);
            }
            catch (Exception err)
            {
                _context.Log.Write(err);
                return(false);
            }
        }
Exemple #10
0
        private bool WriteOtherXmlMessage(HYS.IM.Messaging.Objects.Message msg)
        {
            try
            {
                StringBuilder xmlContent = new StringBuilder();
                xmlContent.AppendLine(string.Format(XmlHelper.XML_DELARATION_FORMAT, _context.ConfigMgr.Config.CodePageName))
                .Append(msg.Body);

                string filePath = Path.Combine(_context.ConfigMgr.Config.OutputFileFolder, PathHelper.GetRelativePathByMode(_context.ConfigMgr.Config.OrganizationMode));
                filePath = Path.Combine(filePath, msg.Header.ID.ToString() + _context.ConfigMgr.Config.FileExtension);

                FileHelper.WriteFile(filePath, xmlContent.ToString(), _context.ConfigMgr.Config.CodePageName);
                _context.Log.Write(string.Format("Write message to file {0} success.", filePath));
                return(true);
            }
            catch (Exception err)
            {
                _context.Log.Write(err);
                return(false);
            }
        }
Exemple #11
0
        public override bool SendMessage(HYS.IM.Messaging.Objects.Message message)
        {
            if (message == null || message.Header == null)
            {
                _log.Write(LogType.Error, "MSMQSender cannot send NULL message or message without header.");
                return(false);
            }

            string msgIDInfo = "MSMQSender send message id=" + message.Header.ID.ToString();

            _log.Write(LogType.Debug, msgIDInfo + " serializing.");
            string xmlString = message.ToXMLString();

            lock (queue)    // 20130204 Send() is not thread safe according to msdn.
            {
                using (MessageQueueTransaction trans = new MessageQueueTransaction())
                {
                    try
                    {
                        _log.Write(LogType.Debug, msgIDInfo + " begin.");

                        trans.Begin();
                        queue.Send(xmlString, MSMQHelper.GetMessageLabel(message), trans);
                        trans.Commit();

                        _log.Write(LogType.Debug, msgIDInfo + " end.");
                        return(true);
                    }
                    catch (Exception err)
                    {
                        trans.Abort();
                        //throw err;
                        _log.Write(LogType.Error, "MSMQSender send message failed.");
                        _log.Write(err);
                        return(false);
                    }
                }
            }
        }
Exemple #12
0
        public bool ProcessSubscribedMessage(MSG.Message msg)
        {
            if (msg == null || msg.Header == null)
            {
                return(false);
            }
            string msgId = msg.Header.ID.ToString();

            bool res = false;

            _context.Log.Write(string.Format("Begin processing message. ID: {0}", msgId));

            if (_context.ConfigMgr.Config.MessageProcessingType == MessageProcessType.HL7v2Text)
            {
                res = WriteHL7v2TextMessage(msg);
            }
            else if (_context.ConfigMgr.Config.MessageProcessingType == MessageProcessType.HL7v2XML)
            {
                res = WriteHL7v2XmlLMessage(msg);
            }
            else if (_context.ConfigMgr.Config.MessageProcessingType == MessageProcessType.OtherXML)
            {
                res = WriteOtherXmlMessage(msg);
            }
            else
            {
                _context.Log.Write(LogType.Error, "Message process type config error.");
            }

            if (!res)
            {
                DumpErrorMessage(msg, msgId);
            }
            _context.Log.Write(string.Format("Finish processing message. ID: {0}, Result: {1}.\r\n", msgId, res));
            return(res);
        }
Exemple #13
0
 private void listBoxMsg_DoubleClick(object sender, EventArgs e)
 {
     MSG.Message msg = this.listBoxMsg.SelectedItem as MSG.Message;
     MessageBox.Show(msg.ToXMLString());
 }
Exemple #14
0
 bool publisher_OnMessagePublish(HYS.IM.Messaging.Objects.Message message)
 {
     AddMessageToTheList(message);
     return(true);
 }
Exemple #15
0
 private void DumpErrorMessage(MSG.Message msg, string msgID)
 {
     DumpErrorMessage(msg.ToXMLString(), msgID);
 }
Exemple #16
0
 public bool NotifyMessagePublish(MSG.Message message)
 {
     _frm.AddMessageToTheList(message);
     return(true);
 }