Exemplo n.º 1
0
        public Submit CreateTestSubmit()
        {
            Submit submit = new Submit();
            submit.FileName = "HelloWorld.cs";
            submit.Data = File.ReadAllBytes(@"C:\mocs\submits\1\goodsolution.cs");
            submit.Team = new Team() { Name = "Team" };
            submit.TournamentAssignment = new TournamentAssignment();

            return submit;
        }
Exemplo n.º 2
0
 public void CopySubmittedFileToDirectory(string teamSubmitDirName, Submit submit)
 {
     //copy the file to this directory
     using (Stream target = FileSystem.FileOpenWrite(Path.Combine(teamSubmitDirName, submit.FileName)))
     {
         try
         {
             target.Write(submit.Data, 0, submit.Data.Length);
         }
         finally
         {
             target.Flush();
         }
     }
 }
Exemplo n.º 3
0
        public void CopyFiles(Assignment assignment, Submit submit, string teamSubmitDirName)
        {
            IFileSystem fileSystem = ServiceLocator.Instance.GetService<IFileSystem>();

            // Copy nunit.framework.dll to this directory
            fileSystem.FileCopy(Path.Combine(Settings.NunitAssemblyPath, "nunit.framework.dll"),
                        Path.Combine(teamSubmitDirName, "nunit.framework.dll"), true);

            //copy the file to this directory
            CopySubmittedFileToDirectory(teamSubmitDirName, submit);

            // Copy the interface file//////////////////////////////////////////////////////////////////////////////
            //delete the file if it existed already
            DeleteAndCopySingleAssignmentFile("InterfaceFile", teamSubmitDirName, assignment);

            DeleteAndCopySingleAssignmentFile("NunitTestFileServer", teamSubmitDirName, assignment);

            DeleteAndCopySingleAssignmentFile("NunitTestFileClient", teamSubmitDirName, assignment);

            DeleteAndCopyMulitpleAssignmentFiles("ServerFileToCopy", teamSubmitDirName, assignment);
        }
Exemplo n.º 4
0
        public ActionResult UploadSubmit()
        {
            Team team = SessionUtil.GetTeamFromFormsAuthentication();
            Tournament t = SessionUtil.GetTournamentFromSession();
            TournamentAssignment ta = SessionUtil.GetTournamentAssignmentFromSession();
            Assignment a = SessionUtil.GetAssignmentFromSession();
            AssignmentEnrollment ae = SessionUtil.GetAssignmentEnrollmentFromSession();

            if (Request.Files.Count == 1)
            {
                HttpPostedFileBase postedFile = Request.Files[0];

                TempData["SubmittedFileText"] = string.Format("File: {0} submitted", postedFile.FileName);

                //Check for big file (> 128KB)
                int submitMaxSize = int.Parse(ConfigurationManager.AppSettings["SubmitMaxSize"]) * 1024;

                if (postedFile.ContentLength > submitMaxSize)
                {
                    TempData["SubmittedFileText"] = string.Format("Submitted file is too large. Maximum size: {0}KB", submitMaxSize);
                    return RedirectToAction("Index");
                }

                //Check for right file extension
                if (postedFile.FileName.IndexOf(".cs") != postedFile.FileName.Length - 3)
                {
                    TempData["SubmittedFileText"] = "Submitted file doesn't have extension '.cs'.";
                    return RedirectToAction("Index");
                }

                //Construct the submit
                Submit s = new Submit()
                {
                    FileName = Path.GetFileName(postedFile.FileName),
                    Team = team,
                    TournamentAssignment = ta,
                    AssignmentEnrollment = ae
                };
                s.Data = new byte[postedFile.ContentLength];

                postedFile.InputStream.Read(s.Data, 0, postedFile.ContentLength);

                // Do the submit
                try
                {
                    ClientFacade.Instance.SaveSubmit(s);
                }
                catch (MoCSException e)
                {
                    TempData["SubmittedFileText"] = "Unable to process submit. Reason: " + e.Message;
                }
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            string textToSubmit = this.richTextBox2.Text;

            ClientFacade facade = new ClientFacade();

            Team team = new Team() {Id=1, Name="Team01", Password="******"};

            team = facade.AuthenticateTeam(team);

            Submit submit = new Submit();
            submit.Team = team;
            submit.Data = new UTF8Encoding().GetBytes(textToSubmit);
            submit.AssignmentEnrollment = new AssignmentEnrollment() {Id=1, Team = team};
            submit.TournamentAssignment = new TournamentAssignment() { Id = 1 };
            submit.SubmitDate = DateTime.Now;
            submit.FileName = "HelloWorld.cs";

            facade.SaveSubmit(submit);
        }
Exemplo n.º 6
0
 public ValidationProcess(Submit submit, DateTime startTime)
 {
     this.Submit = submit;
     this.ProcessingDate = startTime;
 }
Exemplo n.º 7
0
        private static void CopyFiles(Assignment assignment, Submit submit, string teamSubmitDirName, SystemSettings systemSettings)
        {
            MoCS.BuildService.Business.FileSystemWrapper fileSystem = new Business.FileSystemWrapper();

            // Copy nunit.framework.dll to this directory
            fileSystem.FileCopy(Path.Combine(systemSettings.NunitAssemblyPath, "nunit.framework.dll"),
                        Path.Combine(teamSubmitDirName, "nunit.framework.dll"), true);

            //copy the file to this directory
            using (Stream target = fileSystem.FileOpenWrite(Path.Combine(teamSubmitDirName, submit.FileName)))
            {
                try
                {
                    target.Write(submit.Data, 0, submit.Data.Length);
                }
                finally
                {
                    target.Flush();
                }
            }

            // Copy the interface file
            //delete the file if it existed already
            AssignmentFile interfaceFile = assignment.AssignmentFiles.Find(af => af.Name == "InterfaceFile");

            fileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, interfaceFile.FileName));

            fileSystem.FileCopy(Path.Combine(assignment.Path, interfaceFile.FileName),
                        Path.Combine(teamSubmitDirName, interfaceFile.FileName));

            //copy the server testfile
            //delete the file if it existed already
            AssignmentFile serverTestFile = assignment.AssignmentFiles.Find(af => af.Name == "NunitTestFileServer");

            fileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, serverTestFile.FileName));

            fileSystem.FileCopy(Path.Combine(assignment.Path, serverTestFile.FileName),
                        Path.Combine(teamSubmitDirName, serverTestFile.FileName));

            //copy additional serverfiles
            List<AssignmentFile> serverFilesToCopy = assignment.AssignmentFiles.FindAll(af => af.Name == "ServerFileToCopy");
            foreach (AssignmentFile serverFileToCopy in serverFilesToCopy)
            {

                fileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, serverFileToCopy.FileName));

                fileSystem.FileCopy(Path.Combine(assignment.Path, serverFileToCopy.FileName),
                            Path.Combine(teamSubmitDirName, serverFileToCopy.FileName));
            }

            //copy the client testfile
            AssignmentFile clientTestFile = assignment.AssignmentFiles.Find(af => af.Name == "NunitTestFileClient");

            //delete the file if it existed already
            fileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, clientTestFile.FileName));

            fileSystem.FileCopy(Path.Combine(assignment.Path, clientTestFile.FileName),
                        Path.Combine(teamSubmitDirName, clientTestFile.FileName));
        }
