Example #1
0
		public void Stop()
		{
			if (!IsDebugging) {
				MessageService.ShowMessage(errorNotDebugging, "${res:XML.MainMenu.DebugMenu.Stop}");
				return;
			}
			if (IsAttached) {
				StopAttachedProcessDialogResult result = ShowStopAttachedProcessDialog();
				switch (result) {
					case StopAttachedProcessDialogResult.Terminate:
						debuggedProcess.Terminate();
						attached = false;
						break;
					case StopAttachedProcessDialogResult.Detach:
						Detach();
						attached = false;
						break;
				}
			} else {
				debuggedProcess.Terminate();
			}
			
			if (monitor != null) {
				monitor.Stop();
				monitor.Dispose();
				monitor = null;
			}
		}
Example #2
0
		void DisposeProcessMonitor()
		{
			if (monitor != null) {
				monitor.Stop();
				monitor.Dispose();
				monitor = null;
			}
		}
Example #3
0
		public void Start(ProcessStartInfo processStartInfo)
		{
			if (IsDebugging) {
				MessageService.ShowMessage(errorDebugging);
				return;
			}
			if (!ServiceInitialized) {
				InitializeService();
			}

			if (FileUtility.IsUrl(processStartInfo.FileName)) {
				if (!CheckWebProjectStartInfo())
					return;
				
				var project = ProjectService.OpenSolution.StartupProject as CompilableProject;
				var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
				System.Diagnostics.Process defaultAppProcess = null;
				
				if (options.Data.WebServer != WebServer.None) {
					string processName = WebProjectService.WorkerProcessName;
					
					// try find the worker process directly or using the process monitor callback
					var processes = System.Diagnostics.Process.GetProcesses();
					int index = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
					if (index > -1){
						Attach(processes[index]);
					} else {
						try {
							this.monitor = new ProcessMonitor(processName);
							this.monitor.ProcessCreated += delegate {
								WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(defaultAppProcess, options)));
							};
							this.monitor.Start();
						}
						catch (System.Exception ex) {
							LoggingService.ErrorFormatted("Process Monitor exception: {0}", ex.Message);
						}
					}
					
					if (options.Data.WebServer == WebServer.IISExpress) {
						// start IIS express and attach to it
						if (WebProjectService.IISVersion == IISVersion.IISExpress)
							System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation);
						else {
							MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
							return;
						}
					}
				}
				
				// start default application(e.g. browser)
				if (project.StartAction == StartAction.StartURL)
					defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl);
				else {
					if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS)
						defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
					else {
						if (options.Data.WebServer == WebServer.IISExpress)
							defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
					}
				}
			}
			else {
				string version = debugger.GetProgramVersion(processStartInfo.FileName);
				
				if (version.StartsWith("v1.0")) {
					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
				} else if (version.StartsWith("v1.1")) {
					MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
				} else if (debugger.IsKernelDebuggerEnabled) {
					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
				} else {
					attached = false;
					if (DebugStarting != null)
						DebugStarting(this, EventArgs.Empty);
					
					try {
						// set the JIT flag for evaluating optimized code
						Process.DebugMode = DebugModeFlag.Debug;
						Process process = debugger.Start(processStartInfo.FileName,
						                                 processStartInfo.WorkingDirectory,
						                                 processStartInfo.Arguments);
						SelectProcess(process);
					} catch (System.Exception e) {
						// COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
						// COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
						// COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
						// COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
						// BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
						// UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
						if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException) {
							string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
							msg += " " + e.Message;
							// TODO: Remove
							if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032)) {
								msg += Environment.NewLine + Environment.NewLine;
								msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
							}
							MessageService.ShowMessage(msg);
							
							if (DebugStopped != null)
								DebugStopped(this, EventArgs.Empty);
						} else {
							throw;
						}
					}
				}
			}
		}
Example #4
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            if (FileUtility.IsUrl(processStartInfo.FileName))
            {
                if (!CheckWebProjectStartInfo())
                {
                    return;
                }

                var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject;
                var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
                System.Diagnostics.Process defaultAppProcess = null;

                if (options.Data.WebServer != WebServer.None)
                {
                    string processName = WebProjectService.WorkerProcessName;

                    // try find the worker process directly or using the process monitor callback
                    var processes = System.Diagnostics.Process.GetProcesses();
                    int index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                    if (index > -1)
                    {
                        Attach(processes[index]);
                    }
                    else
                    {
                        try {
                            this.monitor = new ProcessMonitor(processName);
                            this.monitor.ProcessCreated += delegate {
                                WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(defaultAppProcess, options)));
                            };
                            this.monitor.Start();
                        }
                        catch (System.Exception ex) {
                            LoggingService.ErrorFormatted("Process Monitor exception: {0}", ex.Message);
                        }
                    }

                    if (options.Data.WebServer == WebServer.IISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IISVersion == IISVersion.IISExpress)
                        {
                            System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                }

                // start default application(e.g. browser)
                if (project.StartAction == StartAction.StartURL)
                {
                    defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl);
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS)
                    {
                        defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                    }
                    else
                    {
                        if (options.Data.WebServer == WebServer.IISExpress)
                        {
                            defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                        }
                    }
                }
            }
            else
            {
                string version = debugger.GetProgramVersion(processStartInfo.FileName);

                if (version.StartsWith("v1.0"))
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
                }
                else if (version.StartsWith("v1.1"))
                {
                    MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
                }
                else if (debugger.IsKernelDebuggerEnabled)
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
                }
                else
                {
                    attached = false;
                    if (DebugStarting != null)
                    {
                        DebugStarting(this, EventArgs.Empty);
                    }

                    try {
                        Process process = debugger.Start(processStartInfo.FileName,
                                                         processStartInfo.WorkingDirectory,
                                                         processStartInfo.Arguments);
                        SelectProcess(process);
                    } catch (System.Exception e) {
                        // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                        // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                        // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                        // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                        // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                        // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                        if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                        {
                            string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
                            msg += " " + e.Message;
                            // TODO: Remove
                            if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032))
                            {
                                msg += Environment.NewLine + Environment.NewLine;
                                msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
                            }
                            MessageService.ShowMessage(msg);

                            if (DebugStopped != null)
                            {
                                DebugStopped(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }