示例#1
0
        void AttachToWebWorkerProcessOrStartIISExpress(WebProjectProperties properties, bool withDebugging)
        {
            string processName = WebProjectService.GetWorkerProcessName(properties);

            // try find the worker process directly or using the process monitor callback
            Process[] processes = System.Diagnostics.Process.GetProcesses();
            int       index     = Array.FindIndex(processes, p => properties.UseIISExpress ? p.Id == LastStartedIISExpressProcessId : p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));

            if (index > -1)
            {
                if (withDebugging)
                {
                    SD.Debugger.Attach(processes[index]);
                }
            }
            else
            {
                if (properties.UseIISExpress)
                {
                    // start IIS express and attach to it
                    if (WebProjectService.IsIISExpressInstalled)
                    {
                        ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
                        if (withDebugging)
                        {
                            SD.Debugger.Start(processInfo);
                        }
                        else
                        {
                            var process = Process.Start(processInfo);
                            LastStartedIISExpressProcessId = process.Id;
                        }
                    }
                }
                else
                {
                    DisposeProcessMonitor();
                    this.monitor = new ProcessMonitor(processName);
                    this.monitor.ProcessCreated += delegate {
                        SD.MainThread.InvokeAsyncAndForget(() => OnProcessCreated(properties, withDebugging));
                    };
                    this.monitor.Start();
                }
            }
        }
示例#2
0
        void AttachToWebWorkerProcessOrStartIISExpress(WebProjectProperties properties, bool withDebugging)
        {
            string processName = WebProjectService.GetWorkerProcessName(properties);

            // try find the worker process directly or using the process monitor callback
            Process[] processes = System.Diagnostics.Process.GetProcesses();
            int       index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));

            if (index > -1)
            {
                if (withDebugging)
                {
                    DebuggerService.CurrentDebugger.Attach(processes[index]);
                }
            }
            else
            {
                if (properties.UseIISExpress)
                {
                    // start IIS express and attach to it
                    if (WebProjectService.IsIISExpressInstalled)
                    {
                        ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
                        if (withDebugging)
                        {
                            DebuggerService.CurrentDebugger.Start(processInfo);
                        }
                        else
                        {
                            Process.Start(processInfo);
                        }
                    }
                }
                else
                {
                    DisposeProcessMonitor();
                    this.monitor = new ProcessMonitor(processName);
                    this.monitor.ProcessCreated += delegate {
                        WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
                    };
                    this.monitor.Start();
                }
            }
        }
示例#3
0
        public override void Start(bool withDebugging)
        {
            if (!CheckWebProjectStartInfo())
            {
                return;
            }

            try {
                WebProjectProperties properties = WebProject.GetWebProjectProperties();
                string processName = WebProjectService.GetWorkerProcessName(properties);

                // try find the worker process directly or using the process monitor callback
                Process[] processes = System.Diagnostics.Process.GetProcesses();
                int       index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                if (index > -1)
                {
                    if (withDebugging)
                    {
                        DebuggerService.CurrentDebugger.Attach(processes[index]);
                    }
                }
                else
                {
                    if (properties.UseIISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IsIISExpressInstalled)
                        {
                            ProcessStartInfo processInfo = IISExpressProcessStartInfo.Create(WebProject);
                            DebuggerService.CurrentDebugger.Start(processInfo);
                        }
                        else
                        {
                            DisposeProcessMonitor();
                            MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                    else
                    {
                        DisposeProcessMonitor();
                        this.monitor = new ProcessMonitor(processName);
                        this.monitor.ProcessCreated += delegate {
                            WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(properties, withDebugging)));
                        };
                        this.monitor.Start();
                    }
                }

                // start default application(e.g. browser) or the one specified
                switch (CompilableProject.StartAction)
                {
                case StartAction.Project:
                    if (FileUtility.IsUrl(properties.IISUrl))
                    {
                        Process.Start(properties.IISUrl);
                    }
                    else
                    {
                        MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                        DisposeProcessMonitor();
                    }
                    break;

                case StartAction.Program:
                    Process.Start(StartProgram);
                    break;

                case StartAction.StartURL:
                    if (FileUtility.IsUrl(StartUrl))
                    {
                        Process.Start(StartUrl);
                    }
                    else
                    {
                        string url = string.Concat(properties.IISUrl, StartUrl);
                        if (FileUtility.IsUrl(url))
                        {
                            Process.Start(url);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WebProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            DisposeProcessMonitor();
                            return;
                        }
                    }
                    break;

                default:
                    throw new Exception("Invalid value for StartAction");
                }
            } catch (Exception ex) {
                MessageService.ShowError(ex.Message);
                LoggingService.Error(ex.ToString());
                DisposeProcessMonitor();
            }
        }