123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 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<TestController> _logger;
- private readonly IAuthorizeGenerator _authorizeGenerator;
- private readonly IOptionsSnapshot<DeviceConfigs> _options;
- private readonly ISessionContext _sessionContext;
- private readonly IUserRepository _userRepository;
- private readonly ITypedCache<User> _cache;
- private readonly IRealtimeService _realtimeService;
- private readonly IBlacklistDomainService _blacklistDomainService;
- private readonly IIvrDomainService _ivrDomainService;
- //private readonly ITypedCache<List<User>> _cache;
- //private readonly ICacheManager<User> _cache;
- public TestController(
- INewRockClient client,
- ILogger<TestController> logger,
- IAuthorizeGenerator authorizeGenerator,
- IOptionsSnapshot<DeviceConfigs> options,
- ISessionContext sessionContext,
- IUserRepository userRepository,
- //ICacheManager<User> cache
- //ITypedCache<List<User>> cache
- ITypedCache<User> 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<User>(config);
- //var a = cache.Add(new CacheItem<User>(user.Id, user, ExpirationMode.None, TimeSpan.FromMinutes(5)));
- //var user1 = cache.Get<User>(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");
- }
- /// <summary>
- /// signalR测试(method: Ring)
- /// </summary>
- /// <returns></returns>
- [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);
- }
- }
- }
|