Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Waiting to run
- Managed Instance reports 12.0.2000.8 but is evergreen: treated as the newest engine with all capabilities; new SelfManagedInfrastructure capability so backup, CHECKDB, files, tempdb, memory, patch level and lifecycle rules report 'handled by Azure' instead of false findings - Microsoft Entra ID login (managed identity, service principal, default credential chain) via SqlConnection.AccessTokenCallback - Least-privilege script recognizes Managed Instance; deadlock collector falls back to the ring buffer when event files cannot be read - Web UI shows the right release for Managed Instance - README and installation docs: notifications and Managed Instance - Catalog test: 61 rules with unique, well-formed ids Integration suite green on SQL Server 2017 and 2022. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using System.Globalization;
|
||
using Microsoft.Extensions.Options;
|
||
using SQLInsight.Core.Findings;
|
||
using SQLInsight.Core.Instances;
|
||
|
||
namespace SQLInsight.Web;
|
||
|
||
/// <summary>
|
||
/// Formatting for the UI: times in the configured time zone, Danish number format, severity names.
|
||
/// </summary>
|
||
public sealed class Display(IOptions<WebOptions> options)
|
||
{
|
||
private static readonly CultureInfo Danish = CultureInfo.GetCultureInfo("da-DK");
|
||
|
||
private readonly TimeZoneInfo _zone = options.Value.TimeZone is { Length: > 0 } id
|
||
? TimeZoneInfo.FindSystemTimeZoneById(id)
|
||
: TimeZoneInfo.Local;
|
||
|
||
public string Time(DateTime? utc) => utc is { } value
|
||
? TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(value, DateTimeKind.Utc), _zone).ToString("dd-MM-yyyy HH:mm", Danish)
|
||
: "–";
|
||
|
||
public string Ago(DateTime? utc)
|
||
{
|
||
if (utc is not { } value)
|
||
{
|
||
return "aldrig";
|
||
}
|
||
|
||
var age = DateTime.UtcNow - value;
|
||
return age.TotalMinutes < 2 ? "lige nu"
|
||
: age.TotalHours < 2 ? $"{age.TotalMinutes:0} min. siden"
|
||
: age.TotalDays < 2 ? $"{age.TotalHours:0} timer siden"
|
||
: $"{age.TotalDays:0} dage siden";
|
||
}
|
||
|
||
public static string Number(double value, int decimals = 0) => value.ToString("N" + decimals, Danish);
|
||
|
||
public static string SeverityName(Severity severity) => severity switch
|
||
{
|
||
Severity.Critical => "Kritisk",
|
||
Severity.High => "Høj",
|
||
Severity.Medium => "Middel",
|
||
Severity.Low => "Lav",
|
||
_ => "Info",
|
||
};
|
||
|
||
public static string SeverityClass(Severity? severity) => severity switch
|
||
{
|
||
Severity.Critical => "sev-critical",
|
||
Severity.High => "sev-high",
|
||
Severity.Medium => "sev-medium",
|
||
Severity.Low => "sev-low",
|
||
Severity.Info => "sev-info",
|
||
_ => "sev-ok",
|
||
};
|
||
|
||
public static string Release(string? productVersion, int? engineEdition = null) =>
|
||
engineEdition == (int)EngineEdition.AzureSqlManagedInstance ? SqlServerRelease.AzureSqlManagedInstance.DisplayName()
|
||
: SqlServerVersion.TryParse(productVersion, out var version) ? version.Release.DisplayName() : "Ukendt version";
|
||
}
|