alielie
2026-03-02 12e606635c42ea20f4b7c2bdda5204237a4b4c96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
 
namespace HMI.Simple.Util
{
    public class AlarmUtil
    {
        private static string ConcatAlarm(string source, string content)
        {
            return $"{source},{content}";
        }
 
        public static bool CreateAlarm(string source, string content, out string msg)
        {
            msg = string.Empty;
            try
            {
                using (var helper = new MSMQHelper("HMI_Alarm"))
                {
                    helper.Send("Alarm", ConcatAlarm(source, content));
                    return true;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
        }
 
        /// <summary>
        /// 创建报警
        /// </summary>
        /// <param name="source">报警来源</param>
        /// <param name="contents">报警内容,同一来源的报警可以多条同时创建</param>
        /// <param name="msg">创建失败时为异常信息</param>
        /// <returns>创建失败时为异常信息</returns>
        public static bool CreateAlarm(string source, string[] contents, out string msg)
        {
            msg = string.Empty;
            try
            {
                using (var helper = new MSMQHelper("HMI_Alarm"))
                {
                    foreach (string content in contents)
                    {
                        helper.Send("Alarm", ConcatAlarm(source, content));
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
        }
 
        public static bool CreateAlarm(string content, out string msg)
        {
            return CreateAlarm("PC", content, out msg);
        }
    }
}