123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.Util;
- using FabConnect.SecsGemInterface.Common.ToolModel;
- using log4net.Core;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using Mono.Security.Authenticode;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_RT.HostWrapper;
- using static Aitex.Core.RT.Log.LOG;
- using static Mono.Security.X509.X520;
- namespace Venus_RT.FAs
- {
- public class FaEvent
- {
- //public event Action<PostFAItem> PostEvent;
- static Dictionary<string, PostFAItem> _eventDic = new Dictionary<string, PostFAItem>();
- static FixSizeQueue<PostFAItem> _eventQueue;
- PeriodicJob _eventJob;
- private const string INFORMATION_EVENT = "INFORMATION_EVENT";
- private const string WARNING_EVENT = "WARNING_EVENT";
- private const string ALARM_EVENT = "ALARM_EVENT";
- public void Initialize(string commonEventListXmlFile)
- {
- _eventJob = new PeriodicJob(100, this.PeriodicRun, "FaEventPeriodicJob", true);
- _eventQueue = new FixSizeQueue<PostFAItem>(1000);
- AddFaEvent(new PostFAItem(INFORMATION_EVENT, EventLevel.Information));
- AddFaEvent(new PostFAItem(WARNING_EVENT, EventLevel.Warning));
- AddFaEvent(new PostFAItem(ALARM_EVENT, EventLevel.Alarm));
- try
- {
- EventDefine eventList = CustomXmlSerializer.Deserialize<EventDefine>(new FileInfo(commonEventListXmlFile));
- foreach (var item in eventList.Items)
- {
- _eventDic[item.EventEnum] = new PostFAItem();
- _eventDic[item.EventEnum].FaEventEnum = item.EventEnum;
- _eventDic[item.EventEnum].Description = item.Description;
- _eventDic[item.EventEnum].Level = item.Level;
- _eventDic[item.EventEnum].Source = item.Source;
- _eventDic[item.EventEnum].FaEventEnum = item.EventEnum;
- }
- }
- catch (ArgumentNullException)
- {
- throw new ApplicationException("初始化EventManager没有设置Event列表文件");
- }
- catch (FileNotFoundException ex)
- {
- throw new ApplicationException("没有找到Event列表文件," + ex.Message);
- }
- catch (Exception ex)
- {
- throw new ApplicationException("EventDefine文件格式不对," + commonEventListXmlFile + ",\r\n" + ex.Message);
- }
- }
- public void Terminate()
- {
- if (_eventJob != null)
- {
- _eventJob.Stop();
- _eventJob = null;
- }
- }
- public static void AddFaEvent(PostFAItem item)
- {
- if (_eventDic.ContainsKey(item.FaEventEnum))
- {
- return;
- }
- _eventDic[item.FaEventEnum] = item;
- }
- bool PeriodicRun()
- {
- PostFAItem FaEv;
- while (_eventQueue.TryDequeue(out FaEv))
- {
- try
- {
- InstanceOnOnEvent(FaEv);
- }
- catch (Exception ex)
- {
- }
- }
- return true;
- }
- private void InstanceOnOnEvent(PostFAItem obj)
- {
- if (obj.Level != EventLevel.Alarm)
- {
- Singleton<FaManager>.Instance.NotifyEvent(obj.FaEventEnum, obj.DVID, obj.ObjDVID);
- }
- else
- {
- Singleton<FaManager>.Instance.NotifyAlarm(obj.FaEventEnum, obj.DVID, obj.ObjDVID, obj.Description);
- }
- }
- public static void SendHost(string module, string eventName, params object[] args)
- {
- if (!_eventDic.ContainsKey(eventName))
- {
- //LOG.Write(eEvent.INFO_FA, "Event name not registered, " + eventName);
- return;
- }
- PostFAItem item = _eventDic[eventName].Clone();
- item.Source = module;
- item.Description = string.Format(_eventDic[eventName].Description, args);
- if (!string.IsNullOrWhiteSpace(item.Source))
- {
- item.Description = item.Source + " " + item.Description;
- }
- _eventQueue.Enqueue(item);
- }
- public static void SendHost(string module, string eventName, string description)
- {
- if (!_eventDic.ContainsKey(eventName))
- {
- //LOG.Write(eEvent.INFO_FA, "Event name not registered, " + eventName);
- return;
- }
- PostFAItem item = _eventDic[eventName].Clone();
- item.Source = module;
- item.Description = description;
- if (!string.IsNullOrWhiteSpace(item.Source))
- {
- item.Description = item.Source + " " + item.Description;
- }
- _eventQueue.Enqueue(item);
- }
- public static void SendHost(string eventName, SerializableDictionary<string, string> dvid)
- {
- if (!_eventDic.ContainsKey(eventName))
- {
- return;
- }
- PostFAItem item = _eventDic[eventName].Clone();
- item.Description = string.Format(_eventDic[eventName].Description);
- item.DVID = dvid;
- item.Source = _eventDic[eventName].Source;
- _eventQueue.Enqueue(item);
- }
- public static void SendHost(string eventName, SerializableDictionary<string, object> dvid)
- {
- if (!_eventDic.ContainsKey(eventName))
- {
- return;
- }
- PostFAItem item = _eventDic[eventName].Clone(dvid);
- item.Description = string.Format(_eventDic[eventName].Description);
- item.ObjDVID = dvid;
- item.Source = _eventDic[eventName].Source;
- _eventQueue.Enqueue(item);
- }
- public static void FaPostAlarm(string module, string message)
- {
- SendHost(module, WARNING_EVENT, message);
- }
- public static void FaPostWarning(string module, string message)
- {
- SendHost(module, ALARM_EVENT, message);
- }
- public static void FaPostInfo(string module, string message)
- {
- SendHost(module, INFORMATION_EVENT, message);
- }
- public static void FaPostMessage(string module, string message, params object[] args)
- {
- SendHost(module, message,args);
- }
- public static void FaNotify(string eventName, SerializableDictionary<string, string> dvid)
- {
- SendHost(eventName, dvid);
- }
- public static void FaNotify(string eventName, SerializableDictionary<string, object> dvid)
- {
- SendHost(eventName, dvid);
- }
- }
- public class PostFAItem
- {
- public string Source { get; set; }
- public string FaEventEnum { get; set; }
- public int Id { get; set; }
- public string Explaination { get; set; }
- public EventLevel Level { get; set; }
- public string Description { get; set; }
- public SerializableDictionary<string, string> DVID
- {
- get;
- set;
- }
- public SerializableDictionary<string, object> ObjDVID
- {
- get;
- set;
- }
- public PostFAItem Clone()
- {
- PostFAItem result = new PostFAItem();
- result.Description = Description;
- result.FaEventEnum = FaEventEnum;
- result.Explaination = Explaination;
- result.Id = Id;
- result.Level = Level;
- result.Source = Source;
- result.DVID = DVID;
- result.ObjDVID = ObjDVID;
- return result;
- }
- public PostFAItem Clone(SerializableDictionary<string, object> objDvid)
- {
- PostFAItem result = new PostFAItem();
- result.Description = Description;
- result.FaEventEnum = FaEventEnum;
- result.Explaination = Explaination;
- result.Id = Id;
- result.Level = Level;
- result.Source = Source;
- result.DVID = DVID;
- result.ObjDVID = objDvid;
- return result;
- }
- public PostFAItem()
- {
- }
- public PostFAItem(string name, EventLevel level)
- {
- FaEventEnum = name;
- Level = level;
- }
- public PostFAItem(string source, string name, string description, EventLevel level)
- {
- Source = source;
- FaEventEnum = name;
- Description = description;
- Level = level;
- }
- public PostFAItem(string source, string name, string description)
- {
- Source = source;
- FaEventEnum = name;
- Description = description;
- }
- }
- }
|