public async Task <ActionResult <ProblemPackage> > Export(string id) { IProblemProvider res = await _workspace.Problems.Get(id); if (res == null) { return(NotFound()); } try { ProblemPackage package = new ProblemPackage { Metadata = await res.GetMetadata(), Description = await res.GetDescription(), }; { List <ProblemPackage.TestCasePackage> ls = new List <ProblemPackage.TestCasePackage>(); IEnumerable <ITestCaseProvider> ss = await res.Samples.GetAll(); foreach (ITestCaseProvider s in ss) { ProblemPackage.TestCasePackage t = new ProblemPackage.TestCasePackage { Metadata = await s.GetMetadata(), Input = await TextIO.ToString(await s.GetInput()), Output = await TextIO.ToString(await s.GetOutput()), }; ls.Add(t); } package.Samples = ls; } { List <ProblemPackage.TestCasePackage> ls = new List <ProblemPackage.TestCasePackage>(); IEnumerable <ITestCaseProvider> ss = await res.Tests.GetAll(); foreach (ITestCaseProvider s in ss) { ProblemPackage.TestCasePackage t = new ProblemPackage.TestCasePackage { Metadata = await s.GetMetadata(), Input = await TextIO.ToString(await s.GetInput()), Output = await TextIO.ToString(await s.GetOutput()), }; ls.Add(t); } package.Tests = ls; } return(Ok(package)); } catch { return(NoContent()); } }
public async Task <ActionResult <ProblemDescription> > GetDescription(string id) { IProblemProvider res = await _workspace.Problems.Get(id); if (res != null) { return(Ok(await res.GetDescription())); } else { return(NotFound()); } }