| | |
| | | |
| | | 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> |
| | |
| | | // 如果消息队列不存在,则创建消息对垒 |
| | | 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) |
| | | { |
| | |
| | | /// </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) |
| | | { |
| | |
| | | /// <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 |
| | |
| | | if (MsgReceived != null) |
| | | { |
| | | MessageID = MsgReceived.Label; |
| | | MsgString = MsgReceived.Body.ToString(); |
| | | alarm = (MQAlarm)MsgReceived.Body; |
| | | } |
| | | } |
| | | catch (Exception ex) |