public AssessmentResult Run(IFile solutionExecutable, IDirectory testDirectory) { string key = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); var userPassword = new SecureString(); _settings.Env.SolutionExecPassword.ForEach(userPassword.AppendChar); PortAssignment port; if (!_reservations.TryReserve(out port)) { return new AssessmentResult(AssessmentOutcome.SystemBusy) { #warning laaaaaame BuildOutput = "Sorry, the system is not able to test the solution at this time. Please push another revision later to try again." }; } using (port) { AssessmentResult result; // start process Process solutionProcess; var solutionOutput = new StringWriter(); try { var solutionArgs = "{0} {1}".FormatFrom(port.Number, key); _log.DebugFormat("{0} {1}", solutionExecutable.Path, solutionArgs); var solutionOutputSync = TextWriter.Synchronized(solutionOutput); solutionProcess = _shell.StartBackgroundProcess( new ProcessStartInfo(solutionExecutable.Path, solutionArgs) { WorkingDirectory = solutionExecutable.Parent().Path }, solutionOutputSync.WriteLine, solutionOutputSync.WriteLine); if (solutionProcess == null) { throw new Exception("Failed to start process"); } } catch (Exception ex) { _log.Warn("Error starting process {0}".FormatFrom(solutionExecutable), ex); return new AssessmentResult(AssessmentOutcome.SolutionFailure) { BuildOutput = "Error starting solution: {0}".FormatFrom(ex.Summary()) }; } try { // verify http if (CheckHttpResponse(solutionProcess, port.Number, key, out result)) { // run tests result = RunTests(testDirectory, port.Number); } } finally { try { solutionProcess.Kill(); solutionProcess.Dispose(); } catch { } } if (result.Outcome == AssessmentOutcome.SolutionFailure) { result.BuildOutput = solutionOutput.ToString(); } return result; } }