namespace UCVL.VPNPlus; internal static class ClientShutdownScope { internal record Instance(int Id, int SessionId, string? Executable); // Legacy events are shared within the logon session. Refuse an ambiguous // same-name process rather than signaling or closing an unrelated instance. internal static bool IsUnambiguous(string expected, int session, IEnumerable processes) => processes.Where(p => p.SessionId == session).All(p => !string.IsNullOrWhiteSpace(p.Executable) && string.Equals(Path.GetFullPath(p.Executable), Path.GetFullPath(expected), StringComparison.OrdinalIgnoreCase)); internal static bool SelfTest() { const string expected = @"C:\fixture\installed\VPNPlus.exe"; return IsUnambiguous(expected, 1, [new(10,1,expected)]) && IsUnambiguous(expected, 1, [new(10,2,@"D:\another-user\VPNPlus.exe")]) && IsUnambiguous(expected, 1, [new(10,1,expected.ToLowerInvariant())]) && !IsUnambiguous(expected, 1, [new(10,1,expected),new(11,1,@"D:\another-app\VPNPlus.exe")]) && !IsUnambiguous(expected, 1, [new(10,1,null)]); } }