123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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<AlarmDefineFileManager>
- {
- private Dictionary<int, AlarmDefine> _allAlarmDefineDic;
- public Dictionary<int, Dictionary<int, AlarmDefine>> AlarmTables { get; private set; }
- public int CurrentAlarmTable { get; set; } = 0;//default table 0
- private bool _isCreateWCFChanel = false;
- public void CreateWCFChanel()
- {
- if(!_isCreateWCFChanel)
- {
- Singleton<WcfServiceManager>.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<int, Dictionary<int, AlarmDefine>>()
- //{
- // {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<int, AlarmDefine> 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;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
|