2
// AspNetExecutionHandler.cs
5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
29
using MonoDevelop.Projects;
30
using MonoDevelop.Core;
31
using MonoDevelop.Core.Assemblies;
32
using MonoDevelop.Core.Execution;
35
namespace MonoDevelop.AspNet
37
public class AspNetExecutionHandler: IExecutionHandler
39
public static string GetXspName (AspNetExecutionCommand cmd)
41
switch (cmd.ClrVersion) {
42
case ClrVersion.Net_1_1:
44
case ClrVersion.Net_2_0:
46
case ClrVersion.Net_4_0:
48
case ClrVersion.Net_4_5:
51
LoggingService.LogError ("ASP.NET is not supported for unknown runtime version '{0}'.", cmd.ClrVersion);
52
throw new UserException (GettextCatalog.GetString (
53
"ASP.NET is not supported for unknown runtime version '{0}'.", cmd.ClrVersion));
57
public static FilePath GetXspPath (AspNetExecutionCommand cmd)
59
var xspName = GetXspName (cmd);
61
FilePath xspPath = cmd.TargetRuntime.GetToolPath (cmd.TargetFramework, xspName);
63
if (xspPath.IsNullOrEmpty && cmd.ClrVersion == ClrVersion.Net_1_1)
64
xspPath = cmd.TargetRuntime.GetToolPath (cmd.TargetFramework, "xsp");
66
//if the current runtime doesn't provide XSP, look for an exe (not script) bundled alongside the addin
67
if (xspPath.IsNullOrEmpty) {
68
FilePath addinPath = typeof (AspNetExecutionHandler).Assembly.Location;
69
xspPath = addinPath.ParentDirectory.Combine (xspName + ".exe");
72
if (File.Exists (xspPath))
75
//if xsp wasn't found there, check beside the entrypoint exe too
76
FilePath rootExe = System.Reflection.Assembly.GetEntryAssembly ().Location;
77
xspPath = rootExe.ParentDirectory.Combine (xspName + ".exe");
79
if (File.Exists (xspPath))
82
LoggingService.LogError ("Did not find web server {0}", xspName);
83
throw new UserException (GettextCatalog.GetString (
84
"The {0} web server cannot be found. Please ensure that it is installed.", xspName), null);
87
public bool CanExecute (ExecutionCommand command)
89
var cmd = command as AspNetExecutionCommand;
90
return cmd != null && !string.IsNullOrEmpty (GetXspName (cmd));
93
public IProcessAsyncOperation Execute (ExecutionCommand command, IConsole console)
95
var cmd = (AspNetExecutionCommand) command;
96
var xspPath = GetXspPath (cmd);
98
var evars = new Dictionary<string, string>(cmd.EnvironmentVariables);
100
foreach (var v in cmd.TargetRuntime.GetToolsExecutionEnvironment (cmd.TargetFramework).Variables)
102
if (!evars.ContainsKey (v.Key))
103
evars.Add (v.Key, v.Value);
106
//if it's a script, use a native execution handler
107
if (xspPath.Extension != ".exe") {
108
//set mono debug mode if project's in debug mode
110
evars ["MONO_OPTIONS"] = "--debug";
113
var ncmd = new NativeExecutionCommand (
114
xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop",
115
cmd.BaseDirectory, evars);
117
return Runtime.ProcessService.GetDefaultExecutionHandler (ncmd).Execute (ncmd, console);
120
// Set DEVPATH when running on Windows (notice that this has no effect unless
121
// <developmentMode developerInstallation="true" /> is set in xsp2.exe.config
123
if (cmd.TargetRuntime is MsNetTargetRuntime)
124
evars["DEVPATH"] = Path.GetDirectoryName (xspPath);
126
var netCmd = new DotNetExecutionCommand (
127
xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop",
128
cmd.BaseDirectory, evars);
129
netCmd.DebugMode = cmd.DebugMode;
131
return cmd.TargetRuntime.GetExecutionHandler ().Execute (netCmd, console);