/// <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 cmdUpload_Click(object sender, System.EventArgs e) { if (fiUpload.PostedFile.FileName.Length == 0) { DisplayMessage("Please select a file to upload"); return; } FileSystem fs = new FileSystem(Globals.CurrentIdentity); string name = Path.GetFileName(fiUpload.PostedFile.FileName); SingleFileSource sfs = new SingleFileSource(name); try { sfs.CreateSource(fiUpload.PostedFile.InputStream); fs.ImportData(GetCurrentPath(), sfs, true, false); } catch (FileOperationException er) { DisplayMessage(er.Message); } BindFileGrid(); }