Пример #1
0
 public static AssignmentSettings CreateAssignmentSettings(Assignment assignment, string assignmentName)
 {
     AssignmentSettings assignmentSettings = new AssignmentSettings();
     assignmentSettings.AssignmentId = assignmentName;
     assignmentSettings.ClassnameToImplement = assignment.ClassNameToImplement;
     assignmentSettings.InterfaceNameToImplement = assignment.InterfaceNameToImplement;
     return assignmentSettings;
 }
Пример #2
0
        public static Assignment FillAssignmentDetailsFromXml(Assignment a, IFileSystem fileSystem, bool includeServerFiles)
        {
            if (a == null)
            {
                return null;    //no active assignment
            }

            string path = Path.Combine(a.Path, "assignment.xml");

            if (fileSystem.FileExists(path))
            {
                XmlDocument doc = fileSystem.LoadXml(path);

                a.FriendlyName = GetNodeValue(doc, "Assignment/DisplayName");
                //a.Tagline = GetNodeValue(doc, "Assignment/Hint");

                a.Difficulty = int.Parse(GetNodeValue(doc, "Assignment/Difficulty"));
                a.Author = GetNodeValue(doc, "Assignment/Author");
                a.Category = GetNodeValue(doc, "Assignment/Category");

                a.InterfaceNameToImplement = GetNodeValue(doc, "Assignment/Rules/InterfaceNameToImplement");
                a.ClassNameToImplement = GetNodeValue(doc, "Assignment/Rules/ClassNameToImplement");

                //a.ClassFileName = GetNodeValue(doc, "Assignment/Files/ClassFile");
                //a.InterfaceFileName = GetNodeValue(doc, "Assignment/Files/InterfaceFile");

                //a.UnitTestClientFileName = GetNodeValue(doc, "Assignment/Files/NunitTestFileClient");
                //a.UnitTestServerFileName = GetNodeValue(doc, "Assignment/Files/NunitTestFileServer");

                //a.CaseFileName = GetNodeValue(doc, "Assignment/Files/Case");
                a.AssignmentFiles = new List<AssignmentFile>();
                XmlNode fileNode = doc.SelectSingleNode("Assignment/Files");
                foreach (XmlNode fileChildNode in fileNode.ChildNodes)
                {
                    string nodeName = fileChildNode.Name;
                    string fileName = fileChildNode.InnerText;

                    string filepath = Path.Combine(a.Path, fileName);
                    if (File.Exists(filepath))
                    {
                        if (includeServerFiles || (nodeName != "NunitTestFileServer" && nodeName != "ServerFileToCopy"))
                        {
                            AssignmentFile assignmentFile = new AssignmentFile();
                            assignmentFile.Name = nodeName;
                            assignmentFile.FileName = fileName;
                            assignmentFile.Data = FacadeHelpers.ReadByteArrayFromFile(filepath);
                            a.AssignmentFiles.Add(assignmentFile);
                        }
                    }
                }
            }
            else
            {
                throw new ApplicationException("Details for the assignment could not be found");
            }
            return a;
        }
Пример #3
0
        public string CreateTeamDirectory(string teamName, Assignment assignment)
        {
            FileSystem.CreateDirectoryIfNotExists(Settings.BaseResultPath);

            //create a directory for the assignment
            FileSystem.CreateDirectoryIfNotExists(Settings.BaseResultPath + assignment.Id);

            string teamDirName = teamName + "_" + DateTime.Now.ToString("ddMMyyyy_HHmmss");
            string teamSubmitDirName = Settings.BaseResultPath + assignment.Id + @"\" + teamDirName;

            //create a new directory for the teamsubmit
            FileSystem.CreateDirectory(teamSubmitDirName);

            return teamSubmitDirName;
        }
Пример #4
0
        private static void ProcessTeamSubmit(ValidationProcess validationProcess, SystemSettings sysSettings)
        {
            Submit submit         = validationProcess.Submit;
            string teamName       = submit.Team.Name;
            string assignmentName = submit.TournamentAssignment.Assignment.Name;

            Log(string.Format("Processing teamsubmit {0} for assignment {1}", teamName, assignmentName));

            //create the processor
            SubmitValidator validator = new SubmitValidator(new MoCS.BuildService.Business.FileSystemWrapper(), new ExecuteCmd());

            validationProcess.SetProcessor(validator);

            //prepare directory and files for processing
            string       teamSubmitDirName = CreateTeamDirectory(sysSettings, teamName, submit.TournamentAssignment.Assignment);
            ClientFacade facade            = new ClientFacade();

            MoCS.Business.Objects.Assignment assignment = facade.GetAssignmentById(submit.TournamentAssignment.Assignment.Id, true);
            CopyFiles(assignment, submit, teamSubmitDirName, sysSettings);

            //START PROCESSING

            //settings that are read from the assignment
            AssignmentSettings assignmentSettings = SettingsFactory.CreateAssignmentSettings(assignment, assignmentName);
            //settings that are from the submitprocess/team submit
            SubmitSettings submitSettings = SettingsFactory.CreateSubmitSettings(teamName, teamSubmitDirName, assignmentName);

            //set status of submit to 'processing'
            facade.UpdateSubmitStatusDetails(submit.Id, SubmitStatus.Processing, "This submitted is currently processed.", DateTime.Now);

            ValidationResult result = validator.Process(sysSettings, assignmentSettings, submitSettings);

            validationProcess.Result = result;

            Log(result.Status + " for " + submit.Team.Name + " on " + submit.TournamentAssignment.Assignment.Name);

            //save the new status to the database
            SaveStatusToDatabase(validationProcess.Submit, result);

            // Delete nunit.framework.dll from the submit dir to keep things clean
            CleanupFiles(teamSubmitDirName);
        }
Пример #5
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);
        }
Пример #6
0
        public static void SetSession(Tournament t, TournamentAssignment ta, Assignment a, AssignmentEnrollment ae)
        {
            if (t != null)
            {
                HttpContext.Current.Session["tournamentId"] = t.Id;
                HttpContext.Current.Session["tournamentName"] = t.Name;

            }
            else
            {
                HttpContext.Current.Session.Remove("tournamentId");
                HttpContext.Current.Session.Remove("tournamentName");
            }
            if (ta != null)
            {
                HttpContext.Current.Session["tournamentAssignmentId"] = ta.Id;
            }
            else
            {
                HttpContext.Current.Session.Remove("tournamentAssignmentId");
            }

            if (a != null)
            {
                HttpContext.Current.Session["assignmentId"] = a.Id;
                HttpContext.Current.Session["assignmentName"] = a.Name;
            }
            else
            {
                HttpContext.Current.Session.Remove("assignmentId");
                HttpContext.Current.Session.Remove("assignmentName");
            }

            if (ae != null)
            {
                HttpContext.Current.Session["assignmentEnrollmentId"] = ae.Id;
                HttpContext.Current.Session["assignmentEnrollmentStartDate"] = ae.StartDate;
            }
            else
            {
                HttpContext.Current.Session.Remove("assignmentEnrollmentId");
                HttpContext.Current.Session.Remove("assignmentEnrollmentStartDate");

            }
        }
Пример #7
0
        public static Assignment GetAssignmentFromSession()
        {
            Assignment result = null;
            if (HttpContext.Current.Session["assignmentId"] != null)
            {
                result = new Assignment
                {
                    Id = (int)HttpContext.Current.Session["assignmentId"],
                    Name = (string)HttpContext.Current.Session["assignmentName"]
                };
            }

            return result;
        }
