diff --git a/FastGithub.DomainResolve/DomainResolveServiceCollectionExtensions.cs b/FastGithub.DomainResolve/DomainResolveServiceCollectionExtensions.cs index 3e7c97f..06d5e83 100644 --- a/FastGithub.DomainResolve/DomainResolveServiceCollectionExtensions.cs +++ b/FastGithub.DomainResolve/DomainResolveServiceCollectionExtensions.cs @@ -18,7 +18,7 @@ namespace FastGithub { services.AddMemoryCache(); services.TryAddSingleton(); - services.AddSingleton(); + services.TryAddSingleton(); services.AddHostedService(); return services; } diff --git a/FastGithub.Upgrade/GithubRelease.cs b/FastGithub.Upgrade/GithubRelease.cs index 6020c40..cf076a9 100644 --- a/FastGithub.Upgrade/GithubRelease.cs +++ b/FastGithub.Upgrade/GithubRelease.cs @@ -8,7 +8,7 @@ namespace FastGithub.Upgrade /// /// 发行记录 /// - sealed class GithubRelease + public class GithubRelease { /// /// 标签名 diff --git a/FastGithub.Upgrade/UpgradeHostedService.cs b/FastGithub.Upgrade/UpgradeHostedService.cs deleted file mode 100644 index 35fa681..0000000 --- a/FastGithub.Upgrade/UpgradeHostedService.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace FastGithub.Upgrade -{ - /// - /// 升级后台服务 - /// - sealed class UpgradeHostedService : BackgroundService - { - private readonly UpgradeService upgradeService; - private readonly ILogger logger; - - /// - /// 升级后台服务 - /// - /// - public UpgradeHostedService( - UpgradeService upgradeService, - ILogger logger) - { - this.upgradeService = upgradeService; - this.logger = logger; - } - - /// - /// 检测版本 - /// - /// - /// - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - try - { - await this.upgradeService.UpgradeAsync(stoppingToken); - } - catch (Exception ex) - { - this.logger.LogWarning($"升级失败:{ex.Message}"); - } - } - } -} diff --git a/FastGithub.Upgrade/UpgradeService.cs b/FastGithub.Upgrade/UpgradeService.cs index ed12903..4ddcf73 100644 --- a/FastGithub.Upgrade/UpgradeService.cs +++ b/FastGithub.Upgrade/UpgradeService.cs @@ -12,7 +12,7 @@ namespace FastGithub.Upgrade /// /// 升级服务 /// - sealed class UpgradeService + public class UpgradeService { private readonly IDomainResolver domainResolver; private readonly ILogger logger; @@ -58,7 +58,7 @@ namespace FastGithub.Upgrade } else { - this.logger.LogInformation($"当前版本{currentVersion}为最新版本"); + this.logger.LogInformation($"当前版本{currentVersion}已经是最新版本"); } } diff --git a/FastGithub.Upgrade/UpgradeServiceCollectionExtensions.cs b/FastGithub.Upgrade/UpgradeServiceCollectionExtensions.cs deleted file mode 100644 index 600fd9b..0000000 --- a/FastGithub.Upgrade/UpgradeServiceCollectionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using FastGithub.Upgrade; -using Microsoft.Extensions.DependencyInjection; - -namespace FastGithub -{ - /// - /// 服务注册扩展 - /// - public static class DnsServiceCollectionExtensions - { - /// - /// 注册升级后台服务 - /// - /// - /// - public static IServiceCollection AddAppUpgrade(this IServiceCollection services) - { - return services - .AddHttpClient() - .AddSingleton() - .AddHostedService(); - } - } -} diff --git a/FastGithub/HostedService.cs b/FastGithub/HostedService.cs index 8658c5a..738463c 100644 --- a/FastGithub/HostedService.cs +++ b/FastGithub/HostedService.cs @@ -1,5 +1,7 @@ -using Microsoft.Extensions.Hosting; +using FastGithub.Upgrade; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using System; using System.Threading; using System.Threading.Tasks; @@ -8,39 +10,43 @@ namespace FastGithub /// /// Host服务 /// - sealed class HostedService : IHostedService + sealed class HostedService : BackgroundService { + private readonly UpgradeService upgradeService; private readonly ILogger logger; /// /// Host服务 /// + /// /// - public HostedService(ILogger logger) + public HostedService( + UpgradeService upgradeService, + ILogger logger) { + this.upgradeService = upgradeService; this.logger = logger; } /// - /// 启动服务 + /// 后台任务 /// - /// + /// /// - public Task StartAsync(CancellationToken cancellationToken) + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - var localhost = "https://127.0.0.1"; - this.logger.LogInformation($"{nameof(FastGithub)}启动完成,访问{localhost}或本机任意ip可查看使用说明"); - return Task.CompletedTask; - } - - /// - /// 停止服务 - /// - /// - /// - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; + try + { + await this.upgradeService.UpgradeAsync(stoppingToken); + } + catch (Exception ex) + { + this.logger.LogWarning($"升级检测失败:{ex.Message}"); + } + finally + { + this.logger.LogInformation($"{nameof(FastGithub)}启动完成,访问https://127.0.0.1或本机其它任意ip可进入Dashboard"); + } } } } diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs index f35c446..7ef5a5e 100644 --- a/FastGithub/Startup.cs +++ b/FastGithub/Startup.cs @@ -1,3 +1,4 @@ +using FastGithub.Upgrade; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -30,9 +31,11 @@ namespace FastGithub services.AddDomainResolve(); services.AddHttpClient(); services.AddReverseProxy(); - services.AddAppUpgrade(); + services.AddSingleton(); services.Configure(this.Configuration.GetSection(nameof(FastGithub))); + + services.AddSingleton(); services.AddHostedService(); services.AddControllersWithViews(); diff --git a/FastGithub/Views/Home/Index.cshtml b/FastGithub/Views/Home/Index.cshtml index cfd0e06..4583d6f 100644 --- a/FastGithub/Views/Home/Index.cshtml +++ b/FastGithub/Views/Home/Index.cshtml @@ -34,7 +34,7 @@ v@(ProductionVersion.GetAppVersion())

- 平台地址: + 项目地址: https://github.com/xljiulang/FastGithub

@@ -42,7 +42,7 @@

CA证书

- 你可能需要下载FastGithub自颁发的CA证书,根据设备所使用的平台要求,导入到受信任的根证书颁发机构或浏览器 + 你可能需要下载FastGithub自颁发的CA证书,根据设备所使用的平台要求,导入到受信任的根证书颁发机构或浏览器

部署方式