1.0.0-rc1
This commit is contained in:
parent
15851e6850
commit
16c34fbc96
@ -4,7 +4,7 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||||
<Version>1.0.0-beta4</Version>
|
<Version>1.0.0-rc1</Version>
|
||||||
<Description>github定制版的dns服务,解析github最优的ip</Description>
|
<Description>github定制版的dns服务,解析github最优的ip</Description>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<Copyright>https://github.com/xljiulang/FastGithub</Copyright>
|
<Copyright>https://github.com/xljiulang/FastGithub</Copyright>
|
||||||
@ -25,7 +25,7 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="README.MD">
|
<None Update="README.MD">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace FastGithub
|
namespace FastGithub
|
||||||
{
|
{
|
||||||
@ -25,7 +26,8 @@ namespace FastGithub
|
|||||||
.UseWindowsService()
|
.UseWindowsService()
|
||||||
.UseBinaryPathContentRoot()
|
.UseBinaryPathContentRoot()
|
||||||
.ConfigureServices((ctx, services) =>
|
.ConfigureServices((ctx, services) =>
|
||||||
{
|
{
|
||||||
|
services.AddHostedService<VersionHostedService>();
|
||||||
services.AddGithubDns(ctx.Configuration);
|
services.AddGithubDns(ctx.Configuration);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
94
FastGithub/VersionHostedService.cs
Normal file
94
FastGithub/VersionHostedService.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FastGithub
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 版本检查
|
||||||
|
/// </summary>
|
||||||
|
sealed class VersionHostedService : IHostedService
|
||||||
|
{
|
||||||
|
private readonly ILogger<VersionHostedService> logger;
|
||||||
|
|
||||||
|
public VersionHostedService(ILogger<VersionHostedService> logger)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return this.CheckVersionAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测新版本
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CheckVersionAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var version = Assembly.GetEntryAssembly()?.GetName().Version;
|
||||||
|
if (version == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var httpClient = new HttpClient();
|
||||||
|
var uri = "https://gitee.com/api/v5/repos/jiulang/fast-github/releases?page=1&per_page=1&direction=desc";
|
||||||
|
var results = await httpClient.GetFromJsonAsync<Release[]>(uri, cancellationToken);
|
||||||
|
var release = results?.FirstOrDefault();
|
||||||
|
if (release == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.Equals(release.tag_name, version.ToString(), StringComparison.OrdinalIgnoreCase) == false)
|
||||||
|
{
|
||||||
|
this.logger.LogInformation($"您正在使用{version}版本{Environment.NewLine}请前往https://gitee.com/jiulang/fast-github/releases下载新版本");
|
||||||
|
this.logger.LogInformation(release.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning($"检测升级信息失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发行记录
|
||||||
|
/// </summary>
|
||||||
|
private class Release
|
||||||
|
{
|
||||||
|
public string tag_name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string body { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime created_at { get; set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return new StringBuilder()
|
||||||
|
.Append("最新版本:").AppendLine(this.tag_name)
|
||||||
|
.Append("发布时间:").AppendLine(this.created_at.ToString())
|
||||||
|
.AppendLine("更新内容:").AppendLine(this.body)
|
||||||
|
.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user