/// <summary> /// Export data into CSV format /// </summary> public CFile Export(FileSystem fs, ExportRow.ExportRowList rows) { int i; MemoryStream csvstream = new MemoryStream(); StreamWriter csvwriter = new StreamWriter(csvstream); //Write the data out in CSV style rows foreach (ExportRow row in rows) { for (i = 0; i < row.Fields.Count; i++) { csvwriter.Write(row.Fields[i]); if (i < row.Fields.Count-1) csvwriter.Write(","); } csvwriter.WriteLine(); } csvwriter.Flush(); //Commit to a temp file within the FS //Create a temp file Guid guid = Guid.NewGuid(); CFile expfile = fs.CreateFile(@"c:\system\export\" + guid.ToString(), false, new CFilePermission.FilePermissionList() ); expfile.Name = expfile.ID + ".csv"; fs.UpdateFileInfo(expfile, false); //Commit the data csvstream.Seek(0, SeekOrigin.Begin); expfile.RawData = Globals.ReadStream(csvstream, (int) csvstream.Length); fs.Edit(expfile); fs.Save(expfile); csvwriter.Close(); return expfile; }
/// <summary> /// Get the export heading for a course export /// </summary> public ExportRow GetCourseExportHeading(int courseID) { ExportRow row = new ExportRow(); Assignment.AssignmentList assts = new Courses(m_ident).GetAssignments(courseID); //User row.Fields.Add("Username"); //Course Total row.Fields.Add("Course Total"); foreach (Assignment asst in assts) row.Fields.AddRange(GetAsstExportHeading(asst.ID).Fields); return row; }
/// <summary> /// Get a user's grades for a course in "export" format /// </summary> public ExportRow GetCourseExport(string username, int courseID) { double totpoints, points; ExportRow row = new ExportRow(); Assignment.AssignmentList assts = new Courses(m_ident).GetAssignments(courseID); //User row.Fields.Add(username); totpoints = 0; foreach (Assignment asst in assts) { row.Fields.AddRange(GetAsstExport(username, asst.ID, out points).Fields); totpoints += points; } //Course Total row.Fields.Insert(1, totpoints.ToString()); return row; }
/// <summary> /// Get the heading row for an export /// </summary> public ExportRow GetAsstExportHeading(int asstID) { Rubrics rubda = new Rubrics(m_ident); ExportRow row = new ExportRow(); //Get all rubric entries for the assignment Assignment asst = new Assignments(m_ident).GetInfo(asstID); Rubric rub = new Assignments(m_ident).GetRubric(asstID); Rubric.RubricList rublist = rubda.Flatten(rub); //Total row.Fields.Add(asst.Description + " Total"); foreach (Rubric rubent in rublist) row.Fields.Add(rubent.Name); return row; }
public ExportRow GetAsstExport(Components.Submission sub, int asstID, out double totpoints) { Rubrics rubda = new Rubrics(m_ident); ExportRow row = new ExportRow(); //Get all rubric entries for the assignment Rubric rub = new Assignments(m_ident).GetRubric(asstID); Rubric.RubricList rublist = rubda.Flatten(rub); //Tally //Cats double points=0; foreach (Rubric rubent in rublist) { if (sub == null) row.Fields.Add("0"); else { double catpoints = rubda.GetPoints(rubent.ID, sub.ID); points += catpoints; row.Fields.Add(catpoints.ToString()); } } //Total row.Fields.Insert(0, points.ToString()); totpoints = points; return row; }