Exemplo n.º 8
0
        private static void SaveStatusToDatabase(Submit submit, ValidationResult result)
        {
            string teamName = submit.Team.Name;
            string assignmentName = submit.TournamentAssignment.Assignment.Name;

            string details = "";
            foreach (string detail in result.Messages)
            {
                details += detail;
            }
            if (details.Length > 1000)
            {
                details = details.Substring(0, 999);
            }

            ClientFacade facade = new ClientFacade();

            //process result
            switch (result.Status)
            {
                case SubmitStatusCode.Unknown:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.ErrorUnknown, details, DateTime.Now);
                    break;
                case SubmitStatusCode.CompilationError:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.ErrorCompilation, details, DateTime.Now);
                    break;
                case SubmitStatusCode.ValidationError:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.ErrorValidation, details, DateTime.Now);
                    break;
                case SubmitStatusCode.TestError:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.ErrorTesting, details, DateTime.Now);
                    break;
                case SubmitStatusCode.ServerError:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.ErrorServer, details, DateTime.Now);
                    break;
                case SubmitStatusCode.Success:
                    facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.Success, details, DateTime.Now);
                    break;
                default:
                    break;
            }
        }
Exemplo n.º 9
0
 private Submit CreateIdSubmit(Submit s)
 {
     Submit result = new Submit
     {
         Id = s.Id,
         Team = CreateIdTeam(s.Team),
         AssignmentEnrollment = CreateIdAssignmentEnrollment(s.AssignmentEnrollment),
         TournamentAssignment = CreateIdTournamentAssignment(s.TournamentAssignment),
         Data = new byte[0],
         FileContents = string.Empty,
         FileName = string.Empty,
         IsProcessed = false,
         ProcessingDetails = string.Empty,
         Status = string.Empty,
         SubmitDate = DateTime.Now
     };
     return result;
 }
Exemplo n.º 10
0
        public Submit SaveSubmit(Submit submit)
        {
            Submit result = null;

            //Check for unprocessed and already successful submits
            foreach (Submit s in GetSubmitsForAssignmentEnrollment(submit.AssignmentEnrollment.Id))
            {
                switch (s.ConvertStatus(s.Status))
                {
                    case SubmitStatus.Submitted:
                    case SubmitStatus.Processing:
                        throw new MoCSException("There are unprocessed submits. Please wait until all your submits have been processed.");
                    case SubmitStatus.Success:
                        throw new MoCSException("A successful solution has already been submitted.");
                    default:
                        break;
                }
            }

            submit.Status = SubmitStatus.Submitted.ToString();
            submit.SubmitDate = DateTime.Now;
            submit.StatusDate = DateTime.Now;
            submit.IsProcessed = false;

            // Get the AssignmentEnrollment in order to determine the time since enrollment.
            AssignmentEnrollment ae = GetAssignmentEnrollmentById(submit.AssignmentEnrollment.Id);
            TimeSpan timeSinceEnrollment = submit.SubmitDate - ae.StartDate;
            submit.SecondsSinceEnrollment = (long)timeSinceEnrollment.TotalSeconds;

            submit.ProcessingDetails = "Empty";
            submit.FileContents = UTF8Encoding.UTF8.GetString(submit.Data);

            result = _dataAccess.SaveSubmit(submit);

            NotifySubmitStatusChange(result.Id, SubmitStatus.Submitted, "", result.StatusDate);

            return result;
        }
Exemplo n.º 11
0
        public void NotifyFirstPlace(Submit submit)
        {
            if (_useNotification)
            {
                string notifyText;

                notifyText = string.Format("Team {0} currently holds first place for assignment {1}. They took {2} seconds to program a correct solution.",
                    new object[] { submit.Team.Name, submit.TournamentAssignment.Assignment.Name, submit.SecondsSinceEnrollment });
                NotifyAll(MessageType.Info, DateTime.Now, "", "FirstPlace", notifyText);
            }
        }
Exemplo n.º 12
0
 public ValidationProcess(Submit submit, DateTime startTime)
 {
     _submit = submit;
     _startTime = startTime;
 }