AlarmDefineFileManager.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Aitex.Core.RT.OperationCenter;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Core.Util;
  4. using Aitex.Core.WCF;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace MECF.Framework.Common.Alarms
  11. {
  12. public class AlarmDefineFileManager : Singleton<AlarmDefineFileManager>
  13. {
  14. private Dictionary<int, AlarmDefine> _allAlarmDefineDic;
  15. public Dictionary<int, Dictionary<int, AlarmDefine>> AlarmTables { get; private set; }
  16. public int CurrentAlarmTable { get; set; } = 0;//default table 0
  17. private bool _isCreateWCFChanel = false;
  18. public void CreateWCFChanel()
  19. {
  20. if(!_isCreateWCFChanel)
  21. {
  22. Singleton<WcfServiceManager>.Instance.Initialize(new Type[]
  23. {
  24. typeof(AlarmDefineService)
  25. });
  26. _isCreateWCFChanel = true;
  27. }
  28. }
  29. public void Initialize()
  30. {
  31. CreateWCFChanel();
  32. //AlarmDefineFileContext context = new AlarmDefineFileContext();
  33. //_allAlarmDefineDic = context.GetAlarmDefine();
  34. //foreach (var alarmdefine in _allAlarmDefineDic.Keys)
  35. //{
  36. // _allAlarmDefineDic[alarmdefine].IsUse = true;
  37. //}
  38. //AlarmTables = new Dictionary<int, Dictionary<int, AlarmDefine>>()
  39. //{
  40. // {0, _allAlarmDefineDic},
  41. //};
  42. //InitAlarmTable();
  43. //OP.Subscribe($"System.UpdateAlarmTable", (string cmd, object[] args) =>
  44. //{
  45. // SC.SetItemValue("PM1.RecipeEditParameter.AlarmTables.AlarmTable", args[0].ToString());
  46. // InitAlarmTable();
  47. // return true;
  48. //});
  49. ////for recipe
  50. //OP.Subscribe($"System.SetAlarmTableID", (out string reason, int time, object[] param) =>
  51. //{
  52. // reason = string.Empty;
  53. // int.TryParse(param[0].ToString(), out var currentAlarmTable);
  54. // CurrentAlarmTable = currentAlarmTable;
  55. // return true;
  56. //});
  57. }
  58. private void InitAlarmTable()
  59. {
  60. if (!SC.ContainsItem("PM1.RecipeEditParameter.AlarmTables.AlarmTable"))
  61. return;
  62. var alarmTableSC = SC.GetStringValue("PM1.RecipeEditParameter.AlarmTables.AlarmTable");
  63. if(!string.IsNullOrEmpty(alarmTableSC))
  64. {
  65. var alarmTables = alarmTableSC.Split('|').ToList();
  66. foreach(var alarmTable in alarmTables)
  67. {
  68. var alarmTableParas = alarmTable.Split(':');
  69. if(alarmTableParas.Length > 1)
  70. {
  71. int.TryParse(alarmTableParas[0], out int tableID);
  72. if(!AlarmTables.ContainsKey(tableID))
  73. {
  74. AlarmDefineFileContext context = new AlarmDefineFileContext();
  75. Dictionary<int, AlarmDefine> alarmDefineDic = context.GetAlarmDefine();
  76. foreach (var alarmdefine in alarmDefineDic.Keys)
  77. {
  78. alarmDefineDic[alarmdefine].IsUse = true;
  79. }
  80. AlarmTables.Add(tableID, alarmDefineDic);
  81. }
  82. var alarmDefines = alarmTableParas[1].Split(';').ToList();
  83. if(alarmDefines.Count > 0)
  84. {
  85. foreach(var alarmDefine in alarmDefines)
  86. {
  87. var alarmDefineItems = alarmDefine.Split(',');
  88. if (alarmDefineItems.Length > 3)
  89. {
  90. int.TryParse(alarmDefineItems[0], out int alarmID);
  91. bool.TryParse(alarmDefineItems[1], out bool isUse);
  92. int.TryParse(alarmDefineItems[2].Replace("ALG", ""), out int alarmGroup);
  93. if (AlarmTables[tableID].ContainsKey(alarmID))
  94. {
  95. AlarmTables[tableID][alarmID].IsUse = isUse;
  96. AlarmTables[tableID][alarmID].AlarmGroup = alarmGroup;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }