public CommandResult ExecuteCommand(string command, IOutputReceiver receiver = null, Type resultType = null, params string[] arguments) { if (receiver == null) { receiver = new OutputCollector(); } int exitCode = 0; string commandline = $"{command} {string.Join(" ", arguments)}"; using (ProcessFacade f = new ProcessFacade(PlcncliCommand, commandline, receiver, CancellationToken.None)) { f.WaitForExit(); exitCode = f.ExitCode; } if (exitCode != 0) { throw new PlcncliException(command, receiver.InfoMessages, receiver.ErrorMessages); } if (resultType == null) { return(null); } List <string> infos = receiver.InfoMessages; var result = JsonConvert.DeserializeObject(string.Join("", infos.SkipWhile(s => !s.Trim().StartsWith("{"))), resultType ?? typeof(CommandResult)); return(result as CommandResult); }
private static void PrintError(string output, PluginManager pluginManager) { foreach (IOutputReceiver plugin in pluginManager.OutputReceiverPlugins) { PluginContainer container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { IOutputReceiver plugin1 = plugin; PluginCommand(() => { plugin1.OnErrorOutput(output); }, container, "Failed in ReactToChangedFile"); } } // Execute the new style plugins var plugins = pluginManager.ImportedPlugins.Where(x => x.OnErrorOutputHandler != null); foreach (var plugin in plugins) { var container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { PluginBase plugin1 = plugin; PluginCommand(() => { plugin1.OnErrorOutputHandler(output); }, container, "Failed in OnErrorOutput"); } } }
public int ExecuteCommand(Command command, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags) { OnCommandExecuting(command); var executor = CreateProcessExecutor(); var exitCode = executor.Execute(PrepareInput(command, GitProcess.DefaultEncoding), stdOutReceiver, stdErrReceiver); return exitCode; }
public int ExecuteCommand(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags) { OnCommandExecuting(command); var executor = CreateProcessExecutor(); var exitCode = executor.Execute(PrepareInput(command, encoding), stdOutReceiver, stdErrReceiver); return(exitCode); }
public ProcessFacade(string fileName, string arguments, IOutputReceiver outputReceiver, CancellationToken cancellationToken) { _killOnDispose = true; _outputReceiver = outputReceiver; ProcessStartInfo processInfo = new ProcessStartInfo(fileName, arguments) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true }; Debug.WriteLine($"Starting process {processInfo.FileName} {processInfo.Arguments} in {processInfo.WorkingDirectory}."); _internalProcess = Process.Start(processInfo); if (_internalProcess != null && !_internalProcess.HasExited) { try { _processName = _internalProcess.ProcessName; _internalProcess.OutputDataReceived += InternalProcessOnOutputDataReceived; _internalProcess.ErrorDataReceived += InternalProcessOnErrorDataReceived; _internalProcess.EnableRaisingEvents = true; _internalProcess.Exited += InternalProcessOnExited; _internalProcess.BeginOutputReadLine(); _outputReadStarted = true; _internalProcess.BeginErrorReadLine(); _errorReadStarted = true; } catch (Exception e) { _processName = "unknown process"; Debug.WriteLine($"Error while starting process: {e}"); //this happens when the process exits somewhere in this if clause } cancellationToken.Register(Dispose); } else { _processName = "unknown process"; } }
public void ExecuteWithoutResult(string command, IOutputReceiver receiver = null, params string[] arguments) { if (receiver == null) { receiver = new OutputCollector(); } int exitCode = 0; string commandline = $"{command} {string.Join(" ", arguments)}"; receiver.LogDebugInfo($"Starting process {PlcncliCommand} with options {commandline}"); using (ProcessFacade f = new ProcessFacade(PlcncliCommand, commandline, receiver, CancellationToken.None)) { f.WaitForExit(); exitCode = f.ExitCode; } if (exitCode != 0) { throw new PlcncliException(command, receiver.InfoMessages, receiver.ErrorMessages); } }
public Task <int> ExecuteCommandAsync(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(command, "command"); return(ExecuteCommandAsyncCore(command, encoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken)); }
private Task <int> ExecuteCommandAsyncCore(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken) { OnCommandExecuting(command); var input = PrepareInput(command, encoding); var processExecutor = CreateProcessExecutor(); var cancellationMethod = GetCancellationMethod(flags); return(processExecutor.ExecuteAsync( input, stdOutReceiver, stdErrReceiver, cancellationMethod, cancellationToken)); }
public IntcodeComputerBuilder WithOutputReceiver(IOutputReceiver outputReceiver) { _outputReceiver = outputReceiver; return(this); }
public IntcodeComputer(IInputSender inputSender, IOutputReceiver outputReceiver, IInstructionParser instructionParser) { _inputSender = inputSender; _outputReceiver = outputReceiver; _instructionParser = instructionParser; }
public Task <int> ExecuteCommandAsync(Command command, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(command, nameof(command)); return(ExecuteCommandAsyncCore(command, GitProcess.DefaultEncoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken)); }
private Task<int> ExecuteCommandAsyncCore(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken) { OnCommandExecuting(command); var input = PrepareInput(command, encoding); var processExecutor = CreateProcessExecutor(); var cancellationMethod = GetCancellationMethod(flags); return processExecutor.ExecuteAsync( input, stdOutReceiver, stdErrReceiver, cancellationMethod, cancellationToken); }
public Task<int> ExecuteCommandAsync(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(command, "command"); return ExecuteCommandAsyncCore(command, encoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken); }