public HastingsModules() { Get["hastings"] = _ => { Logger.Trace("Handling get for /hastings"); return(View["hastings", Hastings.GetPlayers()]); }; Post["/uploadHastingsPlayer"] = _ => { Logger.Trace("Handling post for /uploadHastingsPlayer"); string result = string.Empty; FileUploadRequest request = this.Bind <FileUploadRequest>(); Assignment assignment = uploadHandler.HandleStudentUpload(request.Files); if (!assignment.ValidHeader) { result = string.Format("<p>{0}</p>", assignment.ErrorMessage); } else { result = Hastings.BuildHastings(assignment); } return(result); }; Post["/loadHastingsBattle"] = _ => { Logger.Trace("Handling post for /loadHastingsBattle"); string player1Name = this.Request.Form["player1"]; string player2Name = this.Request.Form["player2"]; Logger.Trace("Loading battle between {0} and {1}", player1Name, player2Name); Random rand = new Random(); string result = string.Empty; // Randomly choose sides if (rand.Next() % 2 == 1) { result = Hastings.DoBattle(player1Name, player2Name); } else { result = Hastings.DoBattle(player2Name, player1Name); } return(result); }; }
public JarvisModules() { #region Gets Get["/"] = _ => { Logger.Trace("Handling get for /"); return(View["index"]); }; Get["/help"] = _ => { Logger.Trace("Handling get for /help"); return(View["help"]); }; Get["/grade"] = _ => { Logger.Trace("Handling get for /grade"); return(View["grade"]); }; Get["/stats"] = _ => { Logger.Trace("Handling get for /stats"); return(View["stats", Jarvis.Stats]); }; #endregion #region Posts Post["/run"] = _ => { Logger.Trace("Handling post for /run"); Runner runner = new Runner(); RunResult result = null; StringBuilder builder = new StringBuilder(); FileUploadRequest request = this.Bind <FileUploadRequest>(); Assignment assignment = uploadHandler.HandleStudentUpload(request.Files); Logger.Info("Received assignment from {0} for {1} HW#{2} with {3} header", assignment.StudentId, assignment.Course, assignment.HomeworkId, assignment.ValidHeader ? "true" : "false"); if (assignment.ValidHeader) { // Run grader Logger.Debug("Assignment header was valid"); result = runner.Run(assignment); builder.Append(result.ToHtml()); StatsManager.UpdateStats(assignment, result); } else { builder.AppendLine("<p>"); builder.AppendLine("The uploaded files did not contain a valid header, sir. I suggest you review the <a href='/help'>help</a>."); builder.AppendFormat("<br />Parser error message: {0}", assignment.ErrorMessage); builder.AppendLine("</p>"); Jarvis.Stats.TotalBadHeaders++; } return(builder.ToString()); }; Post["/grade"] = _ => { Logger.Trace("Handling post for /grade"); Guid temp = Guid.NewGuid(); string baseDir = Jarvis.Config.AppSettings.Settings["workingDir"].Value; string gradingDir = baseDir + "/grading/" + temp.ToString() + "/"; bool runMoss = this.Request.Form["runMoss"]; bool runCode = this.Request.Form["runCode"]; var request = this.Bind <FileUploadRequest>(); List <Assignment> assignments = uploadHandler.HandleGraderUpload(gradingDir, request.Files); Grader grader = new Grader(runMoss, runCode); return(grader.Grade(gradingDir + "canvas.csv", baseDir, assignments)); }; #endregion }