Esempio n. 1
0
        public async Task <IActionResult> Add(
            [FromServices] IExecutableStore executables)
        {
            ViewBag.Executables = await executables.ListAsync("compile");

            ViewBag.Operator = "Add";
            return(View("Edit", new LanguageEditModel {
                TimeFactor = 1
            }));
        }
        public async Task <ActionResult <string> > OnGet(
            [FromRoute] string target,
            [FromServices] IExecutableStore execs)
        {
            var exec = await execs.FindAsync(target);

            if (exec is null)
            {
                return(NotFound());
            }
            var base64encoded = Convert.ToBase64String(exec.ZipFile);

            return(base64encoded);
        }
Esempio n. 3
0
 public KattisExportProvider(
     IProblemStore store,
     ISubmissionStore submissions,
     IExecutableStore execs,
     ITestcaseStore tcs,
     IMarkdownService markdown,
     IStaticFileRepository io2)
 {
     Store       = store;
     StaticFile  = io2;
     Markdown    = markdown;
     Submissions = submissions;
     Executables = execs;
     Testcases   = tcs;
 }
Esempio n. 4
0
 public DataImportProvider(
     IProblemStore store,
     ILanguageStore languages,
     IExecutableStore executables,
     ISubmissionStore submissions,
     ILogger <DataImportProvider> logger,
     IStaticFileRepository io2)
 {
     Logger      = logger;
     Store       = store;
     Languages   = languages;
     Executables = executables;
     Submissions = submissions;
     LogBuffer   = new StringBuilder();
     StaticFiles = io2;
 }
Esempio n. 5
0
 public KattisImportProvider(
     IProblemStore store,
     ILanguageStore languages,
     IExecutableStore executables,
     ISubmissionStore submissions,
     ILogger <KattisImportProvider> logger,
     IMarkdownService markdownService,
     IStaticFileRepository io2)
 {
     Logger      = logger;
     Store       = store;
     Languages   = languages;
     Executables = executables;
     Submissions = submissions;
     LogBuffer   = new StringBuilder();
     Markdown    = markdownService;
     StaticFiles = io2;
 }
Esempio n. 6
0
        public async Task <IActionResult> Executables(string execid,
                                                      [FromServices] IExecutableStore execs)
        {
            if (execid != Problem.CompareScript && execid != Problem.RunScript)
            {
                return(NotFound());
            }
            var bytes = await execs.FindAsync(execid);

            if (bytes is null)
            {
                return(NotFound());
            }

            ViewBag.Executable = bytes;
            var items = await execs.FetchContentAsync(bytes);

            return(View(items));
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(string langid,
                                               [FromServices] IExecutableStore executables)
        {
            var lang = await Store.FindAsync(langid);

            if (lang == null)
            {
                return(NotFound());
            }
            ViewBag.Executables = await executables.ListAsync("compile");

            ViewBag.Operator = "Edit";
            return(View(new LanguageEditModel
            {
                CompileScript = lang.CompileScript,
                ExternalId = lang.Id,
                FileExtension = lang.FileExtension,
                Name = lang.Name,
                TimeFactor = lang.TimeFactor,
            }));
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit(
            int pid, ProblemEditModel model,
            [FromServices] IExecutableStore execs)
        {
            if (model.RunScript == "upload" && model.UploadedRun == null)
            {
                ModelState.AddModelError("XYS::RunScript", "No run script was selected.");
            }
            if (model.CompareScript == "upload" && model.UploadedCompare == null)
            {
                ModelState.AddModelError("XYS::CmpScript", "No compare script was selected.");
            }
            if (!new[] { "compare", Problem.CompareScript, "upload" }.Contains(model.CompareScript))
            {
                ModelState.AddModelError("XYS::CmpScript", "Error compare script defined.");
            }
            if (!new[] { "run", Problem.RunScript, "upload" }.Contains(model.RunScript))
            {
                ModelState.AddModelError("XYS::RunScript", "Error run script defined.");
            }

            if (!ModelState.IsValid)
            {
                StatusMessage = "Error validating problem.\n" +
                                string.Join('\n', ModelState.Values
                                            .SelectMany(m => m.Errors)
                                            .Select(e => e.ErrorMessage));
                return(View(model));
            }

            if (model.RunScript == "upload")
            {
                var cont = await model.UploadedRun.ReadAsync();

                var execid = $"p{pid}run";

                var exec = await execs.FindAsync(execid);

                bool newone = exec == null;
                exec ??= new Executable();
                exec.ExecId      = execid;
                exec.Description = $"run pipe for p{pid}";
                exec.Md5sum      = cont.Item2;
                exec.ZipFile     = cont.Item1;
                exec.Type        = "run";
                exec.ZipSize     = cont.Item1.Length;

                if (newone)
                {
                    await execs.CreateAsync(exec);
                }
                else
                {
                    await execs.UpdateAsync(exec);
                }
                model.RunScript = execid;
            }

            if (model.CompareScript == "upload")
            {
                var cont = await model.UploadedCompare.ReadAsync();

                var execid = $"p{pid}cmp";

                var exec = await execs.FindAsync(execid);

                bool newone = exec == null;
                exec ??= new Executable();
                exec.ExecId      = execid;
                exec.Description = $"output validator for p{pid}";
                exec.Md5sum      = cont.Item2;
                exec.ZipFile     = cont.Item1;
                exec.Type        = "compare";
                exec.ZipSize     = cont.Item1.Length;

                if (newone)
                {
                    await execs.CreateAsync(exec);
                }
                else
                {
                    await execs.UpdateAsync(exec);
                }
                model.CompareScript = execid;
            }

            Problem.RunScript          = model.RunScript;
            Problem.CompareScript      = model.CompareScript;
            Problem.ComapreArguments   = model.CompareArgument;
            Problem.MemoryLimit        = model.MemoryLimit;
            Problem.OutputLimit        = model.OutputLimit;
            Problem.TimeLimit          = model.TimeLimit;
            Problem.Title              = model.Title;
            Problem.Source             = model.Source ?? "";
            Problem.CombinedRunCompare = model.RunAsCompare;
            Problem.Shared             = model.Shared;
            await Problems.UpdateAsync(Problem);

            await HttpContext.AuditAsync("edit", $"{Problem.ProblemId}");

            return(RedirectToAction(nameof(Overview)));
        }
 public ExecutablesController(IExecutableStore store)
 {
     Store = store;
 }