public void ExtractTo(string description, Stream stream, string folder) { Console.WriteLine("Writing contents of zip file {0} to {1}", description, folder); if (Directory.Exists(folder)) { Directory.Delete(folder, true); } Directory.CreateDirectory(folder); var system = new FileSystem(); string fileName = Path.GetTempFileName(); system.WriteStreamToFile(fileName, stream); using (var zipFile = new ZipFile(fileName)) { zipFile.ExtractAll(folder, ExtractExistingFileAction.OverwriteSilently); } system.DeleteFile(fileName); }
public IPackage ExplodeTo(string directory) { var explodedDirectory = ExplodedDirectory(directory); RippleLog.Info("Exploding to " + explodedDirectory); var fileSystem = new FileSystem(); fileSystem.CreateDirectory(explodedDirectory); fileSystem.ForceClean(explodedDirectory); var package = new ZipPackage(_path); package.GetFiles().Each(file => { var target = explodedDirectory.AppendPath(file.Path); fileSystem.CreateDirectory(target.ParentDirectory()); using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write)) { file.GetStream().CopyTo(stream); } }); fileSystem.CopyToDirectory(_path, explodedDirectory); fileSystem.DeleteFile(_path); var newFile = Path.Combine(explodedDirectory, Path.GetFileName(_path)); return new ZipPackage(newFile); }
private void DoDelete(int subID, int locid) { FileSystem fs = new FileSystem(m_ident); //Take results Results resultda = new Results(m_ident); Result.ResultList ress = GetResults(subID); foreach (Result res in ress) resultda.Delete(res.ID); //Take any tests queued AutoJobs jobda = new AutoJobs(m_ident); AutoJobTest.AutoJobTestList tests = jobda.GetSubTests(subID); foreach (AutoJobTest test in tests) jobda.FinishTest(test); //Take the submission record m_dp.DeleteSubmission(subID); //Take the files CFile subdir = fs.GetFile(locid); if (subdir != null) fs.DeleteFile(subdir); }
/// <summary> /// Delete the assignment /// </summary> public bool Delete(int asstID) { FileSystem fs = new FileSystem(m_ident); Submissions subda = new Submissions(m_ident); Evaluations evalda = new Evaluations(m_ident); Results resultda = new Results(m_ident); Groups groupda = new Groups(m_ident); AutoJobs jobda = new AutoJobs(m_ident); Assignment asst = GetInfo(asstID); //Check permission Authorize(asst.CourseID, "delete", asstID, null); //Take auto jobs IProviderTransaction tran = m_dp.BeginTransaction(); AutoJob.AutoJobList jobs = GetAutoJobs(asstID, tran); foreach (AutoJob job in jobs) jobda.Finish(job.ID, tran); m_dp.CommitTransaction(tran); //Take submissions and results Components.Submission.SubmissionList allsubs = GetSubmissions(asstID); foreach (Components.Submission sub in allsubs) subda.Delete(sub.ID); //Take rubric Rubric rub = GetRubric(asstID); new Rubrics(m_ident).Delete(rub.ID); //Take evaluations Evaluation.EvaluationList allevals = GetEvals(asstID); foreach (Evaluation eval in allevals) evalda.Delete(eval.ID); //Take groups Group.GroupList groups = GetGroups(asstID); foreach (Group group in groups) groupda.Delete(group.PrincipalID, asstID); //Take assignment m_dp.DeleteAssignment(asstID); //Take content CFile content = fs.GetFile(asst.ContentID); fs.DeleteFile(content); //Log Log("Deleted assignment: " + asst.Description, asst.ID); return true; }
private bool tb_Delete(object sender, EventArgs e) { TreeNode node; int ty = GetNodeType(node = GetCurrentNode()); switch (ty) { case USER: try { new Courses(Globals.CurrentIdentity).RemoveUser( node.NodeData.Split(" ".ToCharArray())[1], GetCourseID()); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } break; case USERSUB: try { int subID = Convert.ToInt32(node.NodeData.Split(" ".ToCharArray())[2]); new Submissions(Globals.CurrentIdentity).Delete(subID); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } break; case ASSIGNMENT: try { new Assignments(Globals.CurrentIdentity).Delete(GetNodeIndex(node)); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } break; case ANNOUNCEMENT: try { new Announcements(Globals.CurrentIdentity).Delete(GetNodeIndex(node)); } catch (DataAccessException er) { PageError(er.Message); } break; case SECTION: try { new Sections(Globals.CurrentIdentity).Delete(GetNodeIndex(node)); } catch (DataAccessException er) { PageError(er.Message); } break; case HEADING: case CANNED: case AUTOMATIC: Rubric rub = new Rubrics(Globals.CurrentIdentity).GetInfo(GetNodeIndex(node)); if (rub.ParentID < 0) PageError("Cannot delete the root rubric"); else { try { new Rubrics(Globals.CurrentIdentity).Delete(rub.ID); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } } break; case FOLDER: case DOCUMENT: FileSystem fs = new FileSystem(Globals.CurrentIdentity); CFile file = fs.GetFile(GetNodeIndex(node)); try { fs.DeleteFile(file); } catch (DataAccessException er) { PageError(er.Message); } catch (FileOperationException er) { PageError(er.Message); } break; } LoadNode((TreeNode)node.Parent); ActivateNodeView((TreeNode)node.Parent); return true; }