private void StartBrowser(string url, Func <bool> shortCircuitPredicate) { Uri uri; if (!String.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri)) { OnPortOpenedHandler.CreateHandler( uri.Port, shortCircuitPredicate: shortCircuitPredicate, action: () => { var web = _serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; if (web == null) { PythonToolsPackage.OpenWebBrowser(url); return; } ErrorHandler.ThrowOnFailure( web.CreateExternalWebBrowser( (uint)__VSCREATEWEBBROWSER.VSCWB_ForceNew, VSPREVIEWRESOLUTION.PR_Default, url ) ); } ); } }
public ITargetHostProcess StartProcess(string pythonExePath, string webBrowserUrl) { if (string.IsNullOrEmpty(pythonExePath)) { MessageBox.Show(Strings.PythonInterpreterPathNullOrEmpty, Strings.ProductTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } _webBrowserUrl = webBrowserUrl; _targetHostProcess = _targetInterop.ExecuteCommandAsync(pythonExePath, "\"" + _debuggerAdapterDirectory + "\""); if (!string.IsNullOrEmpty(webBrowserUrl) && Uri.TryCreate(webBrowserUrl, UriKind.RelativeOrAbsolute, out var uri)) { OnPortOpenedHandler.CreateHandler(uri.Port, null, null, () => _targetHostProcess.HasExited, LaunchBrowserDebugger); } return(_targetHostProcess); }
private Task StartBrowser(string url, Func <bool> shortCircuitPredicate) { Uri uri; if (!string.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri)) { var tcs = new TaskCompletionSource <object>(); OnPortOpenedHandler.CreateHandler( uri.Port, shortCircuitPredicate: shortCircuitPredicate, action: () => { try { var web = _serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; if (web == null) { CommonPackage.OpenWebBrowser(url); return; } ErrorHandler.ThrowOnFailure( web.CreateExternalWebBrowser( (uint)__VSCREATEWEBBROWSER.VSCWB_ForceNew, VSPREVIEWRESOLUTION.PR_Default, url ) ); } catch (Exception ex) when(!ex.IsCriticalException()) { tcs.SetException(ex); } finally { tcs.TrySetResult(null); } } ); return(tcs.Task); } return(Task.FromResult <object>(null)); }
private void OnBrowserLaunchElapsedTimer(object state) { Uri.TryCreate(_webBrowserUrl, UriKind.RelativeOrAbsolute, out var uri); OnPortOpenedHandler.CreateHandler(uri.Port, null, null, () => _targetHostProcess.HasExited, LaunchBrowserDebugger); _timer.Dispose(); }
private void StartProcess(string launchJson) { var connection = InitializeListenerSocket(); var json = JObject.Parse(launchJson); var exe = json["exe"].Value <string>(); var scriptAndScriptArgs = json["args"].Value <string>(); var cwd = json["cwd"].Value <string>(); ParseOptions(json["options"].Value <string>()); var argsList = new List <string> { string.IsNullOrWhiteSpace(_interpreterOptions) ? "" : _interpreterOptions, PythonToolsInstallPath.GetFile("ptvsd_launcher.py"), cwd.Trim('\\'), $"{_listenerPort}", $"{_processGuid}", $"{_debugOptions}", "-g" }; var launcherArgs = string.Join(" ", argsList.Where(a => !string.IsNullOrWhiteSpace(a)).Select(ProcessOutput.QuoteSingleArgument)); var arguments = $"{launcherArgs} {scriptAndScriptArgs}"; ProcessStartInfo psi = new ProcessStartInfo { FileName = exe, Arguments = arguments, WorkingDirectory = cwd, RedirectStandardError = false, RedirectStandardInput = false, RedirectStandardOutput = false, UseShellExecute = false, CreateNoWindow = false, }; var env = json["env"].Value <JArray>(); foreach (JObject curValue in env) { var name = curValue["name"].Value <string>(); var value = curValue["value"].Value <string>(); if (!string.IsNullOrWhiteSpace(name)) { psi.EnvironmentVariables[name] = value; } } _process = new Process { EnableRaisingEvents = true, StartInfo = psi }; _process.Exited += OnExited; _process.Start(); var logger = (IPythonToolsLogger)VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(IPythonToolsLogger)); try { if (connection.Wait(_debuggerConnectionTimeout)) { var socket = connection.Result; if (socket != null) { _debuggerConnected = true; _stream = new DebugAdapterProcessStream(new NetworkStream(socket, ownsSocket: true)); _stream.Initialized += OnInitialized; _stream.LegacyDebugger += OnLegacyDebugger; if (!string.IsNullOrEmpty(_webBrowserUrl) && Uri.TryCreate(_webBrowserUrl, UriKind.RelativeOrAbsolute, out Uri uri)) { OnPortOpenedHandler.CreateHandler(uri.Port, null, null, ProcessExited, LaunchBrowserDebugger); } } } else { Debug.WriteLine("Timed out waiting for debuggee to connect.", nameof(DebugAdapterProcess)); logger?.LogEvent(PythonLogEvent.DebugAdapterConnectionTimeout, "Launch"); } } catch (AggregateException ex) { Debug.WriteLine("Error waiting for debuggee to connect {0}".FormatInvariant(ex.InnerException ?? ex), nameof(DebugAdapterProcess)); } if (_stream == null && !_process.HasExited) { _process.Kill(); } }