public async Task <CompileResult> CompileAsync(string submissionId, string sourceCode) { PrepareDirectory(submissionId); var workspace = @"E:\ojworkspace\"; File.Copy(@"E:\ojworkspace\Main.csproj", Path.Combine(workspace, submissionId, "Main.csproj")); var submissionFolder = Path.Combine(@"E:\ojworkspace", submissionId); File.WriteAllText(Path.Combine(submissionFolder, "Program.cs"), sourceCode); var processExecutor = new ProcessExecutor(); // TODO need to make a timeout, don't use default value in production var result = await processExecutor.Run("dotnet", "build -c Release", submissionFolder, int.MaxValue, null); var buildSucceed = result.Output.Contains("Build succeeded."); return(new CompileResult { Success = buildSucceed, Output = result.Output, Error = result.Error }); }
internal async Task RunAsync(string submissionId, int problemId) { var executable = @"bin\Release\netcoreapp2.1\Main.dll"; var workspace = @"E:\ojworkspace\"; var submissionFolder = Path.Combine(workspace, submissionId); var problem = repository.Get(problemId); var processExecutor = new ProcessExecutor(); // TODO need to parallelize this one foreach (var testCase in problem.TestCases) { var processResult = await processExecutor.Run("dotnet", executable, submissionFolder, 1000, testCase.Input); Console.WriteLine(processResult.Output.Trim() == testCase.Output.Trim()); // need to publish result on realtime } Directory.Delete(submissionFolder, true); }