Collection.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Uestc.Auto6.Dso.Core
  9. {
  10. public abstract class Collection
  11. {
  12. public string ID;
  13. public Collection(string id, IBroadcaster pub)
  14. {
  15. ID = id;
  16. if (pub != null)
  17. pub.PublisherChanged += HandleCustomEvent;
  18. }
  19. public abstract void HandleCustomEvent(object? sender, CustomEventArg e);
  20. public void Add(IBroadcaster pub)
  21. {
  22. pub.PublisherChanged += HandleCustomEvent;
  23. }
  24. public void Remove(IBroadcaster pub)
  25. {
  26. try
  27. {
  28. pub.PublisherChanged -= HandleCustomEvent;
  29. }
  30. catch (Exception)
  31. {
  32. }
  33. }
  34. public event EventHandler? ExternalEvents;
  35. public void Add(IBroadcaster pub, EventHandler e)
  36. {
  37. pub.PublisherChanged += HandleCustomEvent;
  38. ExternalEvents += e;
  39. }
  40. public void Remove(IBroadcaster pub, EventHandler e)
  41. {
  42. try
  43. {
  44. pub.PublisherChanged -= HandleCustomEvent;
  45. ExternalEvents -= e;
  46. }
  47. catch (Exception)
  48. {
  49. }
  50. }
  51. }
  52. }