// Usage: Xamarin.Interactive.Console.exe {IdentifyAgentRequest args} // Passing no arguments is supported for debug scenarios. public static void RunAgentOnCurrentThread <TAgent> ( Action <TAgent> integrateWithAgentHandler = null) where TAgent : Agent, new () { var ctx = new SingleThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(ctx); var agent = new TAgent(); integrateWithAgentHandler?.Invoke(agent); try { var request = IdentifyAgentRequest.FromCommandLineArguments(Environment.GetCommandLineArgs()); if (request != null && request.ProcessId >= 0) { if (HostEnvironment.OS == HostOS.macOS) { new Thread(() => { MonoTouch.Hosting.ProcessMonitor.WaitPid(request.ProcessId); Environment.Exit(0); }) { IsBackground = true }.Start(); } else { var parentProcess = Process.GetProcessById(request.ProcessId); parentProcess.EnableRaisingEvents = true; parentProcess.Exited += (o, e) => Environment.Exit(0); } } } catch (Exception e) { Log.Error("Main", e); } agent.Start(new AgentStartOptions { ClientSessionKind = ClientSessionKind.Workbook }); DebuggingSupport.LaunchClientAppForDebugging(agent); ctx.RunOnCurrentThread(); }
public void CommandLineRoundTrip(int prependedArgumentCount) { var original = IdentifyAgentRequest.CreateWithBaseConnectUri( new Uri("http://catoverflow.com")); var arguments = new List <string> (); for (int i = 0; i < prependedArgumentCount; i++) { arguments.Add(Guid.NewGuid().ToString()); } arguments.AddRange(original.ToCommandLineArguments()); IdentifyAgentRequest .FromCommandLineArguments(arguments.ToArray()) .ShouldEqual(original); }
// Usage: Xamarin.Interactive.Console.exe {IdentifyAgentRequest args} // Passing no arguments is supported for debug scenarios. public static void Main() { var ctx = new SingleThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(ctx); var agent = new ConsoleAgent(); MacIntegration.Integrate(agent); try { var request = IdentifyAgentRequest.FromCommandLineArguments(Environment.GetCommandLineArgs()); if (request != null && request.ProcessId >= 0) { if (Environment.OSVersion.Platform == PlatformID.Unix) { new Thread(() => { MonoTouch.Hosting.ProcessMonitor.WaitPid(request.ProcessId); Environment.Exit(0); }) { IsBackground = true }.Start(); } else { var parentProcess = Process.GetProcessById(request.ProcessId); parentProcess.EnableRaisingEvents = true; parentProcess.Exited += (o, e) => Environment.Exit(0); } } } catch (Exception e) { Log.Error("Main", e); } agent.Start(new AgentStartOptions { ClientSessionKind = ClientSessionKind.Workbook }); DebuggingSupport.LaunchClientAppForDebugging(agent); ctx.RunOnCurrentThread(); }
void App_OnStartup(object sender, StartupEventArgs e) { var agent = new WpfAgent(() => new MainWindow()); try { var request = IdentifyAgentRequest.FromCommandLineArguments(Environment.GetCommandLineArgs()); if (request.ProcessId >= 0) { var parentProcess = Process.GetProcessById(request.ProcessId); parentProcess.EnableRaisingEvents = true; parentProcess.Exited += (o, _) => Environment.Exit(0); } } catch (Exception ex) { Log.Error("App", ex); } agent.Start(new AgentStartOptions { ClientSessionKind = ClientSessionKind.Workbook }); DebuggingSupport.LaunchClientAppForDebugging(agent); }
protected override IdentifyAgentRequest GetIdentifyAgentRequest() => IdentifyAgentRequest.FromCommandLineArguments(NSProcessInfo.ProcessInfo.Arguments);
protected override IdentifyAgentRequest GetIdentifyAgentRequest() => IdentifyAgentRequest.FromCommandLineArguments(Environment.GetCommandLineArgs());