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); }
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)); }
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))); }