This commit is contained in:
alex
2023-09-18 14:06:43 +08:00
parent 1cefb51aa9
commit 64b6a5485c
3 changed files with 18 additions and 17 deletions

View File

@@ -51,6 +51,7 @@ namespace Tnb.WarehouseMgr
public class BaseWareHouseService : IOverideVisualDevService, IDynamicApiController, ITransient
{
private static Lazy<Dictionary<string, IWHStorageService>> _stroageMapLazy;
private static Dictionary<string, IWHStorageService> _storeMap = new(StringComparer.OrdinalIgnoreCase);
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
private readonly ChannelWriter<NotifyMessage> _channelWriter;
@@ -61,9 +62,9 @@ namespace Tnb.WarehouseMgr
static BaseWareHouseService()
{
_stroageMapLazy = new Lazy<Dictionary<string, IWHStorageService>>(() =>
//_stroageMapLazy = new Lazy<Dictionary<string, IWHStorageService>>(() =>
{
Dictionary<string, IWHStorageService> map = new(StringComparer.OrdinalIgnoreCase);
//Dictionary<string, IWHStorageService> map = new(StringComparer.OrdinalIgnoreCase);
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
foreach (var serviceType in serviceTypes)
{
@@ -72,18 +73,19 @@ namespace Tnb.WarehouseMgr
{
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
if (obj == null) continue;
map[callerName] = obj;
_storeMap[callerName] = obj;
}
}
return map;
});
//return map;
}
//);
}
protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null)
{
asscessToken = asscessToken.Replace("Bearer ", "").Replace("bearer ", "");
asscessToken = asscessToken?.Replace("Bearer ", "").Replace("bearer ", "");
var at = asscessToken ?? UserManager.AsscessToken;
var claims = JWTEncryption.ReadJwtToken(at)?.Claims;
ClaimsIdentity toKen = new ClaimsIdentity();
@@ -144,9 +146,9 @@ namespace Tnb.WarehouseMgr
[NonAction]
protected async Task DoUpdate(WareHouseUpInput input)
{
if (_stroageMapLazy.Value.ContainsKey(input.loginType))
if (_storeMap.ContainsKey(input.loginType))
{
await _stroageMapLazy.Value[input.loginType].Do(input);
await _storeMap[input.loginType].Do(input);
}
}
[NonAction]

View File

@@ -170,6 +170,12 @@ namespace Tnb.WarehouseMgr
#endregion
}
public override Task StopAsync(CancellationToken cancellationToken)
{
IsStarted = false;
return base.StopAsync(cancellationToken);
}
private Task TaskDelay(TimeSpanUnit timeType, int interval)
{
Task delayTask = timeType switch

View File

@@ -289,18 +289,15 @@ public class OAuthService : IDynamicApiController, ITransient
{
if (type.IsNullOrEmpty()) type = "Web"; // 默认为Web端菜单目录
var userId = _userManager.UserId;
//modify by ly on 20230918 登录成功后启动定时服务
if (!userId.IsNullOrWhiteSpace())
{
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted)
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
await _backgroundService.StartAsync(cancellationTokenSource.Token);
await _backgroundService.StartAsync(CancellationToken.None);
}
}
@@ -405,12 +402,8 @@ public class OAuthService : IDynamicApiController, ITransient
[HttpGet("Logout")]
public async Task Logout([FromQuery] string ticket)
{
//await _cacheManager.DelAsync("AsscessToken");
//modify by ly on 20230918
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
isStartedProperty?.SetValue(_backgroundService, false);
await _backgroundService.StopAsync(CancellationToken.None);
UserManager.AsscessToken = string.Empty;