using SQLInsight.Core.CustomRules; using SQLInsight.Rules; using SQLInsight.Rules.Engine; namespace SQLInsight.Community.Services; public sealed record RuleEntry(string Id, string Title, string Area, string? Author, bool Community); /// Every rule the product ships: the built-in ones and the community rules in the rule pack. public static class RuleCatalog { private static readonly Dictionary Areas = new(StringComparer.Ordinal) { ["VER"] = "Version og opdateringer", ["CFG"] = "Konfiguration", ["DB"] = "Databaser, backup og integritet", ["WAIT"] = "Ventetider", ["IO"] = "I/O", ["CPU"] = "CPU og hukommelse", ["MEM"] = "CPU og hukommelse", ["ANOM"] = "Afvigelser fra det normale", ["QS"] = "Query Store og planer", ["PLAN"] = "Query Store og planer", ["IDX"] = "Indexes og statistik", ["STAT"] = "Indexes og statistik", ["AG"] = "Always On og SQL Agent", ["JOB"] = "Always On og SQL Agent", ["BLK"] = "Blocking og deadlocks", ["DLK"] = "Blocking og deadlocks", ["SEC"] = "Sikkerhed", }; public static IReadOnlyList All(IReadOnlyList community) { ArgumentNullException.ThrowIfNull(community); IEnumerable builtIn = BuiltInRules.Create().Select(r => new RuleEntry(r.Id, r.Title, Area(r.Id), null, false)); return builtIn.Concat(community.Select(r => new RuleEntry(r.Id, r.Title, Area(r.Id), r.Author, true))).ToList(); } public static string Area(string id) { ArgumentNullException.ThrowIfNull(id); var parts = id.Split('-'); return parts.Length >= 2 && Areas.TryGetValue(parts[1], out var area) ? area : "Andet"; } }