Пример #8
0
        private Assignment CreateTestAssignment(IBuildServiceFacade facade)
        {
            //setup the mock for facade
            Assignment assignment = new Assignment();
            facade.GetAssignmentById(Arg.Any<int>(), true).Returns(assignment);
            assignment.Path = @"c:\mocs\assignments\1\";
            assignment.AssignmentFiles.Add(new AssignmentFile() { Name = "InterfaceFile", FileName = "IHelloWorld.cs" });
            assignment.AssignmentFiles.Add(new AssignmentFile() { Name = "NunitTestFileServer", FileName = "HelloWorldTestsServer.cs" });
            assignment.AssignmentFiles.Add(new AssignmentFile() { Name = "NunitTestFileClient", FileName = "HelloWorldTests.cs" });
            assignment.AssignmentFiles.Add(new AssignmentFile() { Name = "ServerFileToCopy", FileName = "serverfile1.xml" });
            assignment.AssignmentFiles.Add(new AssignmentFile() { Name = "ServerFileToCopy", FileName = "serverfile2.dll" });
            assignment.Id = 1;
            assignment.ClassNameToImplement = "HelloWorld";
            assignment.InterfaceNameToImplement = "IHelloWorld";

            return assignment;
        }
Пример #9
0
        private void DeleteAndCopySingleAssignmentFile(string fileName, string teamSubmitDirName, Assignment assignment)
        {
            AssignmentFile file = assignment.AssignmentFiles.Find(af => af.Name == fileName);

            FileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, file.FileName));

            FileSystem.FileCopy(Path.Combine(assignment.Path, file.FileName),
                        Path.Combine(teamSubmitDirName, file.FileName));
        }
Пример #10
0
        private void DeleteAndCopyMulitpleAssignmentFiles(string fileName, string teamSubmitDirName, Assignment assignment)
        {
            List<AssignmentFile> files = assignment.AssignmentFiles.FindAll(af => af.Name == fileName);
            foreach (AssignmentFile file in files)
            {
                FileSystem.DeleteFileIfExists(Path.Combine(teamSubmitDirName, file.FileName));

                FileSystem.FileCopy(Path.Combine(assignment.Path, file.FileName),
                            Path.Combine(teamSubmitDirName, file.FileName));
            }
        }
Пример #11
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));
        }
Пример #12
0
        private static string CreateTeamDirectory(SystemSettings sysSettings, string teamName, Assignment assignment)
        {
            MoCS.BuildService.Business.FileSystemWrapper fileSystem = new Business.FileSystemWrapper();

            string resultBasePath = ConfigurationManager.AppSettings["ResultBasePath"];
            if (!resultBasePath.EndsWith(@"\"))
            {
                resultBasePath += @"\";
            }

            //prepare processing
            //create a new directory for the basepath
            fileSystem.CreateDirectoryIfNotExists(resultBasePath);

            //create a directory for the assignment
            fileSystem.CreateDirectoryIfNotExists(resultBasePath + assignment.Name);

            string teamDirName = teamName + "_" + DateTime.Now.ToString("ddMMyyyy_HHmmss");
            string teamSubmitDirName = resultBasePath + assignment.Name + @"\" + teamDirName;
            //create a new directory for the teamsubmit
            fileSystem.CreateDirectory(teamSubmitDirName);

            return teamSubmitDirName;
        }
Пример #13
0
 private Assignment CreateIdAssignment(Assignment a)
 {
     Assignment result = new Assignment
     {
         Id = a.Id,
         AssignmentFiles = new List<AssignmentFile>(),
         Author = string.Empty,
         Category = string.Empty,
         CreateDate = DateTime.Now,
         Difficulty = 0,
         FriendlyName = string.Empty,
         ClassNameToImplement = string.Empty,
         InterfaceNameToImplement = string.Empty,
         Name = string.Empty,
         Path = string.Empty,
         Tagline = string.Empty,
         Version = 0
     };
     return result;
 }
Пример #14
0
        public byte[] GetAssignmentZip(Assignment assignment)
        {
            //Get the assignment
            assignment = _dataAccess.GetAssignmentById(assignment.Id);

            string path = Path.Combine(assignment.Path, assignment.Name + ".zip");

            if (!_fileSystem.FileExists(path))
            {
                throw new ApplicationException("Zip file does not exist");
            }

            byte[] zipBytes = null;
            using (FileStream fs = File.OpenRead(path))
            {
                zipBytes = FacadeHelpers.ConvertStreamToByteArray(fs);
            }

            return zipBytes;
        }