1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using Aitex.Core.RT.Event;
- using Aitex.Core.Util;
- using Aitex.Core.RT.Log;
- namespace Aitex.Triton160.UI
- {
- public class UiEvent
- {
- public event Action<EventItem> OnEvent;
- FixSizeQueue<EventItem> _queue = new FixSizeQueue<EventItem>(300);
- PeriodicJob _fireJob;
- public UiEvent()
- {
- }
- public void Start()
- {
- if (_fireJob != null)
- return;
- _fireJob = new PeriodicJob(1000, this.FireEvent, "UIEvent", true);
- }
- public void Stop()
- {
- _fireJob.Stop();
- }
- bool FireEvent()
- {
- if (OnEvent != null)
- {
- EventItem ev;
- while (_queue.TryDequeue(out ev))
- {
- OnEvent(ev);
- }
- }
- return true;
- }
- public void Event(EventItem ev)
- {
- LOG.Info(ev.Description);
- _queue.Enqueue(ev);
- }
- public void Event(string message, EventLevel level=EventLevel.Information)
- {
- LOG.Info(message);
- _queue.Enqueue(new EventItem()
- {
- OccuringTime = DateTime.Now,
- Description = message,
- Id = 0,
- Level = level,
- Type = EventType.EventUI_Notify,
- });
- }
- }
- }
|