AlarmDefineService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Xml;
  11. namespace MECF.Framework.Common.Alarms
  12. {
  13. class AlarmDefineService : IAlarmDefineService
  14. {
  15. public Dictionary<string, Dictionary<string, EventItem>> GetAlarmDefineTemplate()
  16. {
  17. Dictionary<string, Dictionary<string, EventItem>> result = new Dictionary<string, Dictionary<string, EventItem>>();
  18. foreach (var key in Singleton<EventManager>.Instance.AlarmDic.Keys)
  19. {
  20. Dictionary<string, EventItem> temp = new Dictionary<string, EventItem>();
  21. foreach (var name in Singleton<EventManager>.Instance.AlarmDic[key].Keys)
  22. {
  23. var item = Singleton<EventManager>.Instance.AlarmDic[key][name].Clone();
  24. temp[name] = item;
  25. }
  26. result[key] = temp;
  27. }
  28. return result;
  29. }
  30. private AlarmDefine CreateAlarmDefine(XmlNode alarm)
  31. {
  32. AlarmDefine alarmDefine = new AlarmDefine();
  33. if (alarm != null)
  34. {
  35. if (alarm.Attributes["Number"] != null)
  36. {
  37. int numberValue = 0;
  38. int.TryParse(alarm.Attributes["Number"].Value, out numberValue);
  39. alarmDefine.Number = numberValue;
  40. }
  41. if (alarm.Attributes["Message"] != null)
  42. alarmDefine.Message = alarm.Attributes["Message"].Value;
  43. if (alarm.Attributes["Action"] != null)
  44. alarmDefine.Action = alarm.Attributes["Action"].Value;
  45. if (alarm.Attributes["Recovery"] != null)
  46. alarmDefine.Recovery = alarm.Attributes["Recovery"].Value;
  47. if (alarm.Attributes["Cause"] != null)
  48. alarmDefine.Cause = alarm.Attributes["Cause"].Value;
  49. return alarmDefine;
  50. }
  51. return null;
  52. }
  53. public string GetStringAlarmDefineTemplate()
  54. {
  55. try
  56. {
  57. string recipeSchema = PathManager.GetCfgDir() + @"\AlarmDefine.xml";
  58. XmlDocument xmlDom = new XmlDocument();
  59. xmlDom.Load(recipeSchema);
  60. return xmlDom.OuterXml;
  61. }
  62. catch (Exception ex)
  63. {
  64. LOG.Write(ex);
  65. return "";
  66. }
  67. }
  68. }
  69. }