public void Stop() { if (attachedChildProcessJob != null) { attachedChildProcessJob.Dispose(); attachedChildProcessJob = null; } if (ServiceHost != null) { ServiceHost.Close(); ServiceHost = null; } }
public void Start(string workingDirectory, Process debuggerProcess, LoggerResult logger) { var gameHostAssembly = typeof(GameDebuggerTarget).Assembly.Location; using (var debugger = debuggerProcess != null ? VisualStudioDebugger.GetByProcess(debuggerProcess.Id) : null) { var address = "net.pipe://localhost/" + Guid.NewGuid(); var arguments = $"--host=\"{address}\""; // Child process should wait for a debugger to be attached if (debugger != null) { arguments += " --wait-debugger-attach"; } var startInfo = new ProcessStartInfo { FileName = gameHostAssembly, Arguments = arguments, WorkingDirectory = workingDirectory, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; // Start WCF pipe var gameDebuggerHost = new GameDebuggerHost(logger); ServiceHost = new ServiceHost(gameDebuggerHost); ServiceHost.AddServiceEndpoint(typeof(IGameDebuggerHost), new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxReceivedMessageSize = int.MaxValue }, address); ServiceHost.Open(); var process = new Process { StartInfo = startInfo }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); // Make sure proces will be killed if our process is finished unexpectedly attachedChildProcessJob = new AttachedChildProcessJob(process); // Attach debugger debugger?.AttachToProcess(process.Id); GameHost = gameDebuggerHost; } }
public void Start(string workingDirectory, Process debuggerProcess, LoggerResult logger) { var gameHostAssembly = typeof(GameDebuggerTarget).Assembly.Location; using (var debugger = debuggerProcess != null ? VisualStudioDebugger.GetByProcess(debuggerProcess.Id) : null) { var address = "Stride/Debugger/" + Guid.NewGuid(); var arguments = $"--host=\"{address}\""; // Child process should wait for a debugger to be attached if (debugger != null) { arguments += " --wait-debugger-attach"; } var startInfo = new ProcessStartInfo { FileName = gameHostAssembly, Arguments = arguments, WorkingDirectory = workingDirectory, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; // Start ServiceWire pipe var gameDebuggerHost = new GameDebuggerHost(logger); ServiceHost = new NpHost(address, null, null); ServiceHost.AddService <IGameDebuggerHost>(gameDebuggerHost); ServiceHost.Open(); var process = new Process { StartInfo = startInfo }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); // Make sure proces will be killed if our process is finished unexpectedly attachedChildProcessJob = new AttachedChildProcessJob(process); // Attach debugger debugger?.AttachToProcess(process.Id); GameHost = gameDebuggerHost; } }
private static void ClosePipeAndProcess() { if (strideCommands != null) { try { strideCommands.Dispose(); } catch (Exception ex) { Trace.WriteLine($"Unexpected exception when closing remote connection to VS Commands: {ex}"); } strideCommands = null; } strideCommandsProcessJob?.Dispose(); strideCommandsProcessJob = null; }
/// <summary> /// Gets the current proxy. /// </summary> /// <returns>StrideCommandsProxy.</returns> public static IStrideCommands GetProxy() { lock (commandProxyLock) { // New instance? bool shouldReload = strideCommands == null || solutionChanged || ShouldReload(); if (!shouldReload) { // TODO: Assemblies changed? //shouldReload = ShouldReload(); } // If new instance or assemblies changed, reload if (shouldReload) { ClosePipeAndProcess(); var address = "Stride/VSPackageCommands/" + Guid.NewGuid(); var stridePackageInfo = FindStrideSdkDir(solution).Result; if (stridePackageInfo.LoadedVersion == null) { return(null); } var commandAssembly = stridePackageInfo.SdkPaths.First(x => Path.GetFileNameWithoutExtension(x) == "Stride.VisualStudio.Commands"); var commandExecutable = Path.ChangeExtension(commandAssembly, ".exe"); // .NET Core: .dll => .exe var startInfo = new ProcessStartInfo { // Note: try to get exec server if it exists, otherwise use CompilerApp.exe FileName = commandExecutable, Arguments = $"--pipe=\"{address}\"", WorkingDirectory = Environment.CurrentDirectory, UseShellExecute = false, }; var strideCommandsProcess = new Process { StartInfo = startInfo }; strideCommandsProcess.Start(); strideCommandsProcessJob = new AttachedChildProcessJob(strideCommandsProcess); for (int i = 0; i < 10; ++i) { try { strideCommands = new NpClient <IStrideCommands>(new NpEndPoint(address + "/IStrideCommands")); break; } catch { // Last try, forward exception if (i == 9) { throw; } // Wait until process is ready to accept connections Thread.Sleep(100); } } solutionChanged = false; } return(strideCommands?.Proxy); } }