修改升级检测

This commit is contained in:
xljiulang 2021-07-27 20:23:02 +08:00
parent 8eac0dd5c0
commit 696c0f9dd8
8 changed files with 35 additions and 96 deletions

View File

@ -18,7 +18,7 @@ namespace FastGithub
{
services.AddMemoryCache();
services.TryAddSingleton<IDomainResolver, DomainResolver>();
services.AddSingleton<DnscryptProxyService>();
services.TryAddSingleton<DnscryptProxyService>();
services.AddHostedService<DnscryptProxyHostedService>();
return services;
}

View File

@ -8,7 +8,7 @@ namespace FastGithub.Upgrade
/// <summary>
/// 发行记录
/// </summary>
sealed class GithubRelease
public class GithubRelease
{
/// <summary>
/// 标签名

View File

@ -1,46 +0,0 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace FastGithub.Upgrade
{
/// <summary>
/// 升级后台服务
/// </summary>
sealed class UpgradeHostedService : BackgroundService
{
private readonly UpgradeService upgradeService;
private readonly ILogger<UpgradeHostedService> logger;
/// <summary>
/// 升级后台服务
/// </summary>
/// <param name="logger"></param>
public UpgradeHostedService(
UpgradeService upgradeService,
ILogger<UpgradeHostedService> logger)
{
this.upgradeService = upgradeService;
this.logger = logger;
}
/// <summary>
/// 检测版本
/// </summary>
/// <param name="stoppingToken"></param>
/// <returns></returns>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
await this.upgradeService.UpgradeAsync(stoppingToken);
}
catch (Exception ex)
{
this.logger.LogWarning($"升级失败:{ex.Message}");
}
}
}
}

View File

@ -12,7 +12,7 @@ namespace FastGithub.Upgrade
/// <summary>
/// 升级服务
/// </summary>
sealed class UpgradeService
public class UpgradeService
{
private readonly IDomainResolver domainResolver;
private readonly ILogger<UpgradeService> logger;
@ -58,7 +58,7 @@ namespace FastGithub.Upgrade
}
else
{
this.logger.LogInformation($"当前版本{currentVersion}最新版本");
this.logger.LogInformation($"当前版本{currentVersion}已经是最新版本");
}
}

View File

@ -1,24 +0,0 @@
using FastGithub.Upgrade;
using Microsoft.Extensions.DependencyInjection;
namespace FastGithub
{
/// <summary>
/// 服务注册扩展
/// </summary>
public static class DnsServiceCollectionExtensions
{
/// <summary>
/// 注册升级后台服务
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddAppUpgrade(this IServiceCollection services)
{
return services
.AddHttpClient()
.AddSingleton<UpgradeService>()
.AddHostedService<UpgradeHostedService>();
}
}
}

View File

@ -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
/// <summary>
/// Host服务
/// </summary>
sealed class HostedService : IHostedService
sealed class HostedService : BackgroundService
{
private readonly UpgradeService upgradeService;
private readonly ILogger<HostedService> logger;
/// <summary>
/// Host服务
/// </summary>
/// <param name="upgradeService"></param>
/// <param name="logger"></param>
public HostedService(ILogger<HostedService> logger)
public HostedService(
UpgradeService upgradeService,
ILogger<HostedService> logger)
{
this.upgradeService = upgradeService;
this.logger = logger;
}
/// <summary>
/// 启动服
/// 后台任
/// </summary>
/// <param name="cancellationToken"></param>
/// <param name="stoppingToken"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 停止服务
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
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");
}
}
}
}

View File

@ -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<FastGithubConfig>();
services.Configure<FastGithubOptions>(this.Configuration.GetSection(nameof(FastGithub)));
services.AddSingleton<UpgradeService>();
services.AddHostedService<HostedService>();
services.AddControllersWithViews();

View File

@ -34,7 +34,7 @@
<span>v@(ProductionVersion.GetAppVersion())</span>
</p>
<p>
<span>平台地址:</span>
<span>项目地址:</span>
<a target="_blank" href="https://github.com/xljiulang/FastGithub">https://github.com/xljiulang/FastGithub</a>
</p>
@ -42,7 +42,7 @@
<h3>CA证书</h3>
<p>
你可能需要<a target="_blank" href="/cert">下载FastGithub自颁发的CA证书</a>,根据设备所使用的平台要求,导入到受信任的根证书颁发机构或浏览器
你可能需要下载<a target="_blank" href="/cert">FastGithub自颁发的CA证书</a>,根据设备所使用的平台要求,导入到受信任的根证书颁发机构或浏览器
</p>
<h3>部署方式</h3>