移除upgrade相关代码
This commit is contained in:
parent
c73e219acf
commit
cbd12b69d5
@ -1,11 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0-*" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FastGithub.Http\FastGithub.Http.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace FastGithub.Upgrade
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 发行记录
|
|
||||||
/// </summary>
|
|
||||||
public class GithubRelease
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 标签名
|
|
||||||
/// </summary>
|
|
||||||
[JsonPropertyName("tag_name")]
|
|
||||||
public string TagName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否预览版本
|
|
||||||
/// </summary>
|
|
||||||
[JsonPropertyName("prerelease")]
|
|
||||||
public bool Prerelease { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发行说明
|
|
||||||
/// </summary>
|
|
||||||
[JsonPropertyName("body")]
|
|
||||||
public string Body { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发行时间
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
[JsonPropertyName("created_at")]
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 下载页面
|
|
||||||
/// </summary>
|
|
||||||
[AllowNull]
|
|
||||||
[JsonPropertyName("html_url")]
|
|
||||||
public Uri HtmlUrl { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取产品版本
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public ProductionVersion GetProductionVersion()
|
|
||||||
{
|
|
||||||
var version = this.TagName.TrimStart('v', 'V');
|
|
||||||
return ProductionVersion.Parse(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return new StringBuilder()
|
|
||||||
.Append("最新版本:").AppendLine(this.TagName)
|
|
||||||
.Append("发布时间:").AppendLine(this.CreatedAt.ToString())
|
|
||||||
.AppendLine("更新内容:").AppendLine(this.Body)
|
|
||||||
.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
|
|
||||||
namespace FastGithub.Upgrade
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// github请求消息
|
|
||||||
/// </summary>
|
|
||||||
class GithubRequestMessage : HttpRequestMessage
|
|
||||||
{
|
|
||||||
public GithubRequestMessage()
|
|
||||||
{
|
|
||||||
this.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
|
|
||||||
this.Headers.UserAgent.Add(new ProductInfoHeaderValue(nameof(FastGithub), "1.0"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace FastGithub.Upgrade
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 表示产品版本
|
|
||||||
/// </summary>
|
|
||||||
public class ProductionVersion : IComparable<ProductionVersion>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 版本
|
|
||||||
/// </summary>
|
|
||||||
public Version Version { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 子版本
|
|
||||||
/// </summary>
|
|
||||||
public string SubVersion { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 产品版本
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="version"></param>
|
|
||||||
/// <param name="subVersion"></param>
|
|
||||||
public ProductionVersion(Version version, string subVersion)
|
|
||||||
{
|
|
||||||
this.Version = version;
|
|
||||||
this.SubVersion = subVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 比较版本
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="other"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int CompareTo(ProductionVersion? other)
|
|
||||||
{
|
|
||||||
var x = this;
|
|
||||||
var y = other;
|
|
||||||
|
|
||||||
if (y == null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var value = x.Version.CompareTo(y.Version);
|
|
||||||
if (value == 0)
|
|
||||||
{
|
|
||||||
value = CompareSubVerson(x.SubVersion, y.SubVersion);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
|
|
||||||
static int CompareSubVerson(string subX, string subY)
|
|
||||||
{
|
|
||||||
if (subX.Length == 0 && subY.Length == 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (subX.Length == 0)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (subY.Length == 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return StringComparer.OrdinalIgnoreCase.Compare(subX, subY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{Version}{SubVersion}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="productionVersion"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ProductionVersion Parse(string productionVersion)
|
|
||||||
{
|
|
||||||
const string VERSION = @"^\d+\.(\d+.){0,2}\d+";
|
|
||||||
var verion = Regex.Match(productionVersion, VERSION).Value;
|
|
||||||
var subVersion = productionVersion[verion.Length..];
|
|
||||||
return new ProductionVersion(Version.Parse(verion), subVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取当前应用程序的产品版本
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static ProductionVersion? GetAppVersion()
|
|
||||||
{
|
|
||||||
var version = Assembly
|
|
||||||
.GetEntryAssembly()?
|
|
||||||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
|
||||||
.InformationalVersion;
|
|
||||||
|
|
||||||
return version == null ? null : Parse(version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
using FastGithub.Upgrade;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
|
|
||||||
namespace FastGithub
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 服务注册扩展
|
|
||||||
/// </summary>
|
|
||||||
public static class ServiceCollectionExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 添加升级服务
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IServiceCollection AddUpgrade(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.TryAddSingleton<UpgradeService>();
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,90 +0,0 @@
|
|||||||
using FastGithub.Configuration;
|
|
||||||
using FastGithub.DomainResolve;
|
|
||||||
using FastGithub.Http;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace FastGithub.Upgrade
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 升级服务
|
|
||||||
/// </summary>
|
|
||||||
public class UpgradeService
|
|
||||||
{
|
|
||||||
private readonly IDomainResolver domainResolver;
|
|
||||||
private readonly ILogger<UpgradeService> logger;
|
|
||||||
private readonly Uri releasesUri = new("https://api.github.com/repos/xljiulang/fastgithub/releases");
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 升级服务
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="domainResolver"></param>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
public UpgradeService(
|
|
||||||
IDomainResolver domainResolver,
|
|
||||||
ILogger<UpgradeService> logger)
|
|
||||||
{
|
|
||||||
this.domainResolver = domainResolver;
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 进行升级
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task UpgradeAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var currentVersion = ProductionVersion.GetAppVersion();
|
|
||||||
if (currentVersion == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lastRelease = await this.GetLastedReleaseAsync(cancellationToken);
|
|
||||||
if (lastRelease == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lastedVersion = lastRelease.GetProductionVersion();
|
|
||||||
if (lastedVersion.CompareTo(currentVersion) > 0)
|
|
||||||
{
|
|
||||||
this.logger.LogInformation($"当前版本{currentVersion}为老版本{Environment.NewLine}请前往{lastRelease.HtmlUrl}下载新版本");
|
|
||||||
this.logger.LogInformation(lastRelease.ToString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.logger.LogInformation($"当前版本{currentVersion}已经是最新版本");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取最新发布
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<GithubRelease?> GetLastedReleaseAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var domainConfig = new DomainConfig
|
|
||||||
{
|
|
||||||
TlsSni = false,
|
|
||||||
TlsIgnoreNameMismatch = true,
|
|
||||||
Timeout = TimeSpan.FromSeconds(30d)
|
|
||||||
};
|
|
||||||
|
|
||||||
using var request = new GithubRequestMessage
|
|
||||||
{
|
|
||||||
RequestUri = this.releasesUri
|
|
||||||
};
|
|
||||||
|
|
||||||
using var httpClient = new HttpClient(domainConfig, this.domainResolver);
|
|
||||||
var response = await httpClient.SendAsync(request, cancellationToken);
|
|
||||||
var releases = await response.Content.ReadFromJsonAsync<GithubRelease[]>(cancellationToken: cancellationToken);
|
|
||||||
return releases?.FirstOrDefault(item => item.Prerelease == false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user