Esempio n. 1
0
        public static async Task <ProblemModel> GetAsync(ProblemMetadata metadata, HttpClient client, bool loadDescription, bool loadData)
        {
            ProblemModel res = new ProblemModel
            {
                Metadata = metadata,
            };

            ProblemsClient pcli = new ProblemsClient(client);

            {
                try
                {
                    StatisticsClient stcli = new StatisticsClient(client);
                    res.Statistics = await stcli.GetProblemAsync(metadata.Id);
                }
                catch
                {
                    res.Statistics = null;
                }
            }

            if (loadDescription)
            {
                try
                {
                    res.Description = await pcli.GetDescriptionAsync(metadata.Id);
                }
                catch { }
            }

            if (loadData)
            {
                try
                {
                    res.Samples = await pcli.GetSamplesAsync(metadata.Id);
                }
                catch
                {
                    res.Samples = Array.Empty <TestCaseMetadata>();
                }

                try
                {
                    res.Tests = await pcli.GetTestsAsync(metadata.Id);
                }
                catch
                {
                    res.Tests = Array.Empty <TestCaseMetadata>();
                }
            }

            {
                UsersClient ucli = new UsersClient(client);
                try
                {
                    res.User = await ucli.GetAsync(metadata.UserId);
                }
                catch
                {
                    res.User = null;
                }
            }

            return(res);
        }