namespace ClassNotify.Server.Configuration; public sealed class DeviceVersionPolicyOptions { public string MinimumServiceVersion { get; set; } = "2.4.0"; public string RecommendedServiceVersion { get; set; } = "2.5.0"; public string MinimumClientVersion { get; set; } = "2.4.0"; public string RecommendedClientVersion { get; set; } = "2.5.0"; public int MinimumProtocolVersion { get; set; } = 1; public string EvaluateVersionStatus(string? serviceVersion, string? clientVersion, int? protocolVersion) { if (string.IsNullOrWhiteSpace(serviceVersion) && string.IsNullOrWhiteSpace(clientVersion)) { return "Unknown"; } if (protocolVersion.HasValue && protocolVersion.Value < MinimumProtocolVersion) { return "Unsupported"; } bool isServiceUnsupported = !string.IsNullOrEmpty(serviceVersion) && CompareVersions(serviceVersion, MinimumServiceVersion) < 0; bool isClientUnsupported = !string.IsNullOrEmpty(clientVersion) && CompareVersions(clientVersion, MinimumClientVersion) < 0; if (isServiceUnsupported || isClientUnsupported) { return "Unsupported"; } bool isServiceOutdated = !string.IsNullOrEmpty(serviceVersion) && CompareVersions(serviceVersion, RecommendedServiceVersion) < 0; bool isClientOutdated = !string.IsNullOrEmpty(clientVersion) && CompareVersions(clientVersion, RecommendedClientVersion) < 0; if (isServiceOutdated || isClientOutdated) { return "Outdated"; } return "Current"; } private static int CompareVersions(string a, string b) { if (Version.TryParse(a, out var vA) && Version.TryParse(b, out var vB)) { return vA.CompareTo(vB); } return string.Compare(a, b, StringComparison.OrdinalIgnoreCase); } }