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 async Task OnGetAsync() { HttpClient httpclient = clientFactory.CreateClient(); ProblemsClient client = new ProblemsClient(httpclient); IList <Core.Problems.ProblemMetadata> ms = await client.GetAllAsync(); List <ProblemModel> ss = new List <ProblemModel>(); foreach (Core.Problems.ProblemMetadata v in ms) { ss.Add(await ProblemModel.GetAsync(v, httpclient, false, false)); } Problems = ss; }
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> OnPostQueryAsync() { try { HttpClient httpclient = clientFactory.CreateClient(); ProblemsClient client = new ProblemsClient(httpclient); List <Core.Problems.ProblemMetadata> ms = (await client.QueryAsync(PostData.QueryId, PostData.QueryUserId, PostData.QueryName, PostData.QuerySource)).ToList(); List <ProblemModel> ss = new List <ProblemModel>(); foreach (Core.Problems.ProblemMetadata v in ms) { ss.Add(await ProblemModel.GetAsync(v, httpclient, false, false)); } Problems = ss; } catch { Problems = Array.Empty <ProblemModel>(); } return(Page()); }
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()); }