!36 release:6.0.5.2

* feat: 增加IHostApplicationLifetime实现
* fix(FAIconList): js位置错误
This commit is contained in:
Diego2098
2024-08-12 16:02:37 +00:00
parent 375377fef9
commit debbb049b0
6 changed files with 126 additions and 16 deletions

View File

@@ -0,0 +1,88 @@
// ------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://kimdiego2098.github.io/
// QQ群605534569
// ------------------------------------------------------------------------------
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ThingsGateway.Admin.NetCore;
public sealed class ApplicationLifetime : IHostApplicationLifetime
{
private readonly CancellationTokenSource _startedSource = new CancellationTokenSource();
private readonly CancellationTokenSource _stoppingSource = new CancellationTokenSource();
private readonly CancellationTokenSource _stoppedSource = new CancellationTokenSource();
private readonly ILogger<ApplicationLifetime> _logger;
public ApplicationLifetime(ILogger<ApplicationLifetime> logger)
{
_logger = logger;
}
/// <summary>
/// Triggered when the application host has fully started and is about to wait
/// for a graceful shutdown.
/// </summary>
public CancellationToken ApplicationStarted => _startedSource.Token;
/// <summary>
/// Triggered when the application host is performing a graceful shutdown.
/// Request may still be in flight. Shutdown will block until this event completes.
/// </summary>
public CancellationToken ApplicationStopping => _stoppingSource.Token;
/// <summary>
/// Triggered when the application host is performing a graceful shutdown.
/// All requests should be complete at this point. Shutdown will block
/// until this event completes.
/// </summary>
public CancellationToken ApplicationStopped => _stoppedSource.Token;
/// <summary>
/// Signals the ApplicationStopping event and blocks until it completes.
/// </summary>
public void StopApplication()
{
// Lock on CTS to synchronize multiple calls to StopApplication. This guarantees that the first call
// to StopApplication and its callbacks run to completion before subsequent calls to StopApplication,
// which will no-op since the first call already requested cancellation, get a chance to execute.
lock (_stoppingSource)
{
ExecuteHandlers(_stoppingSource);
}
}
/// <summary>
/// Signals the ApplicationStarted event and blocks until it completes.
/// </summary>
public void NotifyStarted()
{
ExecuteHandlers(_startedSource);
}
/// <summary>
/// Signals the ApplicationStopped event and blocks until it completes.
/// </summary>
public void NotifyStopped()
{
ExecuteHandlers(_stoppedSource);
}
private static void ExecuteHandlers(CancellationTokenSource cancel)
{
// Noop if this is already cancelled
if (cancel.IsCancellationRequested)
{
return;
}
// Run the cancellation token callbacks
cancel.Cancel(throwOnFirstException: false);
}
}

View File

@@ -136,7 +136,6 @@ public class AuthService : IAuthService
/// <param name="loginPolicy">登录策略</param>
/// <param name="input">用户登录参数</param>
/// <param name="sysUser">用户信息</param>
/// <param name="isCookie">cookie方式登录</param>
/// <returns>登录输出结果</returns>
private async Task<LoginOutput> ExecLogin(LoginPolicy loginPolicy, LoginInput input, SysUser sysUser)
{

View File

@@ -17,12 +17,12 @@ using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using ThingsGateway.Admin.NetCore;
namespace ThingsGateway.Photino;
internal class Program
{
internal static CancellationTokenSource CancellationTokenSource = new();
internal static CancellationToken CancellationToken = CancellationTokenSource.Token;
[STAThread]
private static void Main(string[] args)
@@ -69,11 +69,36 @@ internal class Program
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
};
StartHostedService(app.Services);
app.Run();
CancellationTokenSource.Cancel();
CancellationTokenSource.Dispose();
var _hostedServiceExecutor = app.Services.GetRequiredService<HostedServiceExecutor>();
_hostedServiceExecutor.StopAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
StopHostedService(app.Services);
}
public static void StartHostedService(IServiceProvider serviceProvider)
{
var applicationLifetime = serviceProvider.GetRequiredService<ApplicationLifetime>();
var hostedServiceExecutor = serviceProvider.GetRequiredService<HostedServiceExecutor>();
// Fire IHostedService.Start
hostedServiceExecutor.StartAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
applicationLifetime.NotifyStarted();
}
public static void StopHostedService(IServiceProvider serviceProvider)
{
var applicationLifetime = serviceProvider.GetRequiredService<ApplicationLifetime>();
applicationLifetime.StopApplication();
var _hostedServiceExecutor = serviceProvider.GetRequiredService<HostedServiceExecutor>();
_hostedServiceExecutor.StopAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
applicationLifetime.NotifyStopped();
}
}

View File

@@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Localization;
using ThingsGateway.Admin.Application;
@@ -59,6 +60,10 @@ public class Startup : AppStartup
private void ConfigureAdminApp(IServiceCollection services)
{
services.AddSingleton<IHostApplicationLifetime, ApplicationLifetime>();
services.AddSingleton<ApplicationLifetime>();
services.AddSingleton<IAuthService, AuthService>();
services.AddSingleton<IAuthService, AuthService>();
services.AddSingleton<IAuthRazorService, AuthRazorService>();
@@ -82,13 +87,6 @@ public class Startup : AppStartup
}
public void UseAdminCore(IServiceProvider serviceProvider)
{
var _hostedServiceExecutor = serviceProvider.GetRequiredService<HostedServiceExecutor>();
// Fire IHostedService.Start
_hostedServiceExecutor.StartAsync(Program.CancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
}
}

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>6.0.5.1</Version>
<Version>6.0.5.2</Version>
</PropertyGroup>
<ItemGroup>

View File

@@ -15,7 +15,7 @@ namespace ThingsGateway.Razor;
/// <summary>
/// FAIconList 组件
/// </summary>
[JSModuleAutoLoader("Components/ThemeToggle.razor.js", JSObjectReference = true)]
[JSModuleAutoLoader("Components/FAIconList.razor.js", JSObjectReference = true)]
public partial class FAIconList : IAsyncDisposable
{
private string? ClassString => CssBuilder.Default("icon-list")