BlacklistManager.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //using Hotline.CallCenter.BlackLists;
  2. //using Microsoft.Extensions.DependencyInjection;
  3. //using Microsoft.Extensions.Hosting;
  4. //namespace Hotline.CacheManager
  5. //{
  6. // public class BlacklistManager : BackgroundService
  7. // {
  8. // //private readonly ICacheManager<Blacklist> _cacheManager;
  9. // private readonly IServiceScopeFactory _serviceScopeFactory;
  10. // public BlacklistManager(IServiceScopeFactory serviceScopeFactory)
  11. // {
  12. // _serviceScopeFactory = serviceScopeFactory;
  13. // //cacheManager.OnAdd += (sender, args) => { Console.WriteLine(args.ToString()); };
  14. // //cacheManager.OnRemove += (sender, args) => { Console.WriteLine(args.ToString()); };
  15. // //cacheManager.OnClear += (sender, args) => { Console.WriteLine(args.ToString()); };
  16. // //cacheManager.OnRemoveByHandle += (sender, args) => { Console.WriteLine(args.ToString()); };
  17. // //cacheManager.OnPut += (sender, args) => { Console.WriteLine(args.ToString()); };
  18. // //cacheManager.OnUpdate += (sender, args) => { Console.WriteLine(args.ToString()); };
  19. // }
  20. // /// <summary>
  21. // /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
  22. // /// the lifetime of the long running operation(s) being performed.
  23. // /// </summary>
  24. // /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
  25. // /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
  26. // protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  27. // {
  28. // var time = TimeSpan.FromMinutes(5);
  29. // await Task.Delay(time, stoppingToken);
  30. // while (!stoppingToken.IsCancellationRequested)
  31. // {
  32. // using var scope = _serviceScopeFactory.CreateScope();
  33. // var blacklistRepository = scope.ServiceProvider.GetService<IBlacklistRepository>();
  34. // var expiredBlackListItems =
  35. // await blacklistRepository!.QueryAsync(d => d.Expired <= DateTime.Now);
  36. // foreach (var blacklistItem in expiredBlackListItems)
  37. // {
  38. // await blacklistRepository.RemoveAsync(blacklistItem, true, stoppingToken);
  39. // }
  40. // await Task.Delay(time, stoppingToken);
  41. // }
  42. // }
  43. // }
  44. //}