Esempio n. 1
0
        public int LaunchProject(bool debug)
        {
            var config = debug ? _debugConfig : _runConfig;

            DebugLaunchHelper.RequireStartupFile(config);

            Uri url;
            int port;

            GetFullUrl(_serviceProvider, config, out url, out port);

            var env = new Dictionary <string, string> {
                { "SERVER_PORT", port.ToString() }
            };

            if (url != null)
            {
                env["SERVER_HOST"] = url.Host;
            }

            config.Environment = PathUtils.MergeEnvironments(env, config.Environment);

            try {
                _serviceProvider.GetPythonToolsService().Logger?.LogEvent(Logging.PythonLogEvent.Launch, new Logging.LaunchInfo {
                    IsDebug = debug,
                    IsWeb   = true,
                    Version = config.Interpreter?.Version.ToString() ?? ""
                });
            } catch (Exception ex) {
                Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
            }

            if (debug)
            {
                if (url != null)
                {
                    config.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = url.AbsoluteUri;
                }
                using (var dsi = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) {
                    dsi.Launch();
                }
            }
            else
            {
                var psi = DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config);

                var process = Process.Start(psi);
                if (url != null && process != null)
                {
                    StartBrowser(url.AbsoluteUri, () => process.HasExited)
                    .ContinueWith(t => { process.Close(); })
                    .HandleAllExceptions(_serviceProvider, GetType())
                    .DoNotWait();
                }
            }

            return(VSConstants.S_OK);
        }
Esempio n. 2
0
        private int Launch(LaunchConfiguration config, bool debug)
        {
            DebugLaunchHelper.RequireStartupFile(config);

            //if (factory.Id == _cpyInterpreterGuid || factory.Id == _cpy64InterpreterGuid) {
            //    MessageBox.Show(
            //        "The project is currently set to use the .NET debugger for IronPython debugging but the project is configured to start with a CPython interpreter.\r\n\r\nTo fix this change the debugger type in project properties->Debug->Launch mode.\r\nIf IronPython is not an available interpreter you may need to download it from http://ironpython.codeplex.com.",
            //        "Visual Studio");
            //    return VSConstants.S_OK;
            //}

            try {
                if (debug)
                {
                    if (string.IsNullOrEmpty(config.InterpreterArguments))
                    {
                        config.InterpreterArguments = "-X:Debug";
                    }
                    else if (config.InterpreterArguments.IndexOf("-X:Debug", StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        config.InterpreterArguments = "-X:Debug " + config.InterpreterArguments;
                    }

                    var  debugStdLib = _project.GetProperty(IronPythonLauncherOptions.DebugStandardLibrarySetting);
                    bool debugStdLibResult;
                    if (!bool.TryParse(debugStdLib, out debugStdLibResult) || !debugStdLibResult)
                    {
                        string interpDir = config.Interpreter.PrefixPath;
                        config.InterpreterArguments += " -X:NoDebug \"" + System.Text.RegularExpressions.Regex.Escape(Path.Combine(interpDir, "Lib\\")) + ".*\"";
                    }

                    using (var dti = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) {
                        // Set the CLR debugger
                        dti.Info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
                        dti.Info.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;

                        // Clear the CLSID list while launching, then restore it
                        // so Dispose() can free it.
                        var clsidList = dti.Info.pClsidList;
                        dti.Info.pClsidList   = IntPtr.Zero;
                        dti.Info.dwClsidCount = 0;
                        try {
                            dti.Launch();
                        } finally {
                            dti.Info.pClsidList = clsidList;
                        }
                    }
                }
                else
                {
                    var psi = DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config);
                    Process.Start(psi).Dispose();
                }
            } catch (FileNotFoundException) {
            }
            return(VSConstants.S_OK);
        }
Esempio n. 3
0
        private int Launch(LaunchConfiguration config, bool debug)
        {
            DebugLaunchHelper.RequireStartupFile(config);

            if (debug)
            {
                StartWithDebugger(config);
            }
            else
            {
                StartWithoutDebugger(config).Dispose();
            }

            return(VSConstants.S_OK);
        }