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; } } /// /// 创建报警 /// /// 报警来源 /// 报警内容,同一来源的报警可以多条同时创建 /// 创建失败时为异常信息 /// 创建失败时为异常信息 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); } } }