您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LuNotificationsBusiness.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Linq;
  3. using Luticate2.Utils.Hubs;
  4. using Microsoft.AspNetCore.SignalR;
  5. using Microsoft.AspNetCore.SignalR.Infrastructure;
  6. namespace Luticate2.Utils.Business
  7. {
  8. public class LuNotificationsBusiness
  9. {
  10. private readonly LuHubConnectionTracker _connectionTracker;
  11. private readonly IHubContext _hubContext;
  12. public const string EventCreate = "EVENT_CREATE";
  13. public const string EventUpdate = "EVENT_UPDATE";
  14. public const string EventDelete = "EVENT_DELETE";
  15. public LuNotificationsBusiness(IConnectionManager connectionManager, LuHubConnectionTracker connectionTracker)
  16. {
  17. _connectionTracker = connectionTracker;
  18. _hubContext = connectionManager.GetHubContext<LuNotificationsHub>();
  19. }
  20. public void Notify(string eventName, string entityType, object oldEntity, object newEntity, Func<string, bool> filter = null)
  21. {
  22. var connectionsIds = _connectionTracker.Get<LuNotificationsHub>();
  23. var selectedIds = filter != null ? connectionsIds.Where(filter).ToList() : connectionsIds;
  24. _hubContext.Clients.Clients(selectedIds).notify(eventName, entityType, oldEntity, newEntity);
  25. }
  26. public void NotifyCreate(string entityType, object newEntity, Func<string, bool> filter = null)
  27. {
  28. Notify(EventCreate, entityType, null, newEntity, filter);
  29. }
  30. public void NotifyUpdate(string entityType, object oldEntity, object newEntity, Func<string, bool> filter = null)
  31. {
  32. Notify(EventUpdate, entityType, oldEntity, newEntity, filter);
  33. }
  34. public void NotifyDelete(string entityType, object oldEntity, Func<string, bool> filter = null)
  35. {
  36. Notify(EventDelete, entityType, oldEntity, null, filter);
  37. }
  38. }
  39. }