老九 4 年之前
父節點
當前提交
3f8a517a7c

+ 1 - 1
Directory.Build.props

@@ -1,6 +1,6 @@
 <Project>
 	<PropertyGroup>
-		<Version>1.2.0</Version>
+		<Version>1.2.1</Version>
 		<Nullable>enable</Nullable>
 		<Description>github加速神器</Description>
 		<Copyright>https://github.com/dotnetcore/FastGithub</Copyright>

+ 1 - 1
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)

+ 1 - 1
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)
             {

+ 3 - 3
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反向代理启动完成");
         }
 
         /// <summary>
@@ -83,7 +83,7 @@ namespace FastGithub
             else
             {
                 kestrel.Listen(IPAddress.Any, sshPort, listen => listen.UseConnectionHandler<GithubSshProxyHandler>());
-                logger.LogInformation("已监听github的ssh代理");
+                logger.LogInformation($"已监听tcp端口{sshPort},github的ssh代理启动完成");
             }
         }
 

+ 2 - 4
FastGithub/Models/Home.cs

@@ -1,6 +1,4 @@
-using System.Reflection;
-
-namespace FastGithub.Models
+namespace FastGithub.Models
 {
     /// <summary>
     /// 首页模型
@@ -10,7 +8,7 @@ namespace FastGithub.Models
         /// <summary>
         /// 获取版本号
         /// </summary>
-        public string? Version { get; } = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
+        public string? Version { get; } = ProductionVersion.Current?.ToString();
 
         /// <summary>
         /// 请求域名或ip

+ 103 - 0
FastGithub/ProductionVersion.cs

@@ -0,0 +1,103 @@
+using System;
+using System.Reflection;
+using System.Text.RegularExpressions;
+
+namespace FastGithub
+{
+    /// <summary>
+    /// 表示产品版本
+    /// </summary>
+    public class ProductionVersion : IComparable<ProductionVersion>
+    {
+        private static readonly string? productionVersion = Assembly
+            .GetEntryAssembly()?
+            .GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
+            .InformationalVersion;
+
+        /// <summary>
+        /// 获取当前应用程序的产品版本
+        /// </summary>
+        public static ProductionVersion? Current { get; } = productionVersion == null ? null : Parse(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);
+        }
+    }
+}

+ 1 - 0
FastGithub/Startup.cs

@@ -36,6 +36,7 @@ namespace FastGithub
             services.AddReverseProxy();
 
             services.AddControllersWithViews();
+            services.AddHostedService<VersonHostedService>();
         }
 
         /// <summary>

+ 29 - 0
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<VersonHostedService> logger;
+
+        public VersonHostedService(ILogger<VersonHostedService> 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;
+        }
+    }
+}

+ 0 - 10
FastGithub/Views/Home/Index.cshtml

@@ -12,16 +12,6 @@
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href=" https://cdn.jsdelivr.net/npm/@@bootcss/v3.bootcss.com@@1.0.10/dist/css/bootstrap.min.css">
     <title>FastGithub</title>
-
-    <style type="text/css">
-        .os {
-            text-align: center;
-            background-color: #ddd;
-            padding: 12px 0;
-            font-size: 24px;
-            color: #606060;
-        }
-    </style>
 </head>
 
 <body>