From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
HMI.Core/Util/MSMQHelper.cs | 144 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 144 insertions(+), 0 deletions(-)
diff --git a/HMI.Core/Util/MSMQHelper.cs b/HMI.Core/Util/MSMQHelper.cs
new file mode 100644
index 0000000..efa87d5
--- /dev/null
+++ b/HMI.Core/Util/MSMQHelper.cs
@@ -0,0 +1,144 @@
+锘�//-----------------------------------------------------------------------
+// <copyright file="MSMQHelper.cs" company="iPilotWhale">
+// Suzhou Linktron Systems Co.,Ltd . All rights reserved.
+// </copyright>
+// <author>娓╁悜瓒�</author>
+// <description>娑堟伅闃熷垪鎿嶄綔杈呭姪绫�</description>
+//-----------------------------------------------------------------------
+using System;
+using System.Messaging;
+
+namespace HMI.Core.Util
+{
+ /// <summary>
+ /// 娑堟伅闃熷垪鎿嶄綔绫�
+ /// </summary>
+ public class MSMQHelperCCC
+ {
+ /// <summary>
+ /// 娑堟伅闃熷垪鍚嶇О
+ /// </summary>
+ private string msmqName = string.Empty;
+
+ /// <summary>
+ /// 娑堟伅闃熷垪璺緞
+ /// </summary>
+ private string msmqPath = string.Empty;
+
+ /// <summary>
+ /// 瑕佹搷浣滅殑娑堟伅闃熷垪
+ /// </summary>
+ private MessageQueue msgQueue = null;
+
+ /// <summary>
+ /// 鏋勯�犲嚱鏁�
+ /// </summary>
+ /// <param name="Name">娑堟伅闃熷垪鍚嶇О</param>
+ public MSMQHelperCCC(string Name)
+ {
+ try
+ {
+ this.msmqName = Name;
+ this.msmqPath = ".\\private$\\" + this.msmqName;
+ if (MessageQueue.Exists(this.msmqPath))
+ {
+ // 濡傛灉褰撳墠娑堟伅闃熷垪宸茬粡瀛樺湪
+ this.msgQueue = new MessageQueue(this.msmqPath);
+ }
+ else
+ {
+ // 濡傛灉娑堟伅闃熷垪涓嶅瓨鍦紝鍒欏垱寤烘秷鎭鍨�
+ this.msgQueue = MessageQueue.Create(this.msmqPath);
+ }
+ this.msgQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
+ }
+ catch(Exception ex)
+ {
+ throw new Exception(ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 鍙戦�佹秷鎭�
+ /// </summary>
+ /// <param name="MessageID">娑堟伅ID</param>
+ /// <param name="MsgString">瑕佸彂閫佺殑瀛楃涓�</param>
+ public void Send(string MessageID,string MsgString)
+ {
+ try
+ {
+ this.msgQueue.Send(MsgString, MessageID);
+ }
+ catch(Exception ex)
+ {
+ throw new Exception(ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 鎺ユ敹娑堟伅闃熷垪涓殑娑堟伅
+ /// </summary>
+ /// <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)
+ {
+ try
+ {
+ MessageID = string.Empty;
+ MsgString = string.Empty;
+ TimeSpan Time = new TimeSpan(TimeOut);
+ Message MsgReceived = null;
+ try
+ {
+ MsgReceived = this.msgQueue.Receive(Time);
+ }
+ catch
+ {
+ // do nothing
+ }
+
+ if(MsgReceived!=null)
+ {
+ MessageID = MsgReceived.Label;
+ MsgString = MsgReceived.Body.ToString();
+ }
+ }
+ catch(Exception ex)
+ {
+ throw new Exception("鎺ユ敹娑堟伅澶辫触:" + ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 娓呴櫎娑堟伅闃熷垪涓殑娑堟伅
+ /// </summary>
+ public void Clear()
+ {
+ try
+ {
+ this.msgQueue.Purge();
+ }
+ catch(Exception ex)
+ {
+ throw new Exception("娓呴櫎娑堟伅闃熷垪澶辫触:" + ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 鍏抽棴褰撳墠闃熷垪
+ /// </summary>
+ public void Close()
+ {
+ this.msgQueue.Close();
+ }
+
+ /// <summary>
+ /// 鍒犻櫎褰撳墠闃熷垪
+ /// </summary>
+ public void Delete()
+ {
+ MessageQueue.Delete(this.msmqPath);
+ }
+ }
+}
--
Gitblit v1.9.1