This commit is contained in:
alex
2023-09-19 09:14:41 +08:00
parent 18b72a8bad
commit 767076a513

View File

@@ -44,6 +44,7 @@ using Aop.Api.Domain;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using bf = System.Reflection.BindingFlags;
using System.Linq.Expressions;
namespace JNPF.OAuth;
@@ -145,6 +146,7 @@ public class OAuthService : IDynamicApiController, ITransient
private readonly BackgroundService _backgroundService; //added by ly on 20230916
private static CancellationTokenSource stopTimedTaskSvcCTS = new();
private static Dictionary<string, Func<BackgroundService, object>> _fetchPropValue = new();
/// <summary>
@@ -295,14 +297,25 @@ public class OAuthService : IDynamicApiController, ITransient
if (!userId.IsNullOrWhiteSpace())
{
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
//if (!_fetchPropValue.TryGetValue("IsStarted", out var action))
//{
// var isStartedProp = _backgroundService.GetType().GetProperty("IsStarted");
// var paramExp = Expression.Parameter(typeof(BackgroundService), "_backgroundSvc");
// var propExp = Expression.Property(paramExp, isStartedProp);
// var body = Expression.Lambda<Func<BackgroundService, object>>(propExp, paramExp);
// action = body.Compile();
// _fetchPropValue["IsStarted"] = action;
//}
//if(!action?.Invoke(_backgroundService)?.ParseToBool() ?? false)
//{
// await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token);
//}
if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted)
{
await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token);
}
}
var loginOutput = new CurrentUserOutput();
loginOutput.userInfo = await _userManager.GetUserInfo();