Example #1
0
        public static async Task <SubmissionModel> GetAsync(SubmissionMetadata metadata, HttpClient client)
        {
            SubmissionModel res = new SubmissionModel
            {
                Metadata = metadata
            };

            try
            {
                SubmissionsClient scli = new SubmissionsClient(client);
                res.Result = await scli.GetResultAsync(metadata.Id);
            }
            catch
            {
                res.Result = new SubmissionResult
                {
                    State = JudgeState.Pending
                };
            }
            try
            {
                SubmissionsClient scli = new SubmissionsClient(client);
                using (FileResponse file = await scli.GetCodeAsync(metadata.Id))
                    using (StreamReader sr = new StreamReader(file.Stream))
                        res.Code = await sr.ReadToEndAsync();
            }
            catch
            {
                res.Code = "<Loading error>.";
            }
            try
            {
                ProblemsClient pcli = new ProblemsClient(client);
                res.Problem = await pcli.GetAsync(metadata.ProblemId);
            }
            catch
            {
                res.Problem = new ProblemMetadata
                {
                    Id   = res.Metadata.ProblemId,
                    Name = $"Not found: {res.Metadata.ProblemId}"
                };
            }
            try
            {
                UsersClient ucli = new UsersClient(client);
                res.User = await ucli.GetAsync(metadata.UserId);
            }
            catch
            {
                res.User = new UserMetadata
                {
                    Id   = res.Metadata.UserId,
                    Name = $"Not found: {res.Metadata.UserId}"
                };
            }

            return(res);
        }
Example #2
0
        public async Task <IActionResult> OnPostDownloadCodeAsync()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            HttpClient        httpclient = clientFactory.CreateClient();
            SubmissionsClient client     = new SubmissionsClient(httpclient);

            try
            {
                FileResponse file = await client.GetCodeAsync(PostData.Id);

                return(File(file.Stream, "text/plain", $"{PostData.Id}.{ProgrammingLanguageHelper.Extends[PostData.Language]}"));
            }
            catch
            {
                return(NotFound());
            }
        }