mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-28 22:23:59 +08:00
!36 release:6.0.5.2
* feat: 增加IHostApplicationLifetime实现 * fix(FAIconList): js位置错误
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -136,7 +136,6 @@ public class AuthService : IAuthService
|
|||||||
/// <param name="loginPolicy">登录策略</param>
|
/// <param name="loginPolicy">登录策略</param>
|
||||||
/// <param name="input">用户登录参数</param>
|
/// <param name="input">用户登录参数</param>
|
||||||
/// <param name="sysUser">用户信息</param>
|
/// <param name="sysUser">用户信息</param>
|
||||||
/// <param name="isCookie">cookie方式登录</param>
|
|
||||||
/// <returns>登录输出结果</returns>
|
/// <returns>登录输出结果</returns>
|
||||||
private async Task<LoginOutput> ExecLogin(LoginPolicy loginPolicy, LoginInput input, SysUser sysUser)
|
private async Task<LoginOutput> ExecLogin(LoginPolicy loginPolicy, LoginInput input, SysUser sysUser)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ using System.Text;
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
|
|
||||||
|
using ThingsGateway.Admin.NetCore;
|
||||||
|
|
||||||
namespace ThingsGateway.Photino;
|
namespace ThingsGateway.Photino;
|
||||||
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
internal static CancellationTokenSource CancellationTokenSource = new();
|
|
||||||
internal static CancellationToken CancellationToken = CancellationTokenSource.Token;
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
@@ -69,11 +69,36 @@ internal class Program
|
|||||||
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
|
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
StartHostedService(app.Services);
|
||||||
app.Run();
|
app.Run();
|
||||||
CancellationTokenSource.Cancel();
|
StopHostedService(app.Services);
|
||||||
CancellationTokenSource.Dispose();
|
|
||||||
var _hostedServiceExecutor = app.Services.GetRequiredService<HostedServiceExecutor>();
|
|
||||||
_hostedServiceExecutor.StopAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
|
|
||||||
using ThingsGateway.Admin.Application;
|
using ThingsGateway.Admin.Application;
|
||||||
@@ -59,6 +60,10 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
private void ConfigureAdminApp(IServiceCollection services)
|
private void ConfigureAdminApp(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddSingleton<IHostApplicationLifetime, ApplicationLifetime>();
|
||||||
|
services.AddSingleton<ApplicationLifetime>();
|
||||||
|
|
||||||
|
services.AddSingleton<IAuthService, AuthService>();
|
||||||
|
|
||||||
services.AddSingleton<IAuthService, AuthService>();
|
services.AddSingleton<IAuthService, AuthService>();
|
||||||
services.AddSingleton<IAuthRazorService, AuthRazorService>();
|
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>6.0.5.1</Version>
|
<Version>6.0.5.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace ThingsGateway.Razor;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// FAIconList 组件
|
/// FAIconList 组件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JSModuleAutoLoader("Components/ThemeToggle.razor.js", JSObjectReference = true)]
|
[JSModuleAutoLoader("Components/FAIconList.razor.js", JSObjectReference = true)]
|
||||||
public partial class FAIconList : IAsyncDisposable
|
public partial class FAIconList : IAsyncDisposable
|
||||||
{
|
{
|
||||||
private string? ClassString => CssBuilder.Default("icon-list")
|
private string? ClassString => CssBuilder.Default("icon-list")
|
||||||
|
|||||||
Reference in New Issue
Block a user