IEvent.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. namespace ET
  3. {
  4. public interface IEvent
  5. {
  6. Type GetEventType();
  7. }
  8. public interface IEventClass: IEvent
  9. {
  10. void Handle(object a);
  11. }
  12. [Event]
  13. public abstract class AEventClass<A>: IEventClass where A: class
  14. {
  15. public Type GetEventType()
  16. {
  17. return typeof (A);
  18. }
  19. protected abstract void Run(object a);
  20. public void Handle(object a)
  21. {
  22. try
  23. {
  24. Run(a);
  25. }
  26. catch (Exception e)
  27. {
  28. Log.Error(e);
  29. }
  30. }
  31. }
  32. [Event]
  33. public abstract class AEvent<A>: IEvent where A: struct
  34. {
  35. public Type GetEventType()
  36. {
  37. return typeof (A);
  38. }
  39. protected abstract ETTask Run(A a);
  40. public async ETTask Handle(A a)
  41. {
  42. try
  43. {
  44. await Run(a);
  45. }
  46. catch (Exception e)
  47. {
  48. Log.Error(e);
  49. }
  50. }
  51. }
  52. [Event]
  53. public abstract class AEventAsync<A>: IEvent where A: struct
  54. {
  55. public Type GetEventType()
  56. {
  57. return typeof (A);
  58. }
  59. protected abstract ETTask Run(A a);
  60. public async ETTask Handle(A a)
  61. {
  62. try
  63. {
  64. await Run(a);
  65. }
  66. catch (Exception e)
  67. {
  68. Log.Error(e);
  69. }
  70. }
  71. }
  72. }