alielie
2026-06-04 771a0e7b6b1276087515bbe94de28358cb92963b
SimpleUtil/HMI.Simple.Util/MSMQHelper.cs
@@ -3,6 +3,15 @@
namespace HMI.Simple.Util
{
    public class MQAlarm
    {
        public string Source { get; set; }
        public string Content { get; set; }
        public int Level { get; set; }
    }
    public class MSMQHelper : IDisposable
    {
        /// <summary>
@@ -40,7 +49,7 @@
                    // 如果消息队列不存在,则创建消息对垒
                    this.msgQueue = MessageQueue.Create(this.msmqPath);
                }
                this.msgQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
                this.msgQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(MQAlarm) });
            }
            catch (Exception ex)
            {
@@ -53,11 +62,11 @@
        /// </summary>
        /// <param name="MessageID">消息ID</param>
        /// <param name="MsgString">要发送的字符串</param>
        public void Send(string MessageID, string MsgString)
        public void Send(string MessageID, string source, string MsgString, int level)
        {
            try
            {
                this.msgQueue.Send(MsgString, MessageID);
                this.msgQueue.Send(new MQAlarm { Source = source, Content = MsgString, Level = level }, MessageID);
            }
            catch (Exception ex)
            {
@@ -71,12 +80,12 @@
        /// <param name="TimeOut">超时时间(ms)</param>
        /// <param name="MessageID">消息ID</param>
        /// <param name="MsgString">消息内容</param>
        public void Receive(long TimeOut, out string MessageID, out string MsgString)
        public void Receive(long TimeOut, out string MessageID, out MQAlarm alarm)
        {
            try
            {
                MessageID = string.Empty;
                MsgString = string.Empty;
                alarm = null;
                TimeSpan Time = new TimeSpan(TimeOut);
                Message MsgReceived = null;
                try
@@ -91,7 +100,7 @@
                if (MsgReceived != null)
                {
                    MessageID = MsgReceived.Label;
                    MsgString = MsgReceived.Body.ToString();
                    alarm = (MQAlarm)MsgReceived.Body;
                }
            }
            catch (Exception ex)