|
@@ -1,62 +1,62 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using CacheManager.Core;
|
|
|
-using CallCenter.BlackLists;
|
|
|
-using Microsoft.Extensions.DependencyInjection;
|
|
|
-using Microsoft.Extensions.Hosting;
|
|
|
-using XF.Domain.Dependency;
|
|
|
-
|
|
|
-namespace CallCenter.CacheManager
|
|
|
-{
|
|
|
- public class BlacklistManager : BackgroundService
|
|
|
- {
|
|
|
- //private readonly ICacheManager<Blacklist> _cacheManager;
|
|
|
- private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
-
|
|
|
- public BlacklistManager(IServiceScopeFactory serviceScopeFactory)
|
|
|
- {
|
|
|
- _serviceScopeFactory = serviceScopeFactory;
|
|
|
-
|
|
|
- //cacheManager.OnAdd += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- //cacheManager.OnRemove += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- //cacheManager.OnClear += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- //cacheManager.OnRemoveByHandle += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- //cacheManager.OnPut += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- //cacheManager.OnUpdate += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
|
|
|
- /// the lifetime of the long running operation(s) being performed.
|
|
|
- /// </summary>
|
|
|
- /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
|
|
|
- /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
|
|
|
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
- {
|
|
|
- var time = TimeSpan.FromMinutes(5);
|
|
|
- await Task.Delay(time, stoppingToken);
|
|
|
- while (!stoppingToken.IsCancellationRequested)
|
|
|
- {
|
|
|
- using var scope = _serviceScopeFactory.CreateScope();
|
|
|
- var blacklistRepository = scope.ServiceProvider.GetService<IBlacklistRepository>();
|
|
|
- var expiredBlackListItems =
|
|
|
- await blacklistRepository!.QueryAsync(d => !d.IsDeleted && d.Expired <= DateTime.Now);
|
|
|
- foreach (var blacklistItem in expiredBlackListItems)
|
|
|
- {
|
|
|
- await blacklistRepository.RemoveAsync(blacklistItem, true, stoppingToken);
|
|
|
- }
|
|
|
-
|
|
|
- await Task.Delay(time, stoppingToken);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//using System;
|
|
|
+//using System.Collections.Generic;
|
|
|
+//using System.Linq;
|
|
|
+//using System.Text;
|
|
|
+//using System.Threading.Tasks;
|
|
|
+//using CacheManager.Core;
|
|
|
+//using CallCenter.BlackLists;
|
|
|
+//using Microsoft.Extensions.DependencyInjection;
|
|
|
+//using Microsoft.Extensions.Hosting;
|
|
|
+//using XF.Domain.Dependency;
|
|
|
+
|
|
|
+//namespace CallCenter.CacheManager
|
|
|
+//{
|
|
|
+// public class BlacklistManager //: BackgroundService
|
|
|
+// {
|
|
|
+// //private readonly ICacheManager<Blacklist> _cacheManager;
|
|
|
+// private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
+
|
|
|
+// public BlacklistManager(IServiceScopeFactory serviceScopeFactory)
|
|
|
+// {
|
|
|
+// _serviceScopeFactory = serviceScopeFactory;
|
|
|
+
|
|
|
+// //cacheManager.OnAdd += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// //cacheManager.OnRemove += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// //cacheManager.OnClear += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// //cacheManager.OnRemoveByHandle += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// //cacheManager.OnPut += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// //cacheManager.OnUpdate += (sender, args) => { Console.WriteLine(args.ToString()); };
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
|
|
|
+// /// the lifetime of the long running operation(s) being performed.
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
|
|
|
+// /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
|
|
|
+// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
+// {
|
|
|
+// var time = TimeSpan.FromMinutes(5);
|
|
|
+// await Task.Delay(time, stoppingToken);
|
|
|
+// while (!stoppingToken.IsCancellationRequested)
|
|
|
+// {
|
|
|
+// using var scope = _serviceScopeFactory.CreateScope();
|
|
|
+// var blacklistRepository = scope.ServiceProvider.GetService<IBlacklistRepository>();
|
|
|
+// var expiredBlackListItems =
|
|
|
+// await blacklistRepository!.QueryAsync(d => !d.IsDeleted && d.Expired <= DateTime.Now);
|
|
|
+// foreach (var blacklistItem in expiredBlackListItems)
|
|
|
+// {
|
|
|
+// await blacklistRepository.RemoveAsync(blacklistItem, true, stoppingToken);
|
|
|
+// }
|
|
|
+
|
|
|
+// await Task.Delay(time, stoppingToken);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|