protected async override Task OnExecute(ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) { if (data == null || !data.SupportsIntegration || String.IsNullOrEmpty(data.ExecuteTargetName)) { await base.OnExecute(monitor, context, configuration); return; } OperationConsole console = context.ConsoleFactory.CreateConsole(); monitor.BeginTask(GettextCatalog.GetString("Executing {0}", Project.Name), 1); try { ProcessWrapper process = Runtime.ProcessService.StartProcess("make", data.ExecuteTargetName, Project.BaseDirectory, console.Out, console.Error, null); await process.Task; monitor.Log.WriteLine(GettextCatalog.GetString("The application exited with code: {0}", process.ExitCode)); monitor.Step(1); } catch (Exception e) { monitor.ReportError(GettextCatalog.GetString("Project could not be executed: "), e); return; } finally { monitor.EndTask(); console.Dispose(); } }
protected async override Task OnExecute(ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration, SolutionItemRunConfiguration runConfiguration) { ProjectConfiguration conf = (ProjectConfiguration)GetConfiguration(configuration); monitor.Log.WriteLine(GettextCatalog.GetString("Running {0} ...", FileName)); OperationConsole console = conf.ExternalConsole ? context.ExternalConsoleFactory.CreateConsole(!conf.PauseConsoleOutput, monitor.CancellationToken) : context.ConsoleFactory.CreateConsole( OperationConsoleFactory.CreateConsoleOptions.Default.WithTitle(Path.GetFileName(FileName)), monitor.CancellationToken); try { try { ExecutionCommand executionCommand = CreateExecutionCommand(configuration, conf); if (!context.ExecutionHandler.CanExecute(executionCommand)) { monitor.ReportError(GettextCatalog.GetString("Can not execute \"{0}\". The selected execution mode is not supported for .NET projects.", FileName), null); return; } ProcessAsyncOperation asyncOp = context.ExecutionHandler.Execute(executionCommand, console); using (var stopper = monitor.CancellationToken.Register(asyncOp.Cancel)) { await asyncOp.Task; } monitor.Log.WriteLine(GettextCatalog.GetString("The application exited with code: {0}", asyncOp.ExitCode)); } finally { console.Dispose(); } } catch (Exception ex) { LoggingService.LogError(string.Format("Cannot execute \"{0}\"", FileName), ex); monitor.ReportError(GettextCatalog.GetString("Cannot execute \"{0}\"", FileName), ex); } }
public override void Dispose() { if (DisposeWrappedOperationConsole) { console.Dispose(); } else { // Do not dispose. This prevents a null reference exception when the // console is used after the external process has finished. // The console will be disposed later on. } }
protected async override Task OnExecute(ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) { var config = GetConfiguration(configuration) as DotNetProjectConfiguration; DotNetCoreExecutionCommand executionCommand = CreateDotNetCoreExecutionCommand(configuration, config); if (context.ExecutionTarget != null) { executionCommand.Target = context.ExecutionTarget; } executionCommand.Initialize(); if (CanDebug(executionCommand, context)) { await base.OnExecute(monitor, context, configuration); return; } monitor.Log.WriteLine(GettextCatalog.GetString("Running {0} ...", Name)); OperationConsole console = CreateConsole(config, context, monitor); try { try { ProcessAsyncOperation asyncOp = Execute(executionCommand, console); await asyncOp.Task; monitor.Log.WriteLine(GettextCatalog.GetString("The application exited with code: {0}", asyncOp.ExitCode)); } finally { console.Dispose(); } } catch (Exception ex) { LoggingService.LogError(string.Format("Cannot execute \"{0}\"", Name), ex); monitor.ReportError(GettextCatalog.GetString("Cannot execute \"{0}\"", Name), ex); } }
public async Task <bool> Execute(ProgressMonitor monitor, WorkspaceObject entry, ExecutionContext context, ConfigurationSelector configuration) { ProcessExecutionCommand cmd = CreateExecutionCommand(entry, configuration); monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", cmd.Command, cmd.Arguments)); if (!Directory.Exists(cmd.WorkingDirectory)) { monitor.ReportError(GettextCatalog.GetString("Custom command working directory does not exist"), null); return(false); } ProcessAsyncOperation oper = null; OperationConsole console = null; var result = true; try { if (context != null) { if (externalConsole) { console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole, monitor.CancellationToken); } else { console = context.ConsoleFactory.CreateConsole(monitor.CancellationToken); } oper = context.ExecutionHandler.Execute(cmd, console); } else { if (externalConsole) { console = ExternalConsoleFactory.Instance.CreateConsole(!pauseExternalConsole, monitor.CancellationToken); oper = Runtime.ProcessService.StartConsoleProcess(cmd.Command, cmd.Arguments, cmd.WorkingDirectory, console, null); } else { oper = Runtime.ProcessService.StartProcess(cmd.Command, cmd.Arguments, cmd.WorkingDirectory, monitor.Log, monitor.Log, null, false).ProcessAsyncOperation; } } using (var stopper = monitor.CancellationToken.Register(oper.Cancel)) { await oper.Task; } if (oper.ExitCode != 0) { monitor.ReportError(GettextCatalog.GetString("Custom command failed (exit code: {0})", oper.ExitCode), null); } } catch (Win32Exception w32ex) { monitor.ReportError(GettextCatalog.GetString("Failed to execute custom command '{0}': {1}", cmd.Command, w32ex.Message), null); return(false); } catch (Exception ex) { LoggingService.LogError("Command execution failed", ex); throw new UserException(GettextCatalog.GetString("Command execution failed: {0}", ex.Message)); } finally { result = oper != null && oper.ExitCode == 0; if (console != null) { console.Dispose(); } } return(result); }
public override void Dispose() { cancelReg.Dispose(); real.Dispose(); }