using CallCenter.Api.Realtimes; using CallCenter.BlackLists; using CallCenter.Devices; using CallCenter.Ivrs; using CallCenter.Realtimes; using CallCenter.Users; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using NewRock.Sdk; using NewRock.Sdk.Security; using XF.Domain.Cache; using XF.Domain.Https; namespace CallCenter.Api.Controllers { public class TestController : BaseController { private readonly ILogger _logger; private readonly IAuthorizeGenerator _authorizeGenerator; private readonly IOptionsSnapshot _options; private readonly ISessionContext _sessionContext; private readonly IUserRepository _userRepository; private readonly ITypedCache _cache; private readonly IRealtimeService _realtimeService; private readonly IBlacklistDomainService _blacklistDomainService; private readonly IIvrDomainService _ivrDomainService; //private readonly ITypedCache> _cache; //private readonly ICacheManager _cache; public TestController( INewRockClient client, ILogger logger, IAuthorizeGenerator authorizeGenerator, IOptionsSnapshot options, ISessionContext sessionContext, IUserRepository userRepository, //ICacheManager cache //ITypedCache> cache ITypedCache cache, IRealtimeService realtimeService, IBlacklistDomainService blacklistDomainService, IIvrDomainService ivrDomainService ) { _logger = logger; _authorizeGenerator = authorizeGenerator; _options = options; _sessionContext = sessionContext; _userRepository = userRepository; _cache = cache; _realtimeService = realtimeService; _blacklistDomainService = blacklistDomainService; _ivrDomainService = ivrDomainService; } [HttpGet] public async Task Test1() { var user = await _userRepository.GetAsync("08da8016-72af-48b3-8c8f-b39251229f79"); _cache.Add(user.Id, user, ExpireMode.None, TimeSpan.FromMinutes(1)); var user1 = _cache.Get(user.Id); user1.NickName = "aaa"; _cache.Update(user.Id, d => user1); //var config = new ConfigurationBuilder() // .WithUpdateMode(CacheUpdateMode.Up) // .WithMicrosoftMemoryCacheHandle() // .And // .WithRedisConfiguration("redis", d => // { // d.WithDatabase(0) // .WithEndpoint("redis.fengwo.com", 6380); // }) // .WithSerializer(typeof(SystemTextJsonSerializer), new JsonSerializerOptions // { // PropertyNamingPolicy = JsonNamingPolicy.CamelCase, // DictionaryKeyPolicy = JsonNamingPolicy.CamelCase, // DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull // }) // .WithRedisBackplane("redis") // .WithRedisCacheHandle("redis", true) //.Build(); //var cache = CacheFactory.FromConfiguration(config); //var a = cache.Add(new CacheItem(user.Id, user, ExpirationMode.None, TimeSpan.FromMinutes(5))); //var user1 = cache.Get(user.Id); //var a = _cache.Add(user.Id, user, ExpireMode.None, TimeSpan.FromMinutes(5)); //var user1 = _cache.Get(user.Id); //var users = await _userRepository.QueryAsync(d => true); //_cache.Add("users", users, ExpireMode.None); //var u1 = _cache.Get("users"); } /// /// signalR测试(method: Ring) /// /// [HttpGet("ring")] public async Task RingTest() { await _realtimeService.RingAsync(_sessionContext.RequiredUserId, new RingDto { From = "13512341234" }, HttpContext.RequestAborted); } [HttpGet("t2")] public async Task GetVoiceEndAnswerAsyncTest() { var answer = await _ivrDomainService.GetVoiceEndAnswerAsync("3", HttpContext.RequestAborted); Console.WriteLine(answer.Content); } } }