public IHttpActionResult ProgrammingLanguages(SubmissionFormData data) { var context = new OjDBContext(); IEnumerable <ProgrammingLanguage> languages = context.ProgrammingLanguages.OrderBy(x => x.Name); return(Ok(ProgrammingLanguageData.MapTo(languages))); }
public Submission CreateProblemSubmission(int problem_id, SubmissionFormData submission_data) { var problem = context.Problems.Find(problem_id); var judge = new JudgeService(); if (problem == null) { throw new ObjectNotFoundException("Problem with specified id does not exist"); } // Trace.WriteLine(submission_data.ProgrammingLanguageId); var submission = InitializeSubmissionObject(problem, submission_data); context.Submissions.Add(submission); context.SaveChanges(); judge.OnSubmissionStatusChange += (sender, e) => { var result = e.ExecutionResult; submission.Status = context.SubmissionStatus.Find(result.Verdict); submission.RunningTime = result.RunningTime; submission.PeakMemmoryUsage = result.MemmoryUsage; // submission.PeakMemmoryUsage = result.Verdict == Verdict.CompilationError ? 0 : 5; // TODO REPLACE WITH REAL VALUE submission.StandardErrorStream = result.ErrorMsg; context.SaveChanges(); // this event must be emitter *after* invoking context.SaveChanges() OnSubmissionStatusChange?.Invoke(this, e); }; judge.judge(submission_data, problem); return(submission); }
public Object AllSubmissions(SubmissionFormData data) { var ctx = new OjDBContext(); var subs = ctx.Submissions.Where(x => true); return(SubmissionResponseData.MapTo(subs)); }
public Submission InitializeSubmissionObject(Problem problem, SubmissionFormData submission_data) { var language = context.ProgrammingLanguages.Find((ProgrammingLanguageEnum)submission_data.ProgrammingLanguageId); return(new Submission() { Status = context.SubmissionStatus.Find(Verdict.Running), Problem = problem, SourceCode = submission_data.SourceCode, SubmissionDate = DateTime.Now, Submitter = context.Users.Find(user_service.GetUserId()), ProgrammingLanguage = language }); }
public void CreateSubmission(int contest_id, int problem_no, SubmissionFormData submission_data) { // important: submission_repository must be initialized using this.context SubmissionRepository submission_repository = new SubmissionRepository(context); Contest contest = context.Contests.Include(x => x.Problems).FirstOrDefault(x => x.Id == contest_id); if (contest.EndDate < DateTime.Now) { throw new InvalidOperationException("Can not create submission to contest that has ended"); } if (contest.StartDate > DateTime.Now) { throw new InvalidOperationException("Can not create submission to contest that has not started"); } ContestProblem contest_problem = contest.Problems.FirstOrDefault(x => x.Order == problem_no); Problem problem = contest_problem.Problem; submission_repository.OnSubmissionStatusChange += (Object sender, ExecutionResultEventArgs args) => { // the submission entry is updated by SubmissionRepository, // this handler only updates the contestant // replace with real user var contestant = context.Contestants.Include(x => x.Submissions).First(x => x.Contest.Id == contest_id); contestant.Penalty = contest_service.CalclatePenalty(contestant.Submissions); contestant.SolveCount = context.ContestProblems.Count(x => x.Submissions. Count(y => y.Submission.Status.Id == Verdict.Accepted) > 0); context.SaveChanges(); }; User submitter = context.Users.First(); Submission submission = submission_repository.CreateProblemSubmission(problem.Id, submission_data); ContestSubmission contest_submission = new ContestSubmission() { Submitter = context.Contestants.First(x => x.Contest.Id == contest_id && x.User.Id == submitter.Id), Problem = contest_problem, Submission = submission, }; contest.Submissions.Add(contest_submission); context.SaveChanges(); }
public void judge(SubmissionFormData submissison, Problem problem) { int problem_code = problem.Id; logger.Info(String.Format("Submission recieved from user {0}, for Problem {1}", 1, problem_code)); var runner = new JudgeCodeRunner.CodeRunner((ProgrammingLanguageEnum)submissison.ProgrammingLanguageId, submissison.SourceCode, problem.TestCaseInput, problem.TestCaseOutput, problem.TimeLimit); runner.OnExecutionFinished += (sender, e) => { logger.Info("Execution finished"); OnSubmissionStatusChange(this, new ExecutionResultEventArgs(e.ExecutionResult)); }; runner.RunCode(); }
public IHttpActionResult Submit(int problem_id, [FromBody] SubmissionFormData data) { if (!user_service.IsAuthorizedToSubmitToProblem(problem_id)) { return(Unauthorized()); } if (RequestUtility.IsPreFlightRequest(Request)) { return(Ok()); } try{ submission_repository.CreateProblemSubmission(problem_id, data); return(Ok()); } catch (ObjectNotFoundException e) { return(NotFound()); } }
public IHttpActionResult ContestProblemSubmit(int contest_id, int problem_no, [FromBody] SubmissionFormData submission_data) { if (!user_service.IsAuthorizedToSubmitToContest(contest_id)) { return(Unauthorized()); } if (RequestUtility.IsPreFlightRequest(Request)) { return(Ok()); } try{ contest_submission_repository.CreateSubmission(contest_id, problem_no, submission_data); return(Ok()); } catch (InvalidOperationException e) { return(BadRequest("Can not submit to contest that has ended")); } catch (ObjectNotFoundException e) { return(NotFound()); } }