private async Task LoadSubmissionsAsync(XElement sols, ZipArchive zip)
        {
            var langs = await Languages.ListAsync();

            foreach (var sol in sols.Elements("solution"))
            {
                var source   = sol.Element("source");
                var fileName = source.Attribute("path").Value;
                var file     = zip.GetEntry(fileName);
                var tag      = sol.Attribute("tag").Value;

                var lang = langs.FirstOrDefault(l =>
                                                "." + l.FileExtension == Path.GetExtension(file.FullName));

                if (lang == null)
                {
                    Log($"No language found for jury solution '{file.FullName}'.");
                }
                else
                {
                    var expected = Verds.GetValueOrDefault(tag);

                    using var stream = file.Open();
                    using var reader = new StreamReader(stream);
                    var content = await reader.ReadToEndAsync();

                    var sub = await Submissions.CreateAsync(
                        code : content,
                        language : lang.Id,
                        problemId : Problem.ProblemId,
                        contestId : null,
                        userId : 0,
                        ipAddr : System.Net.IPAddress.Parse("127.0.0.1"),
                        via : "polygon-upload",
                        username : "******",
                        expected : expected);

                    Log($"Jury solution '{file.FullName}' saved s{sub.SubmissionId}.");
                }
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Submit(
            CodeSubmitModel model,
            [FromServices] ILanguageStore langs)
        {
            var lang = await langs.FindAsync(model.Language);

            if (lang == null)
            {
                return(BadRequest());
            }

            var sub = await Submissions.CreateAsync(
                code : model.Code,
                language : lang.Id,
                problemId : Problem.ProblemId,
                contestId : null,
                userId : int.Parse(User.GetUserId()),
                ipAddr : HttpContext.Connection.RemoteIpAddress,
                via : "polygon-page",
                username : User.GetUserName(),
                expected : Verdict.Unknown);

            return(RedirectToAction(nameof(Detail), new { sid = sub.SubmissionId }));
        }
Beispiel #3
0
        private async Task LoadSubmissionsAsync(ZipArchive zip)
        {
            var prefix = "submissions/";
            var files  = zip.Entries
                         .Where(z => z.FullName.StartsWith(prefix) && !z.FullName.EndsWith('/'))
                         .ToList();
            var langs = await Languages.ListAsync();

            foreach (var file in files)
            {
                if (file.Length > 65536)
                {
                    Log($"Too big for jury solution '{file.FullName}'");
                    continue;
                }

                var lang = langs.FirstOrDefault(l =>
                                                "." + l.FileExtension == Path.GetExtension(file.FullName));

                if (lang == null)
                {
                    Log($"No language found for jury solution '{file.FullName}'.");
                }
                else
                {
                    var expected = Verdict.Unknown;
                    if (file.FullName.StartsWith("submissions/accepted/"))
                    {
                        expected = Verdict.Accepted;
                    }
                    if (file.FullName.StartsWith("submissions/wrong_answer/"))
                    {
                        expected = Verdict.WrongAnswer;
                    }
                    if (file.FullName.StartsWith("submissions/time_limit_exceeded/"))
                    {
                        expected = Verdict.TimeLimitExceeded;
                    }
                    if (file.FullName.StartsWith("submissions/run_time_error/"))
                    {
                        expected = Verdict.RuntimeError;
                    }

                    using var stream = file.Open();
                    using var reader = new StreamReader(stream);
                    var content = await reader.ReadToEndAsync();

                    var sub = await Submissions.CreateAsync(
                        code : content,
                        language : lang.Id,
                        problemId : Problem.ProblemId,
                        contestId : null,
                        userId : 0,
                        ipAddr : System.Net.IPAddress.Parse("127.0.0.1"),
                        via : "polygon-upload",
                        username : "******",
                        expected : expected);

                    Log($"Jury solution '{file.FullName}' saved s{sub.SubmissionId}.");
                }
            }
        }