From 6cc0529d606c8073a4680468a6adee9efbd7a7c9 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 18 Sep 2023 15:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=90=AF=E5=8A=A8=EF=BC=8C?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=96=B0=E5=A2=9E=E5=AD=97=E5=85=B8=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A4=9A=E6=AC=A1=E5=8F=8D?= =?UTF-8?q?=E5=B0=84=E5=BD=B1=E5=93=8D=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/BaseWareHouseService.cs | 22 ++++++------------- system/Tnb.OAuth/OAuthService.cs | 11 ++++++++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index d31deb82..b822a7a6 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -62,25 +62,17 @@ namespace Tnb.WarehouseMgr static BaseWareHouseService() { - //_stroageMapLazy = new Lazy>(() => + var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList(); + foreach (var serviceType in serviceTypes) { - //Dictionary 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) + var callerName = serviceType.GetCustomAttribute()?.Name ?? string.Empty; + if (!callerName.IsNullOrEmpty()) { - var callerName = serviceType.GetCustomAttribute()?.Name ?? string.Empty; - if (!callerName.IsNullOrEmpty()) - { - var obj = Activator.CreateInstance(serviceType) as IWHStorageService; - if (obj == null) continue; - _storeMap[callerName] = obj; - } + var obj = Activator.CreateInstance(serviceType) as IWHStorageService; + if (obj == null) continue; + _storeMap[callerName] = obj; } - //return map; } - //); - - } protected Task GetUserIdentity(string? asscessToken = null) diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index 31ef6145..a1d76f02 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -144,6 +144,7 @@ public class OAuthService : IDynamicApiController, ITransient private readonly IMHandler _imHandler; private readonly BackgroundService _backgroundService; //added by ly on 20230916 + private static Dictionary _hostSvcRun = new(); @@ -294,11 +295,17 @@ public class OAuthService : IDynamicApiController, ITransient //modify by ly on 20230918 登录成功后启动定时服务 if (!userId.IsNullOrWhiteSpace()) { - var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); - if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted) + if (!_hostSvcRun.TryGetValue("IsStarted", out bool isStarted)) + { + var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); + isStarted = Convert.ToBoolean(isStartedProperty?.GetValue(_backgroundService)); + _hostSvcRun["IsStarted"] = isStarted; + } + if (!isStarted) { await _backgroundService.StartAsync(CancellationToken.None); } + }