protected override TaskProcessResult RunExternalTaskProcess(ITask task, TaskExecutionSettings settings) { var parameters = task.Parameters; var outFile = String.Format("{0}_{1}.txt", "out", task.TaskId); var process = new ExternalProcess { CommandPath = ExecutablePath(@"ModelBatchTest/Model.exe"), Arguments = String.Format("{0} {1} {2}", parameters["l0"], parameters["omega"], outFile), WorkingDirectory = LocalStoragePath }; try { ExternalProcessResult processOutput = process.Run(); return(TaskProcessResult.FromExternalProcessResult(processOutput, outFile)); } catch (ExternalProcessException ex) { string outputInfo = "No program output"; if (!string.IsNullOrEmpty(ex.StandardError) || !string.IsNullOrEmpty(ex.StandardOutput)) { outputInfo = Environment.NewLine + "stderr: " + ex.StandardError + Environment.NewLine + "stdout: " + ex.StandardOutput; } Log.Error("Failed to invoke command {0} {1}: exit code was {2}. {3}", ex.CommandPath, ex.Arguments, ex.ExitCode, outputInfo); } catch (Exception ex) { Log.Error("Error in task processor: {0}", ex.ToString()); } return(new TaskProcessResult { Success = TaskProcessSuccess.RetryableFailure }); }
internal async Task <string> StartGitProzess(string arguments, bool ensureSuccess, string workingFolder = "") { var process = new ExternalProcess(_logger); var output = await process.Run(workingFolder, _pathGit, arguments, ensureSuccess); return(output.Output.TrimEnd(Environment.NewLine.ToCharArray())); }
/// <summary> /// Run a, executable with a given set of arguments. /// </summary> /// <param name="exePath">Path the executable.</param> /// <param name="exeArgs">The command line arguments.</param> /// <returns>The ExternalProcessResult if run successfully, or null if an error was thrown.</returns> private ExternalProcessResult ExecuteProcess(string exePath, string exeArgs) { var process = new ExternalProcess { CommandPath = exePath, Arguments = exeArgs, WorkingDirectory = LocalStoragePath }; try { return(process.Run()); } catch (ExternalProcessException ex) { string outputInfo = "No program output"; if (!string.IsNullOrEmpty(ex.StandardError) || !string.IsNullOrEmpty(ex.StandardOutput)) { outputInfo = Environment.NewLine + "stderr: " + ex.StandardError + Environment.NewLine + "stdout: " + ex.StandardOutput; } Log.Error("Failed to invoke command {0} {1}: exit code was {2}. {3}", ex.CommandPath, ex.Arguments, ex.ExitCode, outputInfo); return(null); } catch (Exception ex) { Log.Error("Error in task processor: {0}", ex.ToString()); return(null); } }
protected override Task <int> InnerRunAsync(BuildArgs args, ILogger log) { log.Info($"Starting {nameof(SolutionBuild)}"); var dotnetAction = args.Publish ? "Publish" : "Build"; foreach (var project in args.ReleaseProjects) { var actionBlock = $"{dotnetAction.ToLowerInvariant()} \"{project.FullName()}\" --configuration {args.Configuration} --verbosity quiet /p:Version={args.Version.SemVer20String}"; if (args.Publish) { actionBlock += $" --runtime {args.Runtime}"; } else { actionBlock += $" --no-incremental"; } log.Info($"{dotnetAction}ing {project.NameWoExtension.Highlight()}"); log.Info(actionBlock.Highlight()); var exitCode = ExternalProcess.Run("dotnet", actionBlock, log.Debug, log.Error); if (exitCode != 0) { throw new CliException($"{dotnetAction} failed for {project.NameWoExtension.Highlight()}. See logs for details", 400); } } return(Task.FromResult(0)); }
public async Task InvalidCommandShouldFail() { var process = new ExternalProcess(); var result = await process.Run(Guid.NewGuid().ToString("N"), false); Assert.That(result.ExitCode, Is.Not.EqualTo(0)); Assert.That(result.ErrorOutput, Is.Not.Empty); Assert.That(result.Success, Is.False); }
public async Task ValidCommandShouldSucceed() { var process = new ExternalProcess(); var result = await process.Run("dir", false); Assert.That(result.ExitCode, Is.EqualTo(0)); Assert.That(result.Output, Is.Not.Empty); Assert.That(result.Success, Is.True); }
protected bool Execute() { File.Copy("SafetySharp.Modeling.dll", Path.Combine(_directory, "Binaries/Release/SafetySharp.Modeling.dll"), overwrite: true); var process = new ExternalProcess(Path.Combine(_directory, "Binaries/Release/Test.exe"), ""); process.Run(); return(process.ExitCode == 0); }
protected bool Compile(string testFile) { var projectPath = Path.Combine(_directory, "TestProject.csproj"); File.Copy("End2End/Files/TestProject.csproj", projectPath, overwrite: true); File.Copy(Path.Combine("End2End/Files", testFile), Path.Combine(_directory, "TestCode.cs"), overwrite: true); var msbuildPath = ToolLocationHelper.GetPathToBuildTools(ToolLocationHelper.CurrentToolsVersion); var process = new ExternalProcess(Path.Combine(msbuildPath, "msbuild.exe"), $"\"{projectPath}\" /p:Configuration=Release /p:Platform=AnyCPU /nr:false", message => Output.Log("{0}", message)); process.Run(); return(process.ExitCode == 0); }
/// <summary> /// Runs the <see cref="_ltsMin" /> process instance. /// </summary> private void Run() { var stopwatch = new Stopwatch(); stopwatch.Start(); _ltsMin.Run(); stopwatch.Stop(); OutputWritten?.Invoke(String.Empty); OutputWritten?.Invoke("====================================="); OutputWritten?.Invoke($"Elapsed time: {stopwatch.Elapsed}"); OutputWritten?.Invoke("====================================="); OutputWritten?.Invoke(String.Empty); }
/// <summary> /// Executes the external process for processing the task /// </summary> /// <param name="task">The task to be processed.</param> /// <param name="settings">Contains information about the processing request.</param> /// <returns>The result of task processing.</returns> protected override TaskProcessResult RunExternalTaskProcess(ITask task, TaskExecutionSettings settings) { var process = new ExternalProcess { CommandPath = ExecutablePath(@"TitanSpikeClusterer.exe"), Arguments = string.Format("ClusterWorkerBlockRange {8} {0} {1} {2} {3} {4} {5} {6} {7}", task.Parameters["HostName"], task.Parameters["DataFileName"], task.Parameters["NumChannels"], task.Parameters["OutFileName"], task.Parameters["MinTemp"], task.Parameters["MaxTemp"], task.Parameters["FirstBlock"], task.Parameters["NumBlocks"], LocalPath("Clusterer")), WorkingDirectory = LocalStoragePath }; try { ExternalProcessResult processOutput = process.Run(); return(new TaskProcessResult { Success = TaskProcessSuccess.Succeeded }); } catch (ExternalProcessException ex) { string outputInfo = "No program output"; if (!string.IsNullOrEmpty(ex.StandardError) || !string.IsNullOrEmpty(ex.StandardOutput)) { outputInfo = Environment.NewLine + "stderr: " + ex.StandardError + Environment.NewLine + "stdout: " + ex.StandardOutput; } Log.Error("Failed to invoke command {0} {1}: exit code was {2}. {3}", ex.CommandPath, ex.Arguments, ex.ExitCode, outputInfo); } catch (Exception ex) { Log.Error("Error in task processor: {0}", ex.ToString()); } return(new TaskProcessResult { Success = TaskProcessSuccess.RetryableFailure }); }
private TemporaryFile WriteFilesAndExecuteMrmc(Formula formulaToCheck, bool outputExactResult) //returns result file { WriteMarkovChainToDisk(); var transformationVisitor = new MrmcTransformer(); transformationVisitor.Visit(formulaToCheck); var formulaToCheckString = transformationVisitor.TransformedFormula; bool useRewards; _initialStates = new Dictionary <int, double>(); var enumerator = MarkovChain.GetEnumerator(); enumerator.SelectInitialDistribution(); while (enumerator.MoveNextTransition()) { //enumerate initial states var entry = enumerator.CurrentTransition; var index = entry.Column + 1; //index in mrmc is 1-based if (_initialStates.ContainsKey(index)) { _initialStates.Add(index, _initialStates[index] + entry.Value); } else { _initialStates.Add(index, entry.Value); } } var fileResults = new TemporaryFile("res"); using (var fileCommandScript = new TemporaryFile("cmd")) using (var fileStateRewards = WriteRewardsToFile(formulaToCheck, out useRewards)) { var script = new StringBuilder(); script.AppendLine("set method_path gauss_jacobi"); //warning: gauss_seidel seems to be buggy in MRMC script.AppendLine("set error_bound 1.0E-6"); script.AppendLine(formulaToCheckString); //write result of every initial state to file if (outputExactResult) { script.Append("write_res_file_result"); } else { script.Append("write_res_file_state"); } foreach (var initialState in _initialStates) { script.Append(" " + (initialState.Key)); } script.AppendLine(); script.AppendLine("quit"); File.WriteAllText(fileCommandScript.FilePath, script.ToString()); var commandLineMode = useRewards ? "dmrm" : "dtmc"; var commandLineArgumentTransitionFile = $" {_fileTransitions.FilePath}"; var commandLineArgumentStateLabelingFile = $" {_fileStateLabelings.FilePath}"; var commandLineArgumentRewardFile = fileStateRewards != null ? $" {fileStateRewards.FilePath}" : ""; var commandLineArgumentCommandScriptFile = $" {fileCommandScript.FilePath}"; var commandLineArgumentResultsFile = $" {fileResults.FilePath}"; var commandLineArguments = commandLineMode + commandLineArgumentTransitionFile + commandLineArgumentStateLabelingFile + commandLineArgumentRewardFile + commandLineArgumentCommandScriptFile + commandLineArgumentResultsFile; var pureModelCheckingTime = ""; var iterations = ""; Action <string> extractInterestingOutput = output => { if (output.StartsWith("The Total Elapsed Model-Checking Time")) { pureModelCheckingTime = output; } else if (output.StartsWith("Gauss Jacobi V_B: The number of Gauss-Jacobi iterations")) { iterations = output; } }; var mrmc = new ExternalProcess("mrmc.exe", commandLineArguments, extractInterestingOutput); var stopwatch = new Stopwatch(); stopwatch.Start(); mrmc.Run(); stopwatch.Stop(); _output?.WriteLine(iterations); _output?.WriteLine(pureModelCheckingTime); _output?.WriteLine($"MRMC total model checking time: {stopwatch.Elapsed}"); } return(fileResults); }
private static async Task <ProcessOutput> RunExternalProcess(string command, string args, bool ensureSuccess) { IExternalProcess process = new ExternalProcess(); return(await process.Run(".", command, args, ensureSuccess)); }
private static BlameResult GetBlameOutput(string repositoryPath, string fileName, string blameCommitId, string[] currentLines) { BlameResult blameResult; using (var repo = new Repository(repositoryPath)) { // try to determine if the remote URL is plausibly a github.com or GitHub Enterprise URL Uri webRootUrl = repo.Network.Remotes .OrderBy(x => x.Name == "origin" ? 0 : 1) .ThenBy(x => x.Name) .Select(x => { Match m = Regex.Match(x.Url, @"^(git@(?'host'[^:]+):(?'user'[^/]+)/(?'repo'[^/]+)\.git|(git|https?)://(?'host'[^/]+)/(?'user'[^/]+)/(?'repo'[^/]+)\.git)$", RegexOptions.ExplicitCapture); if (m.Success) { string host = m.Groups["host"].Value; return(new Uri(string.Format("http{0}://{1}/{2}/{3}/", host == "github.com" ? "s" : "", host, m.Groups["user"].Value, m.Groups["repo"].Value))); } else { return(null); } }).FirstOrDefault(x => x != null); var loadingPerson = new Person("Loading…", "loading"); var commit = new Commit(UncommittedChangesCommitId, loadingPerson, DateTimeOffset.Now, loadingPerson, DateTimeOffset.Now, "", null, null); // create a fake blame result that assigns all the code to the HEAD revision blameResult = new BlameResult(webRootUrl, new[] { new Block(1, currentLines.Length, commit, fileName, 1) }.AsReadOnly(), currentLines.Select((l, n) => new Line(n + 1, l, true)).ToList(), new Dictionary <string, Commit> { { commit.Id, commit } }); } Task.Run(() => { // run "git blame" ExternalProcess git = new ExternalProcess(GetGitPath(), Path.GetDirectoryName(repositoryPath)); List <string> arguments = new List <string> { "blame", "--incremental", "--encoding=utf-8" }; if (blameCommitId != null) { arguments.Add(blameCommitId); } arguments.AddRange(new[] { "--", fileName }); var results = git.Run(new ProcessRunSettings(arguments.ToArray())); if (results.ExitCode != 0) { return; } // parse output List <Block> blocks = new List <Block>(); Dictionary <string, Commit> commits = new Dictionary <string, Commit>(); ParseBlameOutput(results.Output, blocks, commits); // allocate a (1-based) array for all lines in the file int lineCount = blocks.Sum(b => b.LineCount); Invariant.Assert(lineCount == currentLines.Length, "Unexpected number of lines in file."); // initialize all lines from current version Line[] lines = currentLines .Select((l, n) => new Line(n + 1, l, false)) .ToArray(); blameResult.SetData(blocks, lines, commits); Dictionary <string, Task <string> > getFileContentTasks = CreateGetFileContentTasks(repositoryPath, blocks, commits, currentLines); // process the blocks for each unique commit foreach (var groupLoopVariable in blocks.OrderBy(b => b.StartLine).GroupBy(b => b.Commit)) { // check if this commit modifies a previous one var group = groupLoopVariable; Commit commit = group.Key; string commitId = commit.Id; string previousCommitId = commit.PreviousCommitId; if (previousCommitId != null) { // diff the old and new file contents when they become available Task <string> getOldFileContentTask = getFileContentTasks[previousCommitId]; Task <string> getNewFileContentTask = getFileContentTasks[commitId]; Task.Factory.ContinueWhenAll(new[] { getOldFileContentTask, getNewFileContentTask }, tasks => { // diff the two versions var oldFileContents = tasks[0].Result; var newFileContents = tasks[1].Result; // diff_match_patch can generate incorrect output if there are more than 65536 lines being diffed var checkLines = GetLineCount(oldFileContents) < 65000 && GetLineCount(newFileContents) < 65000; var diff = new diff_match_patch { Diff_Timeout = 10 }; var diffs = diff.diff_main(oldFileContents, newFileContents, checkLines); diff.diff_cleanupSemantic(diffs); // process all the lines in the diff output, matching them to blocks using (IEnumerator <Line> lineEnumerator = ParseDiffOutput(diffs).GetEnumerator()) { // move to first line (which is expected to always be present) Invariant.Assert(lineEnumerator.MoveNext(), "Expected at least one line from diff output."); Line line = lineEnumerator.Current; // process all the blocks, finding the corresponding lines from the diff for each one foreach (Block block in group) { // skip all lines that occurred before the start of this block while (line.LineNumber < block.OriginalStartLine) { Invariant.Assert(lineEnumerator.MoveNext(), "diff does not contain the expected number of lines."); line = lineEnumerator.Current; } // process all lines in the current block while (line.LineNumber >= block.OriginalStartLine && line.LineNumber < block.OriginalStartLine + block.LineCount) { // assign this line to the correct index in the blamed version of the file blameResult.SetLine(line.LineNumber - block.OriginalStartLine + block.StartLine, line); // move to the next line (if available) if (lineEnumerator.MoveNext()) { line = lineEnumerator.Current; } else { break; } } } } }); } else { // this is the initial commit (but has not been modified since); grab its lines from the current version of the file foreach (Block block in group) { for (int lineNumber = block.StartLine; lineNumber < block.StartLine + block.LineCount; lineNumber++) { blameResult.SetLine(lineNumber, new Line(lineNumber, currentLines[lineNumber - 1], true)); } } } } }); return(blameResult); }
private static async Task <ProcessOutput> RunExternalProcess(string command, string args, bool ensureSuccess) { IExternalProcess process = new ExternalProcess(Substitute.For <INuKeeperLogger>()); return(await process.Run(".", command, args, ensureSuccess)); }
public static void ServiceCommand(string arguments) { var stdOut = ExternalProcess.Run("ThumbsUp.Service.exe", arguments); C.WriteLine(stdOut); }
public void InvalidCommandShouldThrowWhenSuccessIsEnsured() { var process = new ExternalProcess(); Assert.ThrowsAsync <Exception>(() => process.Run(Guid.NewGuid().ToString("N"), true)); }