1.0.0-rc1

This commit is contained in:
xljiulang 2021-06-20 10:58:27 +08:00
parent 15851e6850
commit 16c34fbc96
3 changed files with 100 additions and 4 deletions

View File

@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<Version>1.0.0-beta4</Version>
<Version>1.0.0-rc1</Version>
<Description>github定制版的dns服务解析github最优的ip</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>https://github.com/xljiulang/FastGithub</Copyright>

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace FastGithub
{
@ -26,6 +27,7 @@ namespace FastGithub
.UseBinaryPathContentRoot()
.ConfigureServices((ctx, services) =>
{
services.AddHostedService<VersionHostedService>();
services.AddGithubDns(ctx.Configuration);
});
}

View 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();
}
}
}
}