Pushes.cs 809 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace InABox.Core
  5. {
  6. /// <summary>
  7. /// Client-side push manager.
  8. /// </summary>
  9. public class PushHandlers
  10. {
  11. private Dictionary<Type, IPushHandler> Handlers = new Dictionary<Type, IPushHandler>();
  12. public void AddHandler<TPush>(PushHandler<TPush> handler)
  13. {
  14. Handlers[typeof(TPush)] = handler;
  15. }
  16. public void AddHandler<TPush>(PushHandler<TPush>.ReceiveEvent receive)
  17. {
  18. Handlers[typeof(TPush)] = new PushHandler<TPush>(receive);
  19. }
  20. public void Push(Type type, object? push)
  21. {
  22. if (Handlers.TryGetValue(type, out var handler))
  23. {
  24. handler.Receive(push);
  25. }
  26. }
  27. }
  28. }