Example #1
0
        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);
        }