TestController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using CallCenter.Api.Realtimes;
  2. using CallCenter.BlackLists;
  3. using CallCenter.Devices;
  4. using CallCenter.Ivrs;
  5. using CallCenter.Realtimes;
  6. using CallCenter.Users;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Options;
  9. using NewRock.Sdk;
  10. using NewRock.Sdk.Security;
  11. using XF.Domain.Cache;
  12. using XF.Domain.Https;
  13. namespace CallCenter.Api.Controllers
  14. {
  15. public class TestController : BaseController
  16. {
  17. private readonly ILogger<TestController> _logger;
  18. private readonly IAuthorizeGenerator _authorizeGenerator;
  19. private readonly IOptionsSnapshot<DeviceConfigs> _options;
  20. private readonly ISessionContext _sessionContext;
  21. private readonly IUserRepository _userRepository;
  22. private readonly ITypedCache<User> _cache;
  23. private readonly IRealtimeService _realtimeService;
  24. private readonly IBlacklistDomainService _blacklistDomainService;
  25. private readonly IIvrDomainService _ivrDomainService;
  26. //private readonly ITypedCache<List<User>> _cache;
  27. //private readonly ICacheManager<User> _cache;
  28. public TestController(
  29. INewRockClient client,
  30. ILogger<TestController> logger,
  31. IAuthorizeGenerator authorizeGenerator,
  32. IOptionsSnapshot<DeviceConfigs> options,
  33. ISessionContext sessionContext,
  34. IUserRepository userRepository,
  35. //ICacheManager<User> cache
  36. //ITypedCache<List<User>> cache
  37. ITypedCache<User> cache,
  38. IRealtimeService realtimeService,
  39. IBlacklistDomainService blacklistDomainService,
  40. IIvrDomainService ivrDomainService
  41. )
  42. {
  43. _logger = logger;
  44. _authorizeGenerator = authorizeGenerator;
  45. _options = options;
  46. _sessionContext = sessionContext;
  47. _userRepository = userRepository;
  48. _cache = cache;
  49. _realtimeService = realtimeService;
  50. _blacklistDomainService = blacklistDomainService;
  51. _ivrDomainService = ivrDomainService;
  52. }
  53. [HttpGet]
  54. public async Task Test1()
  55. {
  56. var user = await _userRepository.GetAsync("08da8016-72af-48b3-8c8f-b39251229f79");
  57. _cache.Add(user.Id, user, ExpireMode.None, TimeSpan.FromMinutes(1));
  58. var user1 = _cache.Get(user.Id);
  59. user1.NickName = "aaa";
  60. _cache.Update(user.Id, d => user1);
  61. //var config = new ConfigurationBuilder()
  62. // .WithUpdateMode(CacheUpdateMode.Up)
  63. // .WithMicrosoftMemoryCacheHandle()
  64. // .And
  65. // .WithRedisConfiguration("redis", d =>
  66. // {
  67. // d.WithDatabase(0)
  68. // .WithEndpoint("redis.fengwo.com", 6380);
  69. // })
  70. // .WithSerializer(typeof(SystemTextJsonSerializer), new JsonSerializerOptions
  71. // {
  72. // PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
  73. // DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
  74. // DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
  75. // })
  76. // .WithRedisBackplane("redis")
  77. // .WithRedisCacheHandle("redis", true)
  78. //.Build();
  79. //var cache = CacheFactory.FromConfiguration<User>(config);
  80. //var a = cache.Add(new CacheItem<User>(user.Id, user, ExpirationMode.None, TimeSpan.FromMinutes(5)));
  81. //var user1 = cache.Get<User>(user.Id);
  82. //var a = _cache.Add(user.Id, user, ExpireMode.None, TimeSpan.FromMinutes(5));
  83. //var user1 = _cache.Get(user.Id);
  84. //var users = await _userRepository.QueryAsync(d => true);
  85. //_cache.Add("users", users, ExpireMode.None);
  86. //var u1 = _cache.Get("users");
  87. }
  88. /// <summary>
  89. /// signalR测试(method: Ring)
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpGet("ring")]
  93. public async Task RingTest()
  94. {
  95. await _realtimeService.RingAsync(_sessionContext.RequiredUserId, new RingDto { From = "13512341234" }, HttpContext.RequestAborted);
  96. }
  97. [HttpGet("t2")]
  98. public async Task GetVoiceEndAnswerAsyncTest()
  99. {
  100. var answer = await _ivrDomainService.GetVoiceEndAnswerAsync("3", HttpContext.RequestAborted);
  101. Console.WriteLine(answer.Content);
  102. }
  103. }
  104. }