Exemplo n.º 1
0
        public async Task <IActionResult> Submission(int cid, int sid,
                                                     [FromServices] ISubmissionStore submissions)
        {
            int teamid = Team.TeamId;

            var models = await submissions.ListWithJudgingAsync(
                predicate : s => s.ContestId == cid && s.SubmissionId == sid,
                selector : (s, j) => new SubmissionViewModel
            {
                SubmissionId   = s.SubmissionId,
                Grade          = j.TotalScore ?? 0,
                Language       = Languages[s.Language],
                Time           = s.Time,
                Verdict        = j.Status,
                Problem        = Problems.Find(s.ProblemId),
                CompilerOutput = j.CompileError,
                SourceCode     = s.SourceCode,
            });

            var model = models.SingleOrDefault();

            if (model == null)
            {
                return(NotFound());
            }
            return(Window(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ByJudgingId(
            [FromRoute] int jid,
            [FromServices] ISubmissionStore submission)
        {
            var item = await submission.FindByJudgingAsync(jid);

            if (item == null)
            {
                return(NotFound());
            }

            if (item.ContestId == 0)
            {
                return(RedirectToAction(
                           actionName: "Detail",
                           controllerName: "Submissions",
                           new { area = "Polygon", sid = item.SubmissionId, jid, pid = item.ProblemId }));
            }
            else
            {
                return(RedirectToAction(
                           actionName: "Detail",
                           controllerName: "Submissions",
                           new { area = "Contest", cid = item.ContestId, sid = item.SubmissionId, jid }));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Home(int cid,
                                               [FromServices] ISubmissionStore submits,
                                               [FromServices] IClarificationStore clars)
        {
            int teamid = Team.TeamId;
            var board  = await FindScoreboardAsync(teamid);

            ViewBag.Clarifications = await clars.ListAsync(cid,
                                                           c => (c.Sender == null && c.Recipient == null) ||
                                                           c.Recipient == teamid || c.Sender == teamid);

            ViewBag.Submissions =
                await submits.ListWithJudgingAsync(
                    predicate : s => s.ContestId == cid && s.Author == teamid,
                    selector : (s, j) => new SubmissionViewModel
            {
                Grade        = j.TotalScore ?? 0,
                Language     = Languages[s.Language],
                SubmissionId = s.SubmissionId,
                Time         = s.Time,
                Verdict      = j.Status,
                Problem      = Problems.Find(s.ProblemId),
            });

            return(View(board));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Detail(int uid,
                                                 [FromServices] ISubmissionStore submissions,
                                                 [FromServices] ITeamStore contests)
        {
            var user = await UserManager.FindByIdAsync(uid);

            if (user == null)
            {
                return(NotFound());
            }

            ViewBag.Roles = await UserManager.ListRolesAsync(user);

            (ViewBag.Submissions, _) = await submissions.ListWithJudgingAsync(
                pagination : (1, 100),
                predicate : s => s.ContestId == 0 && s.Author == uid);

            ViewBag.Student = user.StudentId.HasValue
                ? await UserManager.FindStudentAsync(user.StudentId.Value)
                : null;

            ViewBag.Teams = await contests.ListRegisteredWithDetailAsync(uid);

            return(View(user));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> ProblemView(string prob,
                                                      [FromServices] ISubmissionStore submissions,
                                                      [FromServices] IProblemStore problems)
        {
            if (TooEarly && !ViewData.ContainsKey("IsJury"))
            {
                return(NotFound());
            }
            var problem = Problems.Find(prob);

            if (problem == null)
            {
                return(NotFound());
            }
            ViewBag.CurrentProblem = problem;

            var fileInfo = problems.GetFile(problem, "view.html");
            var view     = await fileInfo.ReadAsync();

            if (string.IsNullOrEmpty(view))
            {
                return(NotFound());
            }
            ViewData["Content"] = view;

            int pid = problem.ProblemId;
            int tid = Team?.TeamId ?? -1000;
            int cid = Contest.ContestId;

            var model = await submissions.ListWithJudgingAsync(
                s => s.ProblemId == pid && s.Author == tid && s.ContestId == cid);

            return(View(model));
        }
Exemplo n.º 6
0
 public SubmissionsController(
     ISubmissionStore s1,
     IRejudgingStore s2,
     IJudgingStore s3)
 {
     Submissions = s1;
     Rejudgings  = s2;
     Judgings    = s3;
 }
Exemplo n.º 7
0
 public ContestFacade(
     DbContextAccessor context,
     IContestStore store1,
     IProblemsetStore store2,
     ITeamStore store3,
     ISubmissionStore store4)
 {
     Context     = context;
     Contests    = store1;
     Problemset  = store2;
     Teams       = store3;
     Submissions = store4;
 }
Exemplo n.º 8
0
        public async Task <IActionResult> Show(string username,
                                               [FromServices] ISubmissionStore subMgr)
        {
            var user = await UserManager.FindByNameAsync(username);

            if (user is null)
            {
                return(NotFound());
            }
            ViewBag.User = user;
            ViewBag.Stat = await subMgr.StatisticsByUserAsync(user.Id);

            return(View());
        }
Exemplo n.º 9
0
 public KattisExportProvider(
     IProblemStore store,
     ISubmissionStore submissions,
     IExecutableStore execs,
     ITestcaseStore tcs,
     IMarkdownService markdown,
     IStaticFileRepository io2)
 {
     Store       = store;
     StaticFile  = io2;
     Markdown    = markdown;
     Submissions = submissions;
     Executables = execs;
     Testcases   = tcs;
 }
Exemplo n.º 10
0
 public DataImportProvider(
     IProblemStore store,
     ILanguageStore languages,
     IExecutableStore executables,
     ISubmissionStore submissions,
     ILogger <DataImportProvider> logger,
     IStaticFileRepository io2)
 {
     Logger      = logger;
     Store       = store;
     Languages   = languages;
     Executables = executables;
     Submissions = submissions;
     LogBuffer   = new StringBuilder();
     StaticFiles = io2;
 }
Exemplo n.º 11
0
        public async Task <IActionResult> Detail(string langid,
                                                 [FromServices] ISubmissionStore submissions)
        {
            var lang = await Store.FindAsync(langid);

            if (lang is null)
            {
                return(NotFound());
            }

            ViewBag.Language    = lang;
            ViewBag.Submissions = await submissions
                                  .ListWithJudgingAsync(s => s.Language == langid, limits : 100);

            return(View());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Submit(
            int cid, TeamCodeSubmitModel model,
            [FromServices] ISubmissionStore submissions)
        {
            if (!ViewData.ContainsKey("HasTeam"))
            {
                StatusMessage = "You should register first.";
                return(RedirectToAction(nameof(Register)));
            }

            if (TooEarly && !ViewData.ContainsKey("IsJury"))
            {
                StatusMessage = "Contest not started.";
                return(RedirectToAction(nameof(Home)));
            }

            var prob = Problems.Find(model.Problem);

            if (prob is null || !prob.AllowSubmit)
            {
                StatusMessage = "Error problem not found.";
                return(RedirectToAction(nameof(Home)));
            }

            var lang = Languages.GetValueOrDefault(model.Language);

            if (lang == null)
            {
                StatusMessage = "Error language not found.";
                return(RedirectToAction(nameof(Home)));
            }

            var s = await Facade.SubmitAsync(
                code : model.Code,
                language : lang.Id,
                problemId : prob.ProblemId,
                contest : Contest,
                teamId : Team.TeamId,
                ipAddr : HttpContext.Connection.RemoteIpAddress,
                via : "gym-page",
                username : User.GetUserName());

            await Mediator.SubmissionCreated(Contest, s);

            StatusMessage = "Submission done!";
            return(RedirectToAction(nameof(ProblemView), new { prob = prob.ShortName }));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Submissions(
            [FromServices] ISubmissionStore submissions,
            int cid, int page = 1)
        {
            if (page <= 0)
            {
                return(BadRequest());
            }

            var(model, count) = await submissions.ListWithJudgingAsync(
                pagination : (page, 50),
                predicate : s => s.ContestId == cid);

            ViewBag.Page      = page;
            ViewBag.TeamsName = await Facade.Teams.ListNamesAsync(cid);

            return(View(model));
        }
Exemplo n.º 14
0
 public KattisImportProvider(
     IProblemStore store,
     ILanguageStore languages,
     IExecutableStore executables,
     ISubmissionStore submissions,
     ILogger <KattisImportProvider> logger,
     IMarkdownService markdownService,
     IStaticFileRepository io2)
 {
     Logger      = logger;
     Store       = store;
     Languages   = languages;
     Executables = executables;
     Submissions = submissions;
     LogBuffer   = new StringBuilder();
     Markdown    = markdownService;
     StaticFiles = io2;
 }
Exemplo n.º 15
0
        public async Task <IActionResult> Files(int cid, int sid,
                                                [FromServices] ISubmissionStore submissions)
        {
            var src = await submissions.GetFileAsync(sid);

            if (src == null)
            {
                return(NotFound());
            }

            var srcDecoded = Convert.FromBase64String(src.Value.src);
            var memStream  = new MemoryStream();

            using (var zip = new ZipArchive(memStream, ZipArchiveMode.Create, true))
                zip.CreateEntryFromByteArray(srcDecoded, "Main." + src.Value.ext);
            memStream.Position = 0;
            return(File(memStream, "application/zip"));
        }
Exemplo n.º 16
0
        public async Task <ActionResult <SubmissionFile[]> > SourceCode(int cid, int sid,
                                                                        [FromServices] ISubmissionStore submissions)
        {
            var src = await submissions.GetFileAsync(sid);

            if (src == null)
            {
                return(NotFound());
            }

            return(new[]
            {
                new SubmissionFile
                {
                    id = sid.ToString(),
                    submission_id = sid.ToString(),
                    filename = "Main." + src.Value.ext,
                    source = src.Value.src
                }
            });
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Status(
            [FromServices] ISubmissionStore submissions,
            [FromQuery] int page = 1)
        {
            if (page <= 0)
            {
                return(BadRequest());
            }

            var(model, totPage) = await submissions
                                  .ListWithJudgingAsync(pagination : (page, 50));

            foreach (var item in model)
            {
                item.AuthorName = item.ContestId == 0
                    ? $"u{item.AuthorId}"
                    : $"c{item.ContestId}t{item.AuthorId}";
            }

            totPage           = (totPage - 1) / 50 + 1;
            ViewBag.Page      = page;
            ViewBag.TotalPage = totPage;
            return(View(model));
        }
Exemplo n.º 18
0
 public SubmissionsController(ISubmissionStore store)
 {
     Store = store;
 }
Exemplo n.º 19
0
        public async Task <IActionResult> Submission(int cid, int sid,
                                                     [FromServices] ISubmissionStore submissions,
                                                     [FromServices] IJudgingStore judgings)
        {
            if (Team == null)
            {
                return(Forbid());
            }

            var models = await submissions.ListWithJudgingAsync(
                predicate : s => s.SubmissionId == sid && s.ContestId == cid,
                selector : (s, j) => new SubmissionViewModel
            {
                SubmissionId   = s.SubmissionId,
                Verdict        = j.Status,
                Time           = s.Time,
                Problem        = Problems.Find(s.ProblemId),
                CompilerOutput = j.CompileError,
                Language       = Languages[s.Language],
                SourceCode     = s.SourceCode,
                Grade          = j.TotalScore ?? 0,
                TeamId         = s.Author,
                JudgingId      = j.JudgingId,
                ExecuteMemory  = j.ExecuteMemory,
                ExecuteTime    = j.ExecuteTime,
            });

            var model = models.SingleOrDefault();

            if (model == null)
            {
                return(NotFound());
            }
            Dictionary <int, (int ac, int tot)> substat = ViewBag.TeamStatistics;

            model.TeamName = (await FindTeamByIdAsync(model.TeamId)).TeamName;

            if (model.TeamId != Team.TeamId)
            {
                if (Contest.StatusAvaliable == 2)
                {
                    if (substat.GetValueOrDefault(model.Problem.ProblemId).ac == 0)
                    {
                        return(Forbid());
                    }
                }
                else if (Contest.StatusAvaliable == 0)
                {
                    return(Forbid());
                }
            }

            var tcs = await judgings.GetDetailsAsync(model.Problem.ProblemId, model.JudgingId);

            if (!model.Problem.Shared)
            {
                tcs = tcs.Where(t => !t.Item2.IsSecret);
            }
            ViewBag.Runs = tcs;

            return(Window(model));
        }
Exemplo n.º 20
0
 public AnalysisController(ISubmissionStore store)
 {
     Store = store;
 }
Exemplo n.º 21
0
 public ProblemController(IArchiveStore probs, ISubmissionStore submits)
 {
     Store   = probs;
     Submits = submits;
 }
Exemplo n.º 22
0
 public static async Task <AnalysisTwoModel> AnalysisAsync(
     ISubmissionStore store,
     Data.Contest contest,
     ContestProblem prob,
     IReadOnlyDictionary <int, (string, string)> cls)