UIEvent.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.Util;
  4. using Aitex.Core.RT.Log;
  5. namespace Aitex.Triton160.UI
  6. {
  7. public class UiEvent
  8. {
  9. public event Action<EventItem> OnEvent;
  10. FixSizeQueue<EventItem> _queue = new FixSizeQueue<EventItem>(300);
  11. PeriodicJob _fireJob;
  12. public UiEvent()
  13. {
  14. }
  15. public void Start()
  16. {
  17. if (_fireJob != null)
  18. return;
  19. _fireJob = new PeriodicJob(1000, this.FireEvent, "UIEvent", true);
  20. }
  21. public void Stop()
  22. {
  23. _fireJob.Stop();
  24. }
  25. bool FireEvent()
  26. {
  27. if (OnEvent != null)
  28. {
  29. EventItem ev;
  30. while (_queue.TryDequeue(out ev))
  31. {
  32. OnEvent(ev);
  33. }
  34. }
  35. return true;
  36. }
  37. public void Event(EventItem ev)
  38. {
  39. LOG.Info(ev.Description);
  40. _queue.Enqueue(ev);
  41. }
  42. public void Event(string message, EventLevel level=EventLevel.Information)
  43. {
  44. LOG.Info(message);
  45. _queue.Enqueue(new EventItem()
  46. {
  47. OccuringTime = DateTime.Now,
  48. Description = message,
  49. Id = 0,
  50. Level = level,
  51. Type = EventType.EventUI_Notify,
  52. });
  53. }
  54. }
  55. }