public EvaluationResultEventArgs(Problem problem, ProblemTest test, SubmissionResult result, Status status) { Problem = problem; Test = test; Result = result; Status = status; }
public void Evaluate(SubmissionJson submission) { Console.WriteLine("Evaluation Started"); ICompiler compiler = CompilerFactory.GetCompiler(submission.Language); string executablePath = String.Empty; string testsFolder = String.Empty; if (compiler != null) { if (compiler.Compile(submissionsPaths[submission.Id], out executablePath)) { Console.WriteLine("Source successfully compiled"); testsFolder = @"b:\tests\"; File.Copy(executablePath, @"b:\tests\a.exe", true); foreach (var test in repository.Tests) { ProblemTest problemTest = new ProblemTest() { Id = test.Id, Name = test.Name, Data = test.Data }; Execution execution = worker.Execute2(@"b:\tests\adunare", problemTest, null); } } else { Console.WriteLine("Source has compiled with errors"); } } }
public Execution Execute(string testsPath, ProblemTest test, Problem problem) { Execution execution; try { CopyTestToWorkArea(testsPath + test.Name + Constants.In, problem); ProcessStartInfo psi = new ProcessStartInfo(workingPath + problem.Name + Constants.exe); psi.WorkingDirectory = workingPath; psi.UseShellExecute = false; psi.CreateNoWindow = true; Process exec = new Process(); exec.StartInfo = psi; bool hasExited = false; double totalMilliseconds = 0; lock (flag) { exec.Start(); exec.WaitForExit(problem.TimeLimit + 230); totalMilliseconds = exec.TotalProcessorTime.TotalMilliseconds; if (!(hasExited = exec.HasExited)) { exec.CloseMainWindow(); exec.Kill(); } exec.Dispose(); Thread.Sleep(250); } string outputFilePath = workingPath + problem.Name + Constants.Out; execution = new Execution(hasExited, (int)totalMilliseconds, 0, GetOutputString(outputFilePath), File.Exists(outputFilePath)); DeleteOutputFile(outputFilePath); } catch (Exception e) { execution = new Execution(false, 0, 0, e.Message, false); } return(execution); }
public Execution Execute2(string testsPath, ProblemTest test, Problem problem) { Execution status; try { CopyTestToWorkArea(testsPath + test.Name + Constants.In, problem); ProcessStartInfo psi = new ProcessStartInfo(workingPath + problem.Name + Constants.exe); psi.WorkingDirectory = workingPath; psi.UseShellExecute = false; psi.CreateNoWindow = true; Process exec = new Process(); exec.StartInfo = psi; bool hasExited = false; double totalMilliseconds = 0; double memoryUsed = 0; lock (flag) { exec.Start(); var ts = new CancellationTokenSource(); Task.Run(() => { Thread.Sleep(5); try { while (!exec.HasExited) { try { var m = exec.WorkingSet64 / 1024.0 / 1024.0; if (m > memoryUsed) { memoryUsed = m; } } catch (Exception e) { var x = e.Message; } } } catch { } }, ts.Token); exec.WaitForExit(problem.TimeLimit + 200); totalMilliseconds = exec.TotalProcessorTime.TotalMilliseconds; if (!(hasExited = exec.HasExited)) { exec.CloseMainWindow(); exec.Kill(); } ts.Cancel(); exec.Dispose(); Thread.Sleep(250); } string outputFilePath = workingPath + problem.Name + Constants.Out; status = new Execution(hasExited, (int)totalMilliseconds, memoryUsed, GetOutputString(outputFilePath), File.Exists(outputFilePath)); DeleteOutputFile(outputFilePath); } catch (Exception e) { status = new Execution(false, 0, 0, e.Message, false); } return(status); }