移除升级服务,因为没有实际的升级功能

This commit is contained in:
xljiulang 2021-07-27 21:30:55 +08:00
parent 04f8d77aaf
commit c73e219acf
10 changed files with 62 additions and 60 deletions

View File

@ -23,11 +23,16 @@ namespace FastGithub.ReverseProxy
this.logger = logger;
}
/// <summary>
/// 服务启动时
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task StartAsync(CancellationToken cancellationToken)
{
const int HTTPSPORT = 443;
if (OperatingSystem.IsWindows())
{
const int HTTPSPORT = 443;
if (TcpTable.TryGetOwnerProcessId(HTTPSPORT, out var pid))
{
try
@ -47,6 +52,11 @@ namespace FastGithub.ReverseProxy
return Task.CompletedTask;
}
/// <summary>
/// 服务停止时
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;

View File

@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub", "FastGithub\Fa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Dns", "FastGithub.Dns\FastGithub.Dns.csproj", "{43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Upgrade", "FastGithub.Upgrade\FastGithub.Upgrade.csproj", "{8239A077-A84C-4FDF-A204-02A2DE4243F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.ReverseProxy", "FastGithub.ReverseProxy\FastGithub.ReverseProxy.csproj", "{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGithub.Http", "FastGithub.Http\FastGithub.Http.csproj", "{B5DCB3E4-5094-4170-B844-6F395002CA42}"
@ -31,10 +29,6 @@ Global
{43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43FF9C79-51D5-4037-AA0B-CA3006E2A7E6}.Release|Any CPU.Build.0 = Release|Any CPU
{8239A077-A84C-4FDF-A204-02A2DE4243F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8239A077-A84C-4FDF-A204-02A2DE4243F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8239A077-A84C-4FDF-A204-02A2DE4243F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8239A077-A84C-4FDF-A204-02A2DE4243F3}.Release|Any CPU.Build.0 = Release|Any CPU
{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28326D0F-B0FB-4B6B-A65A-C69ACB72CAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace FastGithub.Controllers
{
/// <summary>
/// 证书控制器
/// </summary>
public class CertController : Controller
{
/// <summary>

View File

@ -1,10 +1,11 @@
using Microsoft.AspNetCore.Http;
using FastGithub.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace FastGithub.Controllers
{
/// <summary>
/// 首页控制器
/// </summary>
public class HomeController : Controller
{
/// <summary>
@ -13,20 +14,8 @@ namespace FastGithub.Controllers
/// <returns></returns>
public IActionResult Index()
{
return View();
}
/// <summary>
/// 下载CA证书
/// </summary>
/// <returns></returns>
public async Task<IActionResult> Cert()
{
var certFile = $"CACert/{nameof(FastGithub)}.cer";
this.Response.ContentType = "application/x-x509-ca-cert";
this.Response.Headers.Add("Content-Disposition", $"attachment;filename={nameof(FastGithub)}.cer");
await this.Response.SendFileAsync(certFile);
return new EmptyResult();
}
var model = new Home();
return View(model);
}
}
}

View File

@ -19,7 +19,6 @@
<ProjectReference Include="..\FastGithub.Dns\FastGithub.Dns.csproj" />
<ProjectReference Include="..\FastGithub.DomainResolve\FastGithub.DomainResolve.csproj" />
<ProjectReference Include="..\FastGithub.ReverseProxy\FastGithub.ReverseProxy.csproj" />
<ProjectReference Include="..\FastGithub.Upgrade\FastGithub.Upgrade.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -1,52 +1,46 @@
using FastGithub.Upgrade;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace FastGithub
{
/// <summary>
/// Host服务
/// 后台服务
/// </summary>
sealed class HostedService : BackgroundService
sealed class HostedService : IHostedService
{
private readonly UpgradeService upgradeService;
private readonly ILogger<HostedService> logger;
/// <summary>
/// Host服务
/// 后台服务
/// </summary>
/// <param name="upgradeService"></param>
/// <param name="logger"></param>
public HostedService(
UpgradeService upgradeService,
ILogger<HostedService> logger)
public HostedService(ILogger<HostedService> logger)
{
this.upgradeService = upgradeService;
this.logger = logger;
}
/// <summary>
/// 后台任务
/// 服务启动时
/// </summary>
/// <param name="stoppingToken"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
public Task StartAsync(CancellationToken cancellationToken)
{
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");
}
this.logger.LogInformation($"{nameof(FastGithub)}启动完成访问https://127.0.0.1或本机其它任意ip可进入Dashboard");
return Task.CompletedTask;
}
/// <summary>
/// 服务停止时
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}

15
FastGithub/Models/Home.cs Normal file
View File

@ -0,0 +1,15 @@
using System.Reflection;
namespace FastGithub.Models
{
/// <summary>
/// 首页模型
/// </summary>
public class Home
{
/// <summary>
/// 获取版本号
/// </summary>
public string? Version { get; } = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
}
}

View File

@ -31,11 +31,9 @@ namespace FastGithub
services.AddDomainResolve();
services.AddHttpClient();
services.AddReverseProxy();
services.AddUpgrade();
services.AddHostedService<HostedService>();
services.AddHostedService<HostedService>();
services.AddControllersWithViews();
services.AddRouting(c => c.LowercaseUrls = true);
}
/// <summary>
@ -49,7 +47,7 @@ namespace FastGithub
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}");
});
}
}

View File

@ -2,7 +2,7 @@
@{
Layout = null;
}
@using FastGithub.Upgrade
@model Home
<!DOCTYPE html>
<html lang="zh-CN">
@ -31,7 +31,7 @@
<p>github加速神器</p>
<p>
<span>软件版本:</span>
<span>v@(ProductionVersion.GetAppVersion())</span>
<span>v@(Model?.Version)</span>
</p>
<p>
<span>项目地址:</span>

View File

@ -1,2 +1,3 @@
@using FastGithub
@using FastGithub
@using FastGithub.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers