using System; using System.Collections.Generic; using System.IO; namespace ISphereWinHelper { internal static class Program { [STAThread] private static int Main(string[] args) { string requestText = Console.In.ReadToEnd(); Dictionary request; string requestId = ""; string op = ""; if (!HelperProtocol.TryParseRequest(requestText, out request, out requestId, out op)) { Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "INVALID_REQUEST", "request must be valid JSON object"))); return 0; } try { Dictionary opArgs = HelperProtocol.GetObject(request, "args"); Dictionary response; switch (op) { case "version": response = HelperProtocol.Success(requestId, op, VersionData()); break; case "self_check": response = HelperProtocol.Success(requestId, op, SelfCheckData()); break; case "scan_windows": response = HelperProtocol.Success(requestId, op, WindowScanner.Scan(opArgs)); break; case "dump_uia": response = UiaDumper.Dump(requestId, op, opArgs); break; default: response = HelperProtocol.Failure(requestId, op, "UNSUPPORTED_OP", "unsupported op: " + op); break; } Console.WriteLine(HelperProtocol.ToJson(response)); return 0; } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "HELPER_FAILED", ex.Message))); return 0; } } private static Dictionary VersionData() { return new Dictionary { { "helper_name", "ISphereWinHelper" }, { "helper_version", "0.1.0" }, { "protocol", HelperProtocol.Protocol }, { "runtime", ".NET Framework " + Environment.Version } }; } private static Dictionary SelfCheckData() { bool uiaAvailable; try { uiaAvailable = System.Windows.Automation.AutomationElement.RootElement != null; } catch { uiaAvailable = false; } return new Dictionary { { "desktop_access", Environment.UserInteractive }, { "uia_available", uiaAvailable } }; } } }