using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Core.WCF; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.Alarms { public class AlarmDefineFileManager : Singleton { private Dictionary _allAlarmDefineDic; public Dictionary> AlarmTables { get; private set; } public int CurrentAlarmTable { get; set; } = 0;//default table 0 private bool _isCreateWCFChanel = false; public void CreateWCFChanel() { if(!_isCreateWCFChanel) { Singleton.Instance.Initialize(new Type[] { typeof(AlarmDefineService) }); _isCreateWCFChanel = true; } } public void Initialize() { CreateWCFChanel(); //AlarmDefineFileContext context = new AlarmDefineFileContext(); //_allAlarmDefineDic = context.GetAlarmDefine(); //foreach (var alarmdefine in _allAlarmDefineDic.Keys) //{ // _allAlarmDefineDic[alarmdefine].IsUse = true; //} //AlarmTables = new Dictionary>() //{ // {0, _allAlarmDefineDic}, //}; //InitAlarmTable(); //OP.Subscribe($"System.UpdateAlarmTable", (string cmd, object[] args) => //{ // SC.SetItemValue("PM1.RecipeEditParameter.AlarmTables.AlarmTable", args[0].ToString()); // InitAlarmTable(); // return true; //}); ////for recipe //OP.Subscribe($"System.SetAlarmTableID", (out string reason, int time, object[] param) => //{ // reason = string.Empty; // int.TryParse(param[0].ToString(), out var currentAlarmTable); // CurrentAlarmTable = currentAlarmTable; // return true; //}); } private void InitAlarmTable() { if (!SC.ContainsItem("PM1.RecipeEditParameter.AlarmTables.AlarmTable")) return; var alarmTableSC = SC.GetStringValue("PM1.RecipeEditParameter.AlarmTables.AlarmTable"); if(!string.IsNullOrEmpty(alarmTableSC)) { var alarmTables = alarmTableSC.Split('|').ToList(); foreach(var alarmTable in alarmTables) { var alarmTableParas = alarmTable.Split(':'); if(alarmTableParas.Length > 1) { int.TryParse(alarmTableParas[0], out int tableID); if(!AlarmTables.ContainsKey(tableID)) { AlarmDefineFileContext context = new AlarmDefineFileContext(); Dictionary alarmDefineDic = context.GetAlarmDefine(); foreach (var alarmdefine in alarmDefineDic.Keys) { alarmDefineDic[alarmdefine].IsUse = true; } AlarmTables.Add(tableID, alarmDefineDic); } var alarmDefines = alarmTableParas[1].Split(';').ToList(); if(alarmDefines.Count > 0) { foreach(var alarmDefine in alarmDefines) { var alarmDefineItems = alarmDefine.Split(','); if (alarmDefineItems.Length > 3) { int.TryParse(alarmDefineItems[0], out int alarmID); bool.TryParse(alarmDefineItems[1], out bool isUse); int.TryParse(alarmDefineItems[2].Replace("ALG", ""), out int alarmGroup); if (AlarmTables[tableID].ContainsKey(alarmID)) { AlarmTables[tableID][alarmID].IsUse = isUse; AlarmTables[tableID][alarmID].AlarmGroup = alarmGroup; } } } } } } } } } }