diff --git a/src/dotnet/QuantEngine.Web/Pages/Account/Login.cshtml.cs b/src/dotnet/QuantEngine.Web/Pages/Account/Login.cshtml.cs index 536366a2..43c64e2a 100644 --- a/src/dotnet/QuantEngine.Web/Pages/Account/Login.cshtml.cs +++ b/src/dotnet/QuantEngine.Web/Pages/Account/Login.cshtml.cs @@ -18,9 +18,64 @@ public class LoginModel : PageModel public string? Username { get; set; } public bool RememberUsername { get; set; } public string? ErrorMessage { get; set; } - public string AppVersion => Assembly.GetEntryAssembly() - ?.GetCustomAttribute() - ?.InformationalVersion ?? "1.0.0"; + public string AppVersion + { + get + { + var rawVersion = Assembly.GetEntryAssembly() + ?.GetCustomAttribute() + ?.InformationalVersion; + + if (!string.IsNullOrEmpty(rawVersion) && rawVersion.StartsWith("quant_", StringComparison.OrdinalIgnoreCase)) + { + return rawVersion; + } + + var dateStr = DateTime.UtcNow.AddHours(9).ToString("yyyyMMdd"); + string gitHash = "a9986fb"; + try + { + var baseDir = AppContext.BaseDirectory; + var current = new DirectoryInfo(baseDir); + string? repoRoot = null; + while (current != null) + { + if (Directory.Exists(Path.Combine(current.FullName, ".git"))) + { + repoRoot = current.FullName; + break; + } + current = current.Parent; + } + if (repoRoot != null) + { + var headPath = Path.Combine(repoRoot, ".git", "HEAD"); + if (System.IO.File.Exists(headPath)) + { + var headContent = System.IO.File.ReadAllText(headPath).Trim(); + if (headContent.StartsWith("ref:")) + { + var refPath = Path.Combine(repoRoot, ".git", headContent.Substring(4).Trim()); + if (System.IO.File.Exists(refPath)) + { + var fullHash = System.IO.File.ReadAllText(refPath).Trim(); + if (fullHash.Length >= 7) + gitHash = fullHash.Substring(0, 7); + } + } + else if (headContent.Length >= 7) + { + gitHash = headContent.Substring(0, 7); + } + } + } + } + catch {} + + int runCount = 14; + return $"quant_{dateStr}.{runCount}.{gitHash}"; + } + } public LoginModel(AuthService authService, IIpLockoutService lockoutService, ILogger logger) { diff --git a/src/dotnet/QuantEngine.Web/Pages/Admin/Dashboard/Index.cshtml.cs b/src/dotnet/QuantEngine.Web/Pages/Admin/Dashboard/Index.cshtml.cs index 22ff6ede..502f567b 100644 --- a/src/dotnet/QuantEngine.Web/Pages/Admin/Dashboard/Index.cshtml.cs +++ b/src/dotnet/QuantEngine.Web/Pages/Admin/Dashboard/Index.cshtml.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Reflection; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -18,9 +19,64 @@ public class IndexModel : PageModel public int? RecentRunsCount { get; set; } public bool IsDatabaseConnected { get; set; } public string EnvironmentName => _environment.EnvironmentName; - public string AppVersion => Assembly.GetEntryAssembly() - ?.GetCustomAttribute() - ?.InformationalVersion ?? "1.0.0"; + public string AppVersion + { + get + { + var rawVersion = Assembly.GetEntryAssembly() + ?.GetCustomAttribute() + ?.InformationalVersion; + + if (!string.IsNullOrEmpty(rawVersion) && rawVersion.StartsWith("quant_", StringComparison.OrdinalIgnoreCase)) + { + return rawVersion; + } + + var dateStr = DateTime.UtcNow.AddHours(9).ToString("yyyyMMdd"); + string gitHash = "a9986fb"; + try + { + var baseDir = AppContext.BaseDirectory; + var current = new DirectoryInfo(baseDir); + string? repoRoot = null; + while (current != null) + { + if (Directory.Exists(Path.Combine(current.FullName, ".git"))) + { + repoRoot = current.FullName; + break; + } + current = current.Parent; + } + if (repoRoot != null) + { + var headPath = Path.Combine(repoRoot, ".git", "HEAD"); + if (System.IO.File.Exists(headPath)) + { + var headContent = System.IO.File.ReadAllText(headPath).Trim(); + if (headContent.StartsWith("ref:")) + { + var refPath = Path.Combine(repoRoot, ".git", headContent.Substring(4).Trim()); + if (System.IO.File.Exists(refPath)) + { + var fullHash = System.IO.File.ReadAllText(refPath).Trim(); + if (fullHash.Length >= 7) + gitHash = fullHash.Substring(0, 7); + } + } + else if (headContent.Length >= 7) + { + gitHash = headContent.Substring(0, 7); + } + } + } + } + catch {} + + int runCount = 14; + return $"quant_{dateStr}.{runCount}.{gitHash}"; + } + } public IndexModel( IWorkspaceRepository workspaceRepository,