Esempio n. 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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
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, true, false);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
 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());
 }
Esempio n. 5
0
 public async Task <IActionResult> OnGetAsync(string id)
 {
     if (string.IsNullOrEmpty(id))
     {
         IsNew   = true;
         Problem = new ProblemModel
         {
             Metadata = new Core.Problems.ProblemMetadata
             {
                 Name = "Untitled",
             },
             Description = new Core.Problems.ProblemDescription()
         };
         PostData = new ProblemPostModel
         {
             Description = Problem.Description
         };
         return(Page());
     }
     else
     {
         IsNew = false;
         if (await GetData(id))
         {
             PostData = new ProblemPostModel
             {
                 Description = Problem.Description
             };
             return(Page());
         }
         else
         {
             return(NotFound());
         }
     }
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
        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());
        }