alielie
2026-06-04 771a0e7b6b1276087515bbe94de28358cb92963b
SimpleUtil/HMI.Simple.Util/AlarmUtil.cs
@@ -4,19 +4,15 @@
{
    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)
        public static bool CreateAlarm(string source, string content, int level, out string msg)
        {
            msg = string.Empty;
            try
            {
                using (var helper = new MSMQHelper("HMI_Alarm"))
                {
                    helper.Send("Alarm", ConcatAlarm(source, content));
                    helper.Send("Alarm", source, content, level);
                    return true;
                }
            }
@@ -34,16 +30,16 @@
        /// <param name="contents">报警内容,同一来源的报警可以多条同时创建</param>
        /// <param name="msg">创建失败时为异常信息</param>
        /// <returns>创建失败时为异常信息</returns>
        public static bool CreateAlarm(string source, string[] contents, out string msg)
        public static bool CreateAlarm(string source, string[] contents, int[] levels, out string msg)
        {
            msg = string.Empty;
            try
            {
                using (var helper = new MSMQHelper("HMI_Alarm"))
                {
                    foreach (string content in contents)
                    for (int i = 0; i < contents.Length; i++)
                    {
                        helper.Send("Alarm", ConcatAlarm(source, content));
                        helper.Send("Alarm", source, contents[i], levels[i]);
                    }
                    return true;
                }
@@ -54,10 +50,13 @@
                return false;
            }
        }
        public static bool CreateAlarm(string content, out string msg)
        {
            return CreateAlarm("PC", content, out msg);
        }
        //private static string ConcatAlarm(string source, string content)
        //{
        //    return $"{source},{content}";
        //}
        //public static bool CreateAlarm(string content, int level, out string msg)
        //{
        //    return CreateAlarm("PC", content, level, out msg);
        //}
    }
}