public ActionResult CreateMilestone(MilestoneViewModel model, HttpPostedFileBase ZipFile, HttpPostedFileBase TxtFile) { if (ModelState.IsValid) { ModelState.Clear(); int MileID = TS.CreateMilestone(model); model.ID = MileID; if (ZipFile != null) { var ZipType = "zip"; var TextType = "txt"; var ZipEnding = System.IO.Path.GetExtension(ZipFile.FileName).Substring(1); if (!ZipType.Contains(ZipEnding)) { ViewBag.Output = "Error: upload approriate .zip file"; model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID); return(View(model)); } if (TxtFile != null) { var TextEnding = System.IO.Path.GetExtension(TxtFile.FileName).Substring(1); if (!TextType.Contains(TextEnding)) { ViewBag.Output = "Error: upload approriate .txt file"; model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID); return(View(model)); } } Stopwatch watch = new Stopwatch(); watch.Start(); try { model = TS.CompileMilestoneUpload(model, ZipFile, TxtFile); } catch { //return error, compile failed, invalid file? throw new Exception(); } watch.Stop(); TimeSpan ts = watch.Elapsed; ViewBag.Output = "Compiled in " + ts.Seconds + "." + ts.Milliseconds / 10 + " seconds"; TS.EditMilestone(model); } } model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID); return(View(model)); }
//private Plugin.Media.Abstractions.MediaFile _mediaFile; public AchievedMilestonePage(MilestoneViewModel model) { try { InitializeComponent(); media = DependencyService.Get <IMedia>(); _model = model; Init(); } catch (Exception ex) { throw new NotImplementedException(ex.Message); } }
public ActionResult AddMilestoneToProject(int id, MilestoneViewModel model) { if (!ModelState.IsValid) { SetupMilestone(id.ToString()); ViewBag.Typez = new SelectList(Tyypes.GetMilestoneTypes(), "Id", "Name"); return View(); } else { model.ProjectId = id; Tasks.AddTaskForProject(model); return RedirectToAction("AllMilestones", "Projects", new { id = id }); } }
public IActionResult Index() { var milestoneDetailList = new MilestoneViewModel(); milestoneDetailList.MilestoneList = MilestoneDB.GetInstance().GetAllMilestone(JsonConvert.DeserializeObject <Project>(HttpContext.Session.GetString("SelectedProject")).Id); milestoneDetailList.PersonList = PersonDB.GetInstance().GetAllPerson(); //milestoneDetailList.SprintList = SprintDB.GetInstance().GetAllSprint(); var personId = JsonConvert.DeserializeObject <Person>(HttpContext.Session.GetString("ActivePerson")).Id; milestoneDetailList.ProjectList = ProjectDB.GetInstance().GetAllProject(personId); return(View(milestoneDetailList)); }
public ActionResult ApplicationError() { Response.StatusCode = (int)HttpStatusCode.InternalServerError; Response.TrySkipIisCustomErrors = true; if (!User.Identity.IsAuthenticated) { return(View()); } MilestoneViewModel theview = new MilestoneViewModel(); theview.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), null); return(View(theview)); }
public ActionResult AddMilestone(MilestoneViewModel model) { Milestone newMilestone = new Milestone(); newMilestone.AssignmentID = model.AssignmentID; newMilestone.Percentage = model.Percentage; newMilestone.Title = model.Title; newMilestone.MilestoneInput1 = model.MilestoneInput1; newMilestone.MilestoneOutput1 = model.MilestoneOutput1; newMilestone.SubmissionLimit = model.SubmissionLimit; _db.Milestones.Add(newMilestone); _db.SaveChanges(); return(Redirect("~/Teacher/Assignments")); }
//private Plugin.Media.Abstractions.MediaFile _mediaFile; public AchievedMilestonePage(MilestoneViewModel model) { try { InitializeComponent(); media = DependencyService.Get <IMedia>(); _devicePermissionServices = DependencyService.Get <IDevicePermissionServices>(); _model = model; BindingContext = _model; Initialization(); } catch (Exception ex) { DependencyService.Get <IMessage>().AlertAsync(TextResources.Alert, ex.InnerException != null ? ex.InnerException.Message : ex.Message, TextResources.Ok); } }
/// <summary> /// Edits values for existing milestone that is in the database. /// </summary> public void EditMilestone(MilestoneViewModel NewMile) { if (NewMile == null) { return; } var MileToEdit = _db.Milestone.Where(x => x.ID == NewMile.ID).SingleOrDefault(); MileToEdit.Name = NewMile.Name; MileToEdit.Input = NewMile.Input; MileToEdit.Output = NewMile.Output; MileToEdit.Description = NewMile.Description; MileToEdit.AssignmentID = NewMile.AssignmentID; MileToEdit.CourseID = NewMile.CourseID; MileToEdit.Percent = NewMile.Percent; _db.SaveChanges(); }
public ActionResult CreateMilestone(int AssignmentID, int?CourseID) { if (AS.GetAssignmentByID(AssignmentID) == null) { throw new Exception(); } if (CourseID != null) { if (!AS.CourseExist(CourseID)) { throw new Exception(); } } var ViewModel = new MilestoneViewModel(); ViewModel.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), CourseID); return(View(ViewModel)); }
public ActionResult SubmitSolution() { var milestones = _db.Milestones.ToList(); List <MilestoneViewModel> models = new List <MilestoneViewModel>(); foreach (var milestone in milestones) { MilestoneViewModel newModel = new MilestoneViewModel(); newModel.ID = milestone.ID; newModel.Percentage = milestone.Percentage; newModel.Title = milestone.Title; newModel.AssignmentDescriptionFileName = _db.Assignments.Where(x => x.ID == milestone.AssignmentID).Select(x => x.DescriptionFileName).SingleOrDefault(); models.Add(newModel); } return(View(models)); }
public List <MilestoneViewModel> GetMilestoneInAssignment(int assignmentId) { var allMilestones = from milestones in _db.milestones where milestones.AssignmentId.Equals(assignmentId) select milestones; var milestoneViewList = new List <MilestoneViewModel>(); foreach (var milestone in allMilestones) { var tempViewModel = new MilestoneViewModel(); tempViewModel.Id = milestone.Id; tempViewModel.Title = milestone.Title; tempViewModel.Weight = milestone.Weight; tempViewModel.Input = milestone.Input; tempViewModel.Output = milestone.Output; milestoneViewList.Add(tempViewModel); } return(milestoneViewList); }
/// <summary> /// Creates new milestone in the database. /// </summary> public int CreateMilestone(MilestoneViewModel NewMile) { if (NewMile == null) { return(0); } var Mile = new Milestone(); Mile.Name = NewMile.Name; Mile.Input = NewMile.Input; Mile.Output = NewMile.Output; Mile.Description = NewMile.Description; Mile.AssignmentID = NewMile.AssignmentID; Mile.CourseID = NewMile.CourseID; Mile.Percent = NewMile.Percent; _db.Milestone.Add(Mile); _db.SaveChanges(); return(Mile.ID); }
public AssignmentViewModel GetAssignmentById(int assignmentId) { //Gets an assignment link by the assignmentID to the database ( a single assignment will be recived "single or default") var assignment = (from assignments in _db.assignments where assignments.Id.Equals(assignmentId) select assignments).SingleOrDefault(); if (assignment == null) { throw new ArgumentNullException(); } var allMilestones = from milestones in _db.milestones where milestones.AssignmentId.Equals(assignmentId) select milestones; var milestoneViewList = new List <MilestoneViewModel>(); foreach (var milestone in allMilestones) { var tempViewModel = new MilestoneViewModel(); { tempViewModel.Id = milestone.Id; tempViewModel.Title = milestone.Title; tempViewModel.Weight = milestone.Weight; tempViewModel.AssignmentId = assignmentId; }; milestoneViewList.Add(tempViewModel); } //create a viewmodel fot the assignment that has a milestone var viewModel = new AssignmentViewModel { Id = assignment.Id, Title = assignment.Title, CourseId = assignment.CourseId, Milestones = milestoneViewList }; return(viewModel); }
/// <summary> /// Get a single milestone from the database. /// </summary> public MilestoneViewModel GetMilestoneByID(int MileID) { var Milestone = _db.Milestone.SingleOrDefault(x => x.ID == MileID); if (Milestone == null) { return(null); } var ViewModel = new MilestoneViewModel { ID = Milestone.ID, AssignmentID = Milestone.AssignmentID, CourseID = Milestone.CourseID, Name = Milestone.Name, Description = Milestone.Description, Input = Milestone.Input, Output = Milestone.Output, Percent = Milestone.Percent }; return(ViewModel); }
public MilestoneViewModel GetSingleMilestoneInAssignment(int milestoneId) { var theMilestone = (from milestone in _db.milestones where milestone.Id.Equals(milestoneId) select milestone).SingleOrDefault(); if (theMilestone == null) { throw new ArgumentNullException(); } var tempViewModel = new MilestoneViewModel(); tempViewModel.Id = theMilestone.Id; tempViewModel.Title = theMilestone.Title; tempViewModel.Weight = theMilestone.Weight; tempViewModel.AssignmentId = milestoneId; tempViewModel.Output = theMilestone.Output; tempViewModel.Input = theMilestone.Input; return(tempViewModel); }
public ActionResult EditMilestone(MilestoneViewModel model) { if (!ModelState.IsValid) { ViewBag.Typez = new SelectList(Tyypes.GetMilestoneTypes(), "Id", "Name", Tasks.GetTask(model.Id.ToString()).TypeId); return View(); } else { Tasks.EditTask(model); return RedirectToAction("AllMilestones", "Projects", new { id = model.ProjectId }); } }
/// <summary> /// A function that users the compiler when the student uploads assignment, /// very similar to the milestone compile function that the teacher uses. /// </summary> public SubmissionViewModel StudentCompile(MilestoneViewModel model, HttpPostedFileBase ZipFile) { var TheUser = Ident.GetUser(model.UserModel.Name); int Count = 1; var Compiled = new SubmissionViewModel(); var ToCompile = new SubmissionViewModel(); if (model.Output == null) { throw new Exception(); } if (ZipFile != null) { string UserDirectory = UserDataDir + "\\" + TheUser.Id + "\\" + model.AssignmentID + "\\" + model.ID + "\\" + Count; // with each submission we create a new folder with increasing number in the name while (Directory.Exists(UserDirectory)) { Count++; UserDirectory = UserDataDir + "\\" + TheUser.Id + "\\" + model.AssignmentID + "\\" + model.ID + "\\" + Count; } Directory.CreateDirectory(UserDirectory); // we splice a couple of filepaths together to get the userdirectory and // zip directory so the compiler knows where to work. var fileName = Path.GetFileName(ZipFile.FileName); var path = UserDirectory + "\\" + fileName; string NewPath = UserDirectory + "\\" + model.UserModel.Name + "-" + model.ID + ".zip"; try { if (File.Exists(path)) { File.Delete(path); } // saves the zip in user storage ZipFile.SaveAs(Path.GetFullPath(path)); System.IO.File.Move(path, NewPath); fileName = model.UserModel.Name + "-" + model.ID + ".zip"; } catch { // user probably pressed upload twice, nothing to worry about. } ToCompile.UserName = model.UserModel.Name; ToCompile.AssignmentID = model.AssignmentID; ToCompile.MilestoneID = model.ID; ToCompile.FilePath = Count + "\\" + fileName; ToCompile.Input = model.Input; CompilerService CS = new CompilerService(); // compiler called. Compiled = CS.Compile(ToCompile); ToCompile.FilePath = "\\userdata\\" + TheUser.Id + "\\" + model.AssignmentID + "\\" + model.ID + "\\" + Count + "\\" + fileName; ToCompile.Error = Compiled.Error; ToCompile.Output = Compiled.Output; ToCompile.DrMemory = Compiled.DrMemory; ToCompile.Status = Compiled.Status; ToCompile.AssignmentName = AS.GetAssignmentByID(model.AssignmentID).Name; ToCompile.CourseID = model.CourseID; if (ToCompile.Output == null) { ToCompile.Output = "No output obtained"; } if (ToCompile.DrMemory == null) { ToCompile.DrMemory = "No memory file found"; } } return(ToCompile); }
public BasicMilestonePage(MilestoneViewModel model) { InitializeComponent(); this._model = model; this.Init(); }
public ActionResult CompilerIndex(FormCollection data) { string stringToParse = Request.Form["milestoneId"]; int milestoneId = int.Parse(stringToParse); var userName = User.Identity.Name; var cppFileName = userName + ".cpp"; var tableData = (from theFileName in _db.submissions where theFileName.MileStoneId.Equals(milestoneId) && theFileName.UserName.Equals(userName) select theFileName).FirstOrDefault(); var fileName = tableData.FileName; var thePath = Server.MapPath("~/App_Data/TestCode/" + fileName); string code = System.IO.File.ReadAllText(thePath); var workingFolder = Server.MapPath("~/App_Data/Solution_Uploads/"); //directory.createdirectory (so we can create a folder for each user) var exeFilePath = workingFolder + userName + ".exe"; System.IO.File.WriteAllText(workingFolder + cppFileName, code); var compilerFolder = "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\"; Process compiler = new Process(); compiler.StartInfo.FileName = "cmd.exe"; compiler.StartInfo.WorkingDirectory = workingFolder; compiler.StartInfo.RedirectStandardInput = true; compiler.StartInfo.RedirectStandardOutput = true; compiler.StartInfo.UseShellExecute = false; compiler.Start(); compiler.StandardInput.WriteLine("\"" + compilerFolder + "vcvars32.bat" + "\""); compiler.StandardInput.WriteLine("cl.exe /nologo /EHsc " + cppFileName); compiler.StandardInput.WriteLine("exit"); string output = compiler.StandardOutput.ReadToEnd(); compiler.WaitForExit(); compiler.Close(); if (System.IO.File.Exists(exeFilePath)) { var processInfoExe = new ProcessStartInfo(exeFilePath, ""); processInfoExe.UseShellExecute = false; processInfoExe.RedirectStandardOutput = true; processInfoExe.RedirectStandardError = true; processInfoExe.CreateNoWindow = true; using (var processExe = new Process()) { processExe.StartInfo = processInfoExe; processExe.Start(); var lines = new List <string>(); while (!processExe.StandardOutput.EndOfStream) { lines.Add(processExe.StandardOutput.ReadLine()); } ViewBag.Output = lines; } } MilestoneViewModel model = _assignmentMilestoneService.GetSingleMilestoneInAssignment(milestoneId); return(View(model)); }