/// <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> /// Create the course /// </summary> public bool Create(string name, string number, string instructor) { Course course = new Course(); //TODO: Verify these values course.Name = name; course.Number = number; //Create course m_dp.CreateCourse(course); //Get all data course = GetInfo(course.ID); //Define default roles CourseRole role = new CourseRole(); role.CourseID = course.ID; role.Name = "Student"; role.Staff = false; m_dp.CreateCourseRole(role); role.Name = "TA"; role.Staff = true; m_dp.CreateCourseRole(role); role.Name = "Instructor"; role.Staff = true; m_dp.CreateCourseRole(role); //Assign filesys permissions CourseRole student = GetRoleInfo("Student", course.ID); CourseRole ta = GetRoleInfo("TA", course.ID); CourseRole ins = GetRoleInfo("Instructor", course.ID); CFilePermission.FilePermissionList full = new CFilePermission.FilePermissionList(); full.AddRange(CFilePermission.CreateFullAccess(ta.PrincipalID)); full.AddRange(CFilePermission.CreateFullAccess(ins.PrincipalID)); full.Add(new CFilePermission(student.PrincipalID, FileAction.READ, true)); //Create content area FileSystem fs = new FileSystem(m_ident); string cpath = @"c:\ccontent\" + course.ID; CFile cdir = fs.CreateDirectory(cpath, false, full); course.ContentID = cdir.ID; Update(course); CFile ldir = fs.CreateDirectory(cpath + @"\" + "lnotes", false, null); ldir.Alias = "Lecture Notes"; fs.UpdateFileInfo(ldir, false); //Put operator in course temporarily m_dp.CreateCourseMember(m_ident.Name, course.ID, "Instructor", null); //Assign course perms CreatePermissions(course.ID, course.ID, Permission.COURSE); if (instructor != m_ident.Name) { //Add instructor AddUser(instructor, "Instructor", course.ID, null); //Take operator out RemoveUser(m_ident.Name, course.ID); } return true; }
/// <summary> /// Load submission directory with new files, updates time /// </summary> public bool Update(Submission sub, IExternalSource files) { FileSystem fs = new FileSystem(m_ident); bool markcmp, unmarkcmp, defunct; //Get old sub Components.Submission oldsub = GetInfo(sub.ID); markcmp = (oldsub.Status == Components.Submission.UNGRADED && sub.Status == Components.Submission.GRADED); unmarkcmp = (oldsub.Status == Components.Submission.GRADED && sub.Status == Components.Submission.UNGRADED); defunct = (oldsub.Status != Components.Submission.DEFUNCT && sub.Status == Components.Submission.DEFUNCT); //Make sure toplevel zone directory exists CFile subdir = fs.GetFile(@"c:\subs"); if (null == subdir) subdir = fs.CreateDirectory(@"c:\subs", true, null, false); //Build file perms CFilePermission.FilePermissionList perms = new CFilePermission.FilePermissionList(); int courseID = new Assignments(m_ident).GetInfo(sub.AsstID).CourseID; CourseRole.CourseRoleList staff = new Courses(m_ident).GetTypedRoles(courseID, true, null); foreach (CourseRole role in staff) perms.AddRange(CFilePermission.CreateFullAccess(role.PrincipalID)); perms.AddRange(CFilePermission.CreateOprFullAccess(sub.PrincipalID)); //Create zone directory CFile esubdir; string zpath = @"c:\subs\" + sub.ID; if (null == (esubdir = fs.GetFile(zpath))) { esubdir = fs.CreateDirectory(zpath, false, perms, false); esubdir.SpecType = CFile.SpecialType.SUBMISSION; string name = new Principals(m_ident).GetInfo(sub.PrincipalID).Name; esubdir.Alias = String.Format("{0}: {1}", name, GetNextSubmission(sub.AsstID, sub.PrincipalID)); fs.UpdateFileInfo(esubdir, false); } //Update sub entry sub.LocationID = esubdir.ID; m_dp.UpdateSubmission(sub); //Load files try { fs.ImportData(zpath, files, false, false); //Import the data } catch (Exception) { throw new DataAccessException("Invalid external file source. This means the system does " + "not understand how to extract files from the source. Please create a valid source"); } //Verify submission structure VerifyFormat(sub.AsstID, zpath); //Log if (markcmp) Log("User [" + m_ident.Name + "] marked submission " + esubdir.Alias + " completed", sub.ID); else if (unmarkcmp) Log("User [" + m_ident.Name + "] marked submission " + esubdir.Alias + " incomplete", sub.ID); else if (defunct) Log("User [" + m_ident.Name + "] marked submission " + esubdir.Alias + " defunct", sub.ID); return true; }
private void cmdUrlUpload_Click(object sender, System.EventArgs e) { FileSystem fs = new FileSystem(Globals.CurrentIdentity); CFile file = fs.GetFile(GetFileID()); try { //Save Url data fs.Edit(file); file.Data = txtUrl.Text.ToCharArray(); fs.Save(file); //Update file file.Name = file.ID + ".url"; fs.UpdateFileInfo(file, false); } catch (Exception er) { PageLinkError(er.Message); } BindData(); if (Refresh != null) Refresh(this, new RefreshEventArgs("", true, false)); }
private void cmdUpdate_Click(object sender, EventArgs e) { FileSystem fs; CFile file = (fs = new FileSystem(Globals.CurrentIdentity)).GetFile(GetFileID()); file.Alias = txtName.Text; file.Description = txtDesc.Text; string tyext = txtType.Text; if (!tyext.StartsWith(".")) tyext = "." + tyext; file.Name = Path.GetFileNameWithoutExtension(file.Name) + tyext; try { fs.UpdateFileInfo(file, false); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } if (Refresh != null) Refresh(this, new RefreshEventArgs("", true, false)); }
private void cmdDataUpload_Click(object sender, EventArgs e) { if (ufContent.PostedFile.ContentLength > 0) { FileSystem fs = new FileSystem(Globals.CurrentIdentity); CFile file = fs.GetFile(GetFileID()); try { fs.Edit(file); byte[] content = Globals.ReadStream( ufContent.PostedFile.InputStream, ufContent.PostedFile.ContentLength); file.RawData = content; fs.Save(file); file.Name = file.ID + Path.GetFileName(ufContent.PostedFile.FileName); fs.UpdateFileInfo(file, false); } catch (Exception er) { PageUpError(er.Message); } if (Refresh != null) Refresh(this, new RefreshEventArgs("", true, false)); } else PageUpError("Must specify a local file to upload"); BindData(); }
private void dgFiles_UpdateCommand(object source, DataGridCommandEventArgs e) { FileSystem fs = new FileSystem(Globals.CurrentIdentity); TextBox txtName = e.Item.FindControl("txtName") as TextBox; int fileID = (int) dgFiles.DataKeys[e.Item.ItemIndex]; CFile file = fs.GetFile(fileID); if (file.Alias == file.Name) file.Name = txtName.Text; file.Alias = txtName.Text; try { fs.UpdateFileInfo(file, false); } catch (FileOperationException er) { DisplayMessage(er.Message); } dgFiles.EditItemIndex = -1; UpdateTreeNode(tvFiles.GetNodeFromIndex(tvFiles.SelectedNodeIndex), true); BindFileGrid(); }
private bool tb_CreateFolder(object sender, EventArgs e) { FileSystem fs = new FileSystem(Globals.CurrentIdentity); CFile par = fs.GetFile(GetCurrentFileID()); string path = par.FullPath + @"\" + "newfolder"; try { CFile fold = fs.CreateDirectory(path, false, null); fold.Alias = "New Folder"; fold.Name = fold.ID + fold.Name; fs.UpdateFileInfo(fold, false); } catch (FileOperationException er) { PageError(er.Message); return false; } TreeNode node = GetCurrentNode(); LoadNode(node); node.Expanded = true; return true; }
private bool tb_CreateDocument(object sender, EventArgs e) { FileSystem fs = new FileSystem(Globals.CurrentIdentity); CFile par = fs.GetFile(GetCurrentFileID()); string path = par.FullPath + @"\" + "newdoc.txt"; try { CFile doc = fs.CreateFile(path, false, null); doc.Alias = "New Document"; doc.Name = doc.ID + doc.Name; fs.UpdateFileInfo(doc, false); } catch (FileOperationException er) { PageError(er.Message); return false; } TreeNode node = GetCurrentNode(); LoadNode(node); node.Expanded = true; return true; }