/// <summary> /// Initiate a CF CLI command process by invoking the <see cref="CommandProcessService"/>. /// This method is asynchronous, meaning it cannot be used within a lock statement. /// </summary> /// <param name="arguments"></param> /// <param name="stdOutCallback"></param> /// <param name="stdErrCallback"></param> /// <param name="workingDir"></param> /// <param name="cancellationTriggers"></param> /// <returns>An awaitable <see cref="Task"/> which will return a <see cref="DetailedResult"/> containing the results of the CF command.</returns> internal async Task <DetailedResult> RunCfCommandAsync(string arguments, Action <string> stdOutCallback = null, Action <string> stdErrCallback = null, string workingDir = null, List <string> cancellationTriggers = null) { string pathToCfExe = _fileService.FullPathToCfExe; if (string.IsNullOrEmpty(pathToCfExe)) { return(new DetailedResult(false, $"Unable to locate cf.exe.")); } var envVars = new Dictionary <string, string> { { "CF_HOME", ConfigFilePath } }; ICommandProcessService cmdProcessService = Services.GetRequiredService <ICommandProcessService>(); CommandResult result = await Task.Run(() => cmdProcessService.RunExecutable(pathToCfExe, arguments, workingDir, envVars, stdOutCallback, stdErrCallback, processCancelTriggers: cancellationTriggers)); if (result.ExitCode == 0) { return(new DetailedResult(succeeded: true, cmdResult: result)); } string reason = result.StdErr; if (string.IsNullOrEmpty(result.StdErr)) { if (result.StdOut.Contains("FAILED")) { reason = result.StdOut; } else { reason = $"Unable to execute `cf {arguments}`."; } } return(new DetailedResult(false, reason, cmdResult: result)); }
/// <summary> /// Invoke a CF CLI command using the <see cref="CommandProcessService"/>. /// This method is synchronous, meaning it can be used within a lock statement. /// </summary> /// <param name="arguments"></param> /// <param name="stdOutCallback"></param> /// <param name="stdErrCallback"></param> /// <param name="workingDir"></param> /// <returns>A <see cref="DetailedResult"/> containing the results of the CF command.</returns> internal DetailedResult ExecuteCfCliCommand(string arguments, string workingDir = null) { string pathToCfExe = _fileService.FullPathToCfExe; if (string.IsNullOrEmpty(pathToCfExe)) { return(new DetailedResult(false, _cfExePathErrorMsg)); } var envVars = new Dictionary <string, string> { { "CF_HOME", ConfigFilePath } }; ICommandProcessService cmdProcessService = Services.GetRequiredService <ICommandProcessService>(); CommandResult result = cmdProcessService.RunExecutable(pathToCfExe, arguments, workingDir, envVars); if (result.ExitCode == 0) { return(new DetailedResult(succeeded: true, cmdResult: result)); } string reason = result.StdErr; if (string.IsNullOrEmpty(result.StdErr)) { if (result.StdOut.Contains("FAILED")) { reason = result.StdOut; } else { reason = $"Unable to execute `cf {arguments}`."; } } return(new DetailedResult(false, reason, cmdResult: result)); }