async Task <bool> GetData(string id) { HttpClient httpclient = clientFactory.CreateClient(); ProblemsClient client = new ProblemsClient(httpclient); try { ProblemMetadata metadata = await client.GetAsync(id); Problem = await ProblemModel.GetAsync(metadata, httpclient, false, true); } catch { return(false); } TestCasePreviewModel emptyTestCase = new TestCasePreviewModel { Metadata = new TestCaseMetadata { Id = "empty", TimeLimit = TimeSpan.FromSeconds(1), MemoryLimit = 128 * MemoryValueHelper.MB, }, IsNew = true, }; { List <TestCasePreviewModel> ls = new List <TestCasePreviewModel>(); foreach (TestCaseMetadata item in Problem.Samples) { ls.Add(new TestCasePreviewModel { Metadata = item, Input = await client.GetSampleInputPreviewAsync(Problem.Metadata.Id, item.Id, MaxPreviewBytes), Output = await client.GetSampleOutputPreviewAsync(Problem.Metadata.Id, item.Id, MaxPreviewBytes), IsNew = false, }); } ls.Add(emptyTestCase); SamplePreview = ls; } { List <TestCasePreviewModel> ls = new List <TestCasePreviewModel>(); foreach (TestCaseMetadata item in Problem.Tests) { ls.Add(new TestCasePreviewModel { Metadata = item, Input = await client.GetTestInputPreviewAsync(Problem.Metadata.Id, item.Id, MaxPreviewBytes), Output = await client.GetTestOutputPreviewAsync(Problem.Metadata.Id, item.Id, MaxPreviewBytes), }); } ls.Add(emptyTestCase); TestPreview = ls; } return(true); }
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); }
async Task <bool> GetData(string id) { HttpClient httpclient = clientFactory.CreateClient(); ProblemsClient client = new ProblemsClient(httpclient); try { ProblemMetadata metadata = await client.GetAsync(id); Problem = await ProblemModel.GetAsync(metadata, httpclient, true, false); } catch { return(false); } return(true); }
public async Task <IActionResult> OnGetAsync(string id) { if (string.IsNullOrEmpty(id)) { return(NotFound()); } HttpClient httpclient = clientFactory.CreateClient(); ProblemsClient client = new ProblemsClient(httpclient); try { ProblemMetadata metadata = await client.GetAsync(id); Problem = await ProblemModel.GetAsync(metadata, httpclient, true, true); } catch { return(NotFound()); } List <TestCaseData> samples = new List <TestCaseData>(); foreach (TestCaseMetadata s in Problem.Samples) { Core.DataPreview input = await client.GetSampleInputPreviewAsync(id, s.Id, int.MaxValue); Core.DataPreview output = await client.GetSampleOutputPreviewAsync(id, s.Id, int.MaxValue); TestCaseData td = new TestCaseData { Metadata = s, Input = input.Content, Output = output.Content, }; samples.Add(td); } SampleData = samples; CurrentUser = await _userManager.GetUserAsync(User); EnableCode = CurrentUser != null; if (EnableCode) { StringBuilder res = new StringBuilder(); WorkspaceClient wclient = new WorkspaceClient(httpclient); IList <ProgrammingLanguage> langs; try { langs = await wclient.GetSupportLanguagesAsync(); } catch { langs = Array.Empty <ProgrammingLanguage>(); } if (langs.Count == 0) { EnableCode = false; } else { EnableCode = true; foreach (ProgrammingLanguage item in langs) { string editorId = Helper.GetEditorLanguage(item); if (editorId == "plaintext") { continue; } res.Append("{editorId: \"" + editorId + "\", "); switch (item) { // editorId for editor, lang for enum, show for selector in html case ProgrammingLanguage.C: res.Append("lang: \"C\", show: \"C\"},"); break; case ProgrammingLanguage.Cpp: res.Append("lang: \"Cpp\", show: \"C++\"},"); break; case ProgrammingLanguage.Java: res.Append("lang: \"Java\", show: \"Java\"},"); break; case ProgrammingLanguage.Python: res.Append("lang: \"Python\", show: \"Python\"},"); break; case ProgrammingLanguage.CSharp: res.Append("lang: \"CSharp\", show: \"C#\"},"); break; case ProgrammingLanguage.Rust: res.Append("lang: \"Rust\", show: \"Rust\"},"); break; case ProgrammingLanguage.VisualBasic: res.Append("lang: \"VisualBasic\", show: \"Visual Basic\"},"); break; case ProgrammingLanguage.Go: res.Append("lang: \"Go\", show: \"Go\"},"); break; case ProgrammingLanguage.Haskell: res.Append("lang: \"Haskell\", show: \"Haskell\"},"); break; case ProgrammingLanguage.Javascript: res.Append("lang: \"Javascript\", show: \"Javascript\"},"); break; case ProgrammingLanguage.Kotlin: res.Append("lang: \"Kotlin\", show: \"Kotlin\"},"); break; case ProgrammingLanguage.Php: res.Append("lang: \"Php\", show: \"PHP\"},"); break; case ProgrammingLanguage.Ruby: res.Append("lang: \"Ruby\", show: \"Ruby\"},"); break; case ProgrammingLanguage.Scala: res.Append("lang: \"Scala\", show: \"Scala\"},"); break; } } } LanguageConfig = res.ToString(); } return(Page()); }