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); }
public Assignment GetAssignmentById(int assignmentId, bool includeServerFiles) { Assignment result = _dataAccess.GetAssignmentById(assignmentId); if (result != null) { // TODO Fill the object with additional data from the XML-file if (!string.IsNullOrEmpty(result.Path)) { result = FacadeHelpers.FillAssignmentDetailsFromXml(result, _fileSystem, includeServerFiles); } } return(result); }
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); }
public TournamentAssignment GetTournamentAssignmentById(int id, bool includeServerFiles) { TournamentAssignment result = _dataAccess.GetTournamentAssignmentById(id); if (result != null) { // TODO Fill the object with additional data from the XML-file if (!string.IsNullOrEmpty(result.Assignment.Path)) { result.Assignment = FacadeHelpers.FillAssignmentDetailsFromXml(result.Assignment, _fileSystem, includeServerFiles); } //result.Assignment.AssignmentFiles //result.Assignment.Author //result.Assignment.Category //result.Assignment.Difficulty = //result.Assignment.ClassNameToImplement = //result.Assignment.InterfaceNameToImplement = //result.Assignment.Version = } return(result); }