public Task Connect (NUnitVersion version, IExecutionHandler executionHandler = null, OperationConsole console = null) { var exePath = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), version.ToString (), "NUnitRunner.exe"); connection = new RemoteProcessConnection (exePath, executionHandler, console, Runtime.MainSynchronizationContext); connection.AddListener (this); return connection.Connect (); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { DotNetExecutionCommand cmd = (DotNetExecutionCommand) command; if (cmd.TargetRuntime == null) cmd.TargetRuntime = Runtime.SystemAssemblyService.DefaultRuntime; return cmd.TargetRuntime.GetExecutionHandler ().Execute (cmd, console); }
internal ProcessAsyncOperation InternalExecute (CommandExecutionContext ctx, IExecutionMode mode, ExecutionCommand command, OperationConsole console) { CustomExecutionMode cmode = ExecutionModeCommandService.ShowParamtersDialog (ctx, mode, null); if (cmode == null) return new CancelledProcessAsyncOperation (); return cmode.Execute (command, console, false, false); }
public override ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { DotNetExecutionCommand dotcmd = (DotNetExecutionCommand) command; string runtimeArgs = string.IsNullOrEmpty (dotcmd.RuntimeArguments) ? "--debug" : dotcmd.RuntimeArguments; string args = string.Format ("{2} \"{0}\" {1}", dotcmd.Command, dotcmd.Arguments, runtimeArgs); NativeExecutionCommand cmd = new NativeExecutionCommand (monoPath, args, dotcmd.WorkingDirectory, dotcmd.EnvironmentVariables); return base.Execute (cmd, console); }
public virtual ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { ProcessExecutionCommand cmd = (ProcessExecutionCommand) command; IDictionary<string, string> vars; if (defaultEnvironmentVariables != null && defaultEnvironmentVariables.Count > 0) { if (cmd.EnvironmentVariables.Count == 0) { vars = defaultEnvironmentVariables; } else { // Merge the variables. vars = new Dictionary<string, string> (defaultEnvironmentVariables); foreach (KeyValuePair<string,string> evar in cmd.EnvironmentVariables) vars [evar.Key] = evar.Value; } } else vars = cmd.EnvironmentVariables; return Runtime.ProcessService.StartConsoleProcess (cmd.Command, cmd.Arguments, cmd.WorkingDirectory, console, vars); }
public ProcessMonitor (OperationConsole console, ProcessAsyncOperation operation, EventHandler exited) { this.exited = exited; this.operation = operation; this.console = console; operation.Task.ContinueWith (t => OnOperationCompleted ()); cancelRegistration = console.CancellationToken.Register (operation.Cancel); }
public ProcessAsyncOperation StartConsoleProcess (string command, string arguments, string workingDirectory, OperationConsole console, IDictionary<string, string> environmentVariables = null, EventHandler exited = null) { var externalConsole = console as ExternalConsole; if ((console == null || externalConsole != null) && externalConsoleHandler != null) { var dict = new Dictionary<string,string> (); if (environmentVariables != null) foreach (var kvp in environmentVariables) dict[kvp.Key] = kvp.Value; if (environmentVariableOverrides != null) foreach (var kvp in environmentVariableOverrides) dict[kvp.Key] = kvp.Value; var p = externalConsoleHandler (command, arguments, workingDirectory, dict, GettextCatalog.GetString ("{0} External Console", BrandingService.ApplicationName), externalConsole != null ? !externalConsole.CloseOnDispose : false); if (p != null) { if (exited != null) p.Task.ContinueWith (t => exited (p, EventArgs.Empty), Runtime.MainTaskScheduler); Counters.ProcessesStarted++; return p; } else { LoggingService.LogError ("Could not create external console for command: " + command + " " + arguments); } } ProcessStartInfo psi = CreateProcessStartInfo (command, arguments, workingDirectory, false); if (environmentVariables != null) foreach (KeyValuePair<string, string> kvp in environmentVariables) psi.EnvironmentVariables [kvp.Key] = kvp.Value; try { ProcessWrapper pw = StartProcess (psi, console.Out, console.Error, null); new ProcessMonitor (console, pw.ProcessAsyncOperation, exited); return pw.ProcessAsyncOperation; } catch (Exception ex) { // If the process can't be started, dispose the console now since ProcessMonitor won't do it console.Error.WriteLine (GettextCatalog.GetString ("The application could not be started")); LoggingService.LogError ("Could not start process for command: " + psi.FileName + " " + psi.Arguments, ex); console.Dispose (); return NullProcessAsyncOperation.Failure; } }
public IDisposable CreateExternalProcessObject (Type type, IExecutionHandler executionHandler, IList<string> userAssemblyPaths = null, OperationConsole console = null) { CheckRemoteType (type); var hc = GetHost (type.ToString (), false, executionHandler); return (IDisposable)hc.CreateInstance (type.Assembly.Location, type.FullName, GetRequiredAddins (type), userAssemblyPaths, console); }
public ProcessAsyncOperation StartConsoleProcess(string command, string arguments, string workingDirectory, OperationConsole console, IDictionary <string, string> environmentVariables = null, EventHandler exited = null) { var externalConsole = console as ExternalConsole; if ((console == null || externalConsole != null) && externalConsoleHandler != null) { var dict = new Dictionary <string, string> (); if (environmentVariables != null) { foreach (var kvp in environmentVariables) { dict[kvp.Key] = kvp.Value; } } if (environmentVariableOverrides != null) { foreach (var kvp in environmentVariableOverrides) { dict[kvp.Key] = kvp.Value; } } var p = externalConsoleHandler(command, arguments, workingDirectory, dict, externalConsole?.Title ?? GettextCatalog.GetString("{0} External Console", BrandingService.ApplicationName), externalConsole != null ? !externalConsole.CloseOnDispose : false); if (p != null) { if (exited != null) { p.Task.ContinueWith(t => exited(p, EventArgs.Empty), Runtime.MainTaskScheduler); } Counters.ProcessesStarted++; return(p); } else { LoggingService.LogError("Could not create external console for command: " + command + " " + arguments); } } ProcessStartInfo psi = CreateProcessStartInfo(command, arguments, workingDirectory, false); if (environmentVariables != null) { foreach (KeyValuePair <string, string> kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } try { ProcessWrapper pw = StartProcess(psi, console.Out, console.Error, null); new ProcessMonitor(console, pw.ProcessAsyncOperation, exited); return(pw.ProcessAsyncOperation); } catch (Exception ex) { // If the process can't be started, dispose the console now since ProcessMonitor won't do it console.Error.WriteLine(GettextCatalog.GetString("The application could not be started")); LoggingService.LogError("Could not start process for command: " + psi.FileName + " " + psi.Arguments, ex); console.Dispose(); return(NullProcessAsyncOperation.Failure); } }
public IDisposable CreateExternalProcessObject(Type type, IExecutionHandler executionHandler, IList <string> userAssemblyPaths = null, OperationConsole console = null) { CheckRemoteType(type); var hc = GetHost(type.ToString(), false, executionHandler); return((IDisposable)hc.CreateInstance(type.Assembly.Location, type.FullName, GetRequiredAddins(type), userAssemblyPaths, console)); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { return Handler.InternalExecute (Context, ParentMode, command, console); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { return InternalExecute (new CommandExecutionContext (null, command), new ExecutionMode ("", "", this), command, console); }
public ProcessAsyncOperation Execute(ExecutionCommand command, OperationConsole console) { IExecutionHandler handler = Runtime.ProcessService.GetDefaultExecutionHandler(command); return(handler.Execute(command, console)); }
public ProcessAsyncOperation Execute(MonoDevelop.Core.Execution.ExecutionCommand command, MonoDevelop.Core.Execution.OperationConsole console) { throw new InvalidOperationException(); }
public void Start (IList<string> userAssemblyPaths = null, OperationConsole console = null) { lock (this) { if (starting) return; starting = true; exitRequestEvent.Reset (); RemotingService.RegisterRemotingChannel (); BinaryFormatter bf = new BinaryFormatter (); ObjRef oref = RemotingServices.Marshal (this); MemoryStream ms = new MemoryStream (); bf.Serialize (ms, oref); string sref = Convert.ToBase64String (ms.ToArray ()); string tmpFile = null; if (executionHandlerFactory == null) executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler (); try { string location = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location); location = Path.Combine (location, "mdhost.exe"); tmpFile = Path.GetTempFileName (); StreamWriter sw = new StreamWriter (tmpFile); sw.WriteLine (sref); sw.WriteLine (Process.GetCurrentProcess ().Id); sw.WriteLine (Runtime.SystemAssemblyService.CurrentRuntime.RuntimeId); // Explicitly load Mono.Addins since the target runtime may not have it installed sw.WriteLine (2); sw.WriteLine (typeof(AddinManager).Assembly.Location); sw.WriteLine (typeof(Mono.Addins.Setup.SetupService).Assembly.Location); sw.Close (); string arguments = string.Format ("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand (location, arguments, AppDomain.CurrentDomain.BaseDirectory); if (userAssemblyPaths != null) cmd.UserAssemblyPaths = userAssemblyPaths; cmd.DebugMode = isDebugMode; OperationConsole cons = console ?? new ProcessHostConsole (); var p = process = executionHandlerFactory.Execute (cmd, cons); Counters.ExternalHostProcesses++; process.Task.ContinueWith ((t) => ProcessExited (p)); } catch (Exception ex) { if (tmpFile != null) { try { File.Delete (tmpFile); } catch { } } LoggingService.LogError (ex.ToString ()); throw; } } }
public OperationConsoleWrapper(OperationConsole console, Action cancelAction) { this.console = console; this.cancelAction = cancelAction; console.CancellationToken.Register(cancelAction); }
public object CreateInstance (string assemblyPath, string typeName, string[] addins, IList<string> userAssemblyPaths = null, OperationConsole console = null) { lock (this) { references++; if (processHost == null) Start (userAssemblyPaths, console); } if (!runningEvent.WaitOne (15000, false)) { references--; throw new ApplicationException ("Couldn't create a remote process."); } try { // Before creating the instance, load the add-ins on which it depends if (addins != null && addins.Length > 0) processHost.LoadAddins (addins); RemotingService.RegisterAssemblyForSimpleResolve (Path.GetFileNameWithoutExtension (assemblyPath)); object obj = processHost.CreateInstance (assemblyPath, typeName); RemotingService.RegisterMethodCallback (obj, "Dispose", RemoteProcessObjectDisposing, null); RemotingService.RegisterMethodCallback (obj, "Shutdown", RemoteProcessObjectShuttingDown, null); remoteObjects.Add (obj); Counters.ExternalObjects++; return obj; } catch { ReleaseInstance (null); throw; } }
/// <summary> /// Runs a command /// </summary> /// <param name="command"> /// Command to run /// </param> /// <param name="console"> /// The console where to redirect the output /// </param> /// <param name="ctx"> /// Context with execution information /// </param> /// <param name="configurationData"> /// Configuration information. Created by the IExecutionConfigurationEditor object. /// </param> public abstract ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console, CommandExecutionContext ctx, object configurationData);
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { return Handler.Execute (command, console); }
public RemoteProcessConnection(string exePath, IExecutionHandler executionHandler = null, OperationConsole console = null, SynchronizationContext syncContext = null) { if (executionHandler == null) { executionHandler = Runtime.ProcessService.DefaultExecutionHandler; } if (console == null) { console = new ProcessHostConsole(); } this.executionHandler = executionHandler; this.exePath = exePath; this.syncContext = syncContext; this.console = console; mainCancelSource = new CancellationTokenSource(); }
public OperationConsoleWrapper (OperationConsole console, Action cancelAction) { this.console = console; this.cancelAction = cancelAction; console.CancellationToken.Register (cancelAction); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { if (Mode is CustomExecutionMode) return ((CustomExecutionMode)Mode).Execute (command, console, true, true); else { CustomExecutionMode cmode = new CustomExecutionMode (); cmode.Mode = Mode; cmode.Project = Context.Project; cmode.PromptForParameters = true; return cmode.ExecutionHandler.Execute (command, console); } }
public void Start(IList <string> userAssemblyPaths = null, OperationConsole console = null) { lock (this) { if (starting) { return; } starting = true; exitRequestEvent.Reset(); RemotingService.RegisterRemotingChannel(); BinaryFormatter bf = new BinaryFormatter(); ObjRef oref = RemotingServices.Marshal(this); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, oref); string sref = Convert.ToBase64String(ms.ToArray()); string tmpFile = null; if (executionHandlerFactory == null) { executionHandlerFactory = Runtime.SystemAssemblyService.CurrentRuntime.GetExecutionHandler(); } try { string location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); location = Path.Combine(location, "mdhost.exe"); tmpFile = Path.GetTempFileName(); StreamWriter sw = new StreamWriter(tmpFile); sw.WriteLine(sref); sw.WriteLine(Process.GetCurrentProcess().Id); sw.WriteLine(Runtime.SystemAssemblyService.CurrentRuntime.RuntimeId); // Explicitly load Mono.Addins since the target runtime may not have it installed sw.WriteLine(2); sw.WriteLine(typeof(AddinManager).Assembly.Location); sw.WriteLine(typeof(Mono.Addins.Setup.SetupService).Assembly.Location); sw.Close(); string arguments = string.Format("{0} \"{1}\"", id, tmpFile); DotNetExecutionCommand cmd = new DotNetExecutionCommand(location, arguments, AppDomain.CurrentDomain.BaseDirectory); if (userAssemblyPaths != null) { cmd.UserAssemblyPaths = userAssemblyPaths; } cmd.DebugMode = isDebugMode; OperationConsole cons = console ?? new ProcessHostConsole(); var p = process = executionHandlerFactory.Execute(cmd, cons); Counters.ExternalHostProcesses.Inc(1); process.Task.ContinueWith((t) => ProcessExited(p)); } catch (Exception ex) { if (tmpFile != null) { try { File.Delete(tmpFile); } catch { } } LoggingService.LogError(ex.ToString()); throw; } } }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { IExecutionHandler handler = Runtime.ProcessService.GetDefaultExecutionHandler (command); return handler.Execute (command, console); }
public XspBrowserLauncherConsole (OperationConsole real, Action <string> launchBrowser) { this.real = real; this.launchBrowser = launchBrowser; cancelReg = real.CancellationToken.Register (CancellationSource.Cancel); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { if (!CanExecute (command)) return null; return DebuggingService.Run (command, console); }
internal LogViewProgressMonitor (LogView pad): base (Runtime.MainSynchronizationContext) { outputPad = pad; outputPad.Clear (); internalLogger.TextWritten += outputPad.WriteConsoleLogText; console = new LogViewProgressConsole (this); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console, bool allowPrompt, bool forcePrompt) { if ((PromptForParameters || forcePrompt) && allowPrompt) { var ctx = new CommandExecutionContext (Project, command); CustomExecutionMode customMode = ExecutionModeCommandService.ShowParamtersDialog (ctx, Mode, this); if (customMode == null) return new CancelledProcessAsyncOperation (); return customMode.Execute (command, console, false, false); } foreach (var cc in GetCachedCustomizers ()) { cc.Item1.Customize (command, cc.Item2); } var cmode = Mode.ExecutionHandler as ParameterizedExecutionHandler; if (cmode != null) { CommandExecutionContext ctx = new CommandExecutionContext (Project, command); return cmode.Execute (command, console, ctx, Data); } return Mode.ExecutionHandler.Execute (command, console); }
public object CreateInstance(string assemblyPath, string typeName, string[] addins, IList <string> userAssemblyPaths = null, OperationConsole console = null) { lock (this) { references++; if (processHost == null) { Start(userAssemblyPaths, console); } } if (!runningEvent.WaitOne(15000, false)) { references--; throw new ApplicationException("Couldn't create a remote process."); } try { // Before creating the instance, load the add-ins on which it depends if (addins != null && addins.Length > 0) { processHost.LoadAddins(addins); } RemotingService.RegisterAssemblyForSimpleResolve(Path.GetFileNameWithoutExtension(assemblyPath)); object obj = processHost.CreateInstance(assemblyPath, typeName); RemotingService.RegisterMethodCallback(obj, "Dispose", RemoteProcessObjectDisposing, null); RemotingService.RegisterMethodCallback(obj, "Shutdown", RemoteProcessObjectShuttingDown, null); remoteObjects.Add(obj); Counters.ExternalObjects.Inc(1); return(obj); } catch { ReleaseInstance(null); throw; } }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { var cmd = (AspNetExecutionCommand) command; var xspPath = GetXspPath (cmd); var evars = new Dictionary<string, string>(cmd.EnvironmentVariables); foreach (var v in cmd.TargetRuntime.GetToolsExecutionEnvironment (cmd.TargetFramework).Variables) { if (!evars.ContainsKey (v.Key)) evars.Add (v.Key, v.Value); } //HACK: work around Mono trying to create registry in non-writable location if (cmd.TargetRuntime is MonoTargetRuntime && !Platform.IsWindows) { evars ["MONO_REGISTRY_PATH"] = UserProfile.Current.TempDir.Combine ("aspnet-registry"); } //if it's a script, use a native execution handler if (xspPath.Extension != ".exe") { //set mono debug mode if project's in debug mode if (cmd.DebugMode) { evars ["MONO_OPTIONS"] = "--debug"; } var ncmd = new NativeExecutionCommand ( xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop", cmd.BaseDirectory, evars); return Runtime.ProcessService.GetDefaultExecutionHandler (ncmd).Execute (ncmd, console); } // Set DEVPATH when running on Windows (notice that this has no effect unless // <developmentMode developerInstallation="true" /> is set in xsp2.exe.config if (cmd.TargetRuntime is MsNetTargetRuntime) evars["DEVPATH"] = Path.GetDirectoryName (xspPath); var netCmd = new DotNetExecutionCommand ( xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop", cmd.BaseDirectory, evars); netCmd.DebugMode = cmd.DebugMode; return cmd.TargetRuntime.GetExecutionHandler ().Execute (netCmd, console); }
public ProcessAsyncOperation Execute (ExecutionCommand command, OperationConsole console) { return Execute (command, console, true, false); }