OnlineNotificationHandler.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Hotline.Caches;
  2. using Hotline.CallCenter.Tels;
  3. using Hotline.Share.Enums.CallCenter;
  4. using Hotline.Share.Notifications;
  5. using MediatR;
  6. using XF.Domain.Cache;
  7. namespace Hotline.Application.Handlers.CallCenter.ExtState
  8. {
  9. public class OnlineNotificationHandler : INotificationHandler<OnlineNotification>
  10. {
  11. private readonly ITelRepository _telRepository;
  12. private readonly ITelCacheManager _telCacheManager;
  13. private readonly ITypedCache<Tel> _typedCache;
  14. public OnlineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache)
  15. {
  16. _telRepository = telRepository;
  17. _telCacheManager = telCacheManager;
  18. _typedCache = typedCache;
  19. }
  20. /// <summary>Handles a notification</summary>
  21. /// <param name="notification">The notification</param>
  22. /// <param name="cancellationToken">Cancellation token</param>
  23. public async Task Handle(OnlineNotification notification, CancellationToken cancellationToken)
  24. {
  25. var telModel = _telCacheManager.GetTel(notification.TelNo);
  26. telModel.TelStatus = ETelStatus.Ready;
  27. telModel.RegisterIP = notification.RegisterIP;
  28. await _telRepository.UpdateAsync(telModel,cancellationToken);
  29. _typedCache.Update(notification.TelNo, x => telModel);
  30. }
  31. }
  32. }