diff --git a/Directory.Build.props b/Directory.Build.props index a2ce20e..a51c7e1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.2.0 + 1.2.1 enable github加速神器 https://github.com/dotnetcore/FastGithub diff --git a/FastGithub.Dns/DnsOverUdpHostedService.cs b/FastGithub.Dns/DnsOverUdpHostedService.cs index e2747ee..2f88f3a 100644 --- a/FastGithub.Dns/DnsOverUdpHostedService.cs +++ b/FastGithub.Dns/DnsOverUdpHostedService.cs @@ -50,7 +50,7 @@ namespace FastGithub.Dns { var dnsPort = this.options.CurrentValue.Listen.DnsPort; this.dnsOverUdpServer.Bind(IPAddress.Any, dnsPort); - this.logger.LogInformation("DNS服务启动成功"); + this.logger.LogInformation($"已监听udp端口{dnsPort},DNS服务启动完成"); const int STANDARD_DNS_PORT = 53; if (dnsPort == STANDARD_DNS_PORT) diff --git a/FastGithub.DomainResolve/DnscryptProxyHostedService.cs b/FastGithub.DomainResolve/DnscryptProxyHostedService.cs index 635f7b6..fdf70d9 100644 --- a/FastGithub.DomainResolve/DnscryptProxyHostedService.cs +++ b/FastGithub.DomainResolve/DnscryptProxyHostedService.cs @@ -37,7 +37,7 @@ namespace FastGithub.DomainResolve try { await this.dnscryptProxy.StartAsync(cancellationToken); - this.logger.LogInformation($"{this.dnscryptProxy}启动成功"); + this.logger.LogInformation($"{this.dnscryptProxy}启动完成"); } catch (Exception ex) { diff --git a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs index 2df39bc..8c06047 100644 --- a/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs +++ b/FastGithub.ReverseProxy/KestrelServerOptionsExtensions.cs @@ -32,7 +32,7 @@ namespace FastGithub else { kestrel.Listen(IPAddress.Any, HTTP_PORT); - logger.LogInformation($"已监听http反向代理,访问 http://127.0.0.1 或本机其它任意ip可进入Dashboard"); + logger.LogInformation($"已监听tcp端口{HTTP_PORT},http反向代理启动完成"); } } @@ -63,7 +63,7 @@ namespace FastGithub certService.GetOrCreateServerCert(domain))); var logger = kestrel.GetLogger(); - logger.LogInformation($"已监听https反向代理,访问 https://127.0.0.1 或本机其它任意ip可进入Dashboard"); + logger.LogInformation($"已监听tcp端口{HTTPS_PORT},https反向代理启动完成"); } /// @@ -83,7 +83,7 @@ namespace FastGithub else { kestrel.Listen(IPAddress.Any, sshPort, listen => listen.UseConnectionHandler()); - logger.LogInformation("已监听github的ssh代理"); + logger.LogInformation($"已监听tcp端口{sshPort},github的ssh代理启动完成"); } } diff --git a/FastGithub/Models/Home.cs b/FastGithub/Models/Home.cs index 4a5687c..023d107 100644 --- a/FastGithub/Models/Home.cs +++ b/FastGithub/Models/Home.cs @@ -1,6 +1,4 @@ -using System.Reflection; - -namespace FastGithub.Models +namespace FastGithub.Models { /// /// 首页模型 @@ -10,7 +8,7 @@ namespace FastGithub.Models /// /// 获取版本号 /// - public string? Version { get; } = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion; + public string? Version { get; } = ProductionVersion.Current?.ToString(); /// /// 请求域名或ip diff --git a/FastGithub/ProductionVersion.cs b/FastGithub/ProductionVersion.cs new file mode 100644 index 0000000..2b8fb70 --- /dev/null +++ b/FastGithub/ProductionVersion.cs @@ -0,0 +1,103 @@ +using System; +using System.Reflection; +using System.Text.RegularExpressions; + +namespace FastGithub +{ + /// + /// 表示产品版本 + /// + public class ProductionVersion : IComparable + { + private static readonly string? productionVersion = Assembly + .GetEntryAssembly()? + .GetCustomAttribute()? + .InformationalVersion; + + /// + /// 获取当前应用程序的产品版本 + /// + public static ProductionVersion? Current { get; } = productionVersion == null ? null : Parse(productionVersion); + + + /// + /// 版本 + /// + public Version Version { get; } + + /// + /// 子版本 + /// + public string SubVersion { get; } + + /// + /// 产品版本 + /// + /// + /// + public ProductionVersion(Version version, string subVersion) + { + this.Version = version; + this.SubVersion = subVersion; + } + + /// + /// 比较版本 + /// + /// + /// + 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}"; + } + + /// + /// 解析 + /// + /// + /// + 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); + } + } +} diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs index bd0d3e6..185753a 100644 --- a/FastGithub/Startup.cs +++ b/FastGithub/Startup.cs @@ -36,6 +36,7 @@ namespace FastGithub services.AddReverseProxy(); services.AddControllersWithViews(); + services.AddHostedService(); } /// diff --git a/FastGithub/VersonHostedService.cs b/FastGithub/VersonHostedService.cs new file mode 100644 index 0000000..ffbb3f7 --- /dev/null +++ b/FastGithub/VersonHostedService.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System.Threading; +using System.Threading.Tasks; + +namespace FastGithub +{ + sealed class VersonHostedService : IHostedService + { + private readonly ILogger logger; + + public VersonHostedService(ILogger logger) + { + this.logger = logger; + } + + public Task StartAsync(CancellationToken cancellationToken) + { + var version = ProductionVersion.Current; + this.logger.LogInformation($"{nameof(FastGithub)}启动完成,当前版本为v{version}"); + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } +} diff --git a/FastGithub/Views/Home/Index.cshtml b/FastGithub/Views/Home/Index.cshtml index 1ab8e20..7dd11c7 100644 --- a/FastGithub/Views/Home/Index.cshtml +++ b/FastGithub/Views/Home/Index.cshtml @@ -12,16 +12,6 @@ FastGithub - -