From b6fe47b4042f9f04824d667af65b448818483a3f Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 2 Aug 2011 23:59:46 +0200 Subject: [PATCH] fix start options for ASp.NET MVC projects --- .../Debugger.AddIn/Service/WindowsDebugger.cs | 124 ++++++++++++------ 1 file changed, 83 insertions(+), 41 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs index aa5d94b9c5..c010a3850f 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs @@ -143,12 +143,12 @@ namespace ICSharpCode.SharpDevelop.Services 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) { + // we deal with a WebProject + try { + var project = ProjectService.OpenSolution.StartupProject as CompilableProject; + var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); + System.Diagnostics.Process defaultAppProcess = null; + string processName = WebProjectService.WorkerProcessName; // try find the worker process directly or using the process monitor callback @@ -171,28 +171,50 @@ namespace ICSharpCode.SharpDevelop.Services if (options.Data.WebServer == WebServer.IISExpress) { // start IIS express and attach to it - if (WebProjectService.IISVersion == IISVersion.IISExpress) + if (WebProjectService.IISVersion == IISVersion.IISExpress) { System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation); - else { + } 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); + + // start default application(e.g. browser) or the one specified + switch (project.StartAction) { + case StartAction.Project: + if (FileUtility.IsUrl(options.Data.ProjectUrl)) { + defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl); + } else { + MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}"); + return; + } + break; + case StartAction.Program: + defaultAppProcess = System.Diagnostics.Process.Start(project.StartProgram); + break; + case StartAction.StartURL: + if (FileUtility.IsUrl(project.StartUrl)) + defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl); + else { + string url = string.Concat(options.Data.ProjectUrl, project.StartUrl); + if (FileUtility.IsUrl(url)) { + defaultAppProcess = System.Diagnostics.Process.Start(url); + } else { + MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}"); + return; + } + } + break; + default: + throw new System.Exception("Invalid value for StartAction"); } + } catch (System.Exception ex) { + string err = "Error: " + ex.Message; + MessageService.ShowError(err); + LoggingService.Error(err); + return; } - } - else { + } else { string version = debugger.GetProgramVersion(processStartInfo.FileName); if (version.StartsWith("v1.0")) { @@ -301,11 +323,11 @@ namespace ICSharpCode.SharpDevelop.Services if (FileUtility.IsUrl(processStartInfo.FileName)) { if (!CheckWebProjectStartInfo()) return; - - var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject; - var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); - - if (options.Data.WebServer != WebServer.None) { + // we deal with a WebProject + try { + var project = ProjectService.OpenSolution.StartupProject as CompilableProject; + var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); + string processName = WebProjectService.WorkerProcessName; if (options.Data.WebServer == WebServer.IISExpress) { @@ -317,23 +339,43 @@ namespace ICSharpCode.SharpDevelop.Services return; } } - } - - // start default application(e.g. browser) - if (project.StartAction == StartAction.StartURL) - System.Diagnostics.Process.Start(project.StartUrl); - else { - if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS) - System.Diagnostics.Process.Start(options.Data.ProjectUrl); - else { - if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IISExpress) - System.Diagnostics.Process.Start(options.Data.ProjectUrl); - else - System.Diagnostics.Process.Start(processStartInfo.FileName); + + // start default application(e.g. browser) or the one specified + switch (project.StartAction) { + case StartAction.Project: + if (FileUtility.IsUrl(options.Data.ProjectUrl)) { + System.Diagnostics.Process.Start(options.Data.ProjectUrl); + } else { + MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}"); + return; + } + break; + case StartAction.Program: + System.Diagnostics.Process.Start(project.StartProgram); + break; + case StartAction.StartURL: + if (FileUtility.IsUrl(project.StartUrl)) + System.Diagnostics.Process.Start(project.StartUrl); + else { + string url = string.Concat(options.Data.ProjectUrl, project.StartUrl); + if (FileUtility.IsUrl(url)) { + System.Diagnostics.Process.Start(url); + } else { + MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}"); + return; + } + } + break; + default: + throw new System.Exception("Invalid value for StartAction"); } + } catch (System.Exception ex) { + string err = "Error: " + ex.Message; + MessageService.ShowError(err); + LoggingService.Error(err); + return; } - } - else + } else System.Diagnostics.Process.Start(processStartInfo); }