public void CanGetDirectory_ByPath() { Directory d = (Directory)upload.GetChild("Folder 2/Folder 3"); Assert.That(d, Is.Not.Null); Assert.That(d.Name, Is.EqualTo("Folder 3")); }
private void AssertMovement(Action <File, Directory> moveAction) { Directory sourceDirectory = (Directory)upload.GetChild("Folder1"); Directory destinationDirectory = (Directory)upload.GetChild("Folder 2"); File f = (File)sourceDirectory.GetChild("File1.txt"); moveAction(f, destinationDirectory); Assert.That(sourceDirectory.GetChild("File1.txt"), Is.Null); Assert.That(f.Parent, Is.EqualTo(destinationDirectory)); Assert.That(destinationDirectory.GetChild("File1.txt"), Is.Not.Null); }
private void ExportDirectory(ZipOutputStream zip, Directory directory) { foreach (var file in directory.GetFiles()) { zip.PutNextEntry(file.Url.Substring(rootPath.Length)); fileSystem.ReadFileContents(file.Url, zip); } foreach (var subDirectory in directory.GetDirectories()) { ExportDirectory(zip, subDirectory); } }
public void CanMoveDirectory_ToRootDirectory() { Directory d = (Directory)upload.GetChild("Folder 2/Folder 3"); string sourcePath = MapPath("/Upload/Folder 2/Folder 3"); string destinationPath = MapPath("/Upload/Folder 3"); try { d.AddTo(upload); Assert.That(System.IO.Directory.Exists(destinationPath)); Assert.That(!System.IO.Directory.Exists(sourcePath)); } finally { if (System.IO.Directory.Exists(destinationPath)) { System.IO.Directory.Move(destinationPath, sourcePath); } } }
public void MoveDirectory_TriggersEvent() { Directory d = (Directory)upload.GetChild("Folder 2/Folder 3"); string sourcePath = MapPath("/Upload/Folder 2/Folder 3"); string destinationPath = MapPath("/Upload/Folder1/Folder 3"); try { d.AddTo(upload.GetChild("Folder1")); Assert.That(arguments[0].SourcePath, Is.EqualTo("/Upload/Folder 2/Folder 3/")); Assert.That(arguments[0].VirtualPath, Is.EqualTo("/Upload/Folder1/Folder 3")); Assert.That(operations[0], Is.EqualTo("DirectoryMoved")); } finally { if (System.IO.Directory.Exists(destinationPath)) { System.IO.Directory.Move(destinationPath, sourcePath); } } }
public void CanMoveFile_ToOtherDirectory() { File f = (File)upload.GetChild("Folder 2/Folder 3/File 3.txt"); string sourcePath = MapPath(@"/Upload/Folder 2/Folder 3/File 3.txt"); string destinationPath = MapPath(@"/Upload/Folder1/File 3.txt"); Directory d = (Directory)upload.GetChild("Folder1"); try { f.AddTo(d); Assert.That(System.IO.File.Exists(destinationPath)); Assert.That(!System.IO.File.Exists(sourcePath)); } finally { if (System.IO.File.Exists(destinationPath)) { System.IO.File.Move(destinationPath, sourcePath); } } }
private void CopyAndDelete(Func <File, Directory, ContentItem> copyAction) { Directory d1 = (Directory)upload.GetChild("Folder1"); Directory d2 = (Directory)upload.GetChild("Folder 2"); File f = (File)d1.GetChild("File1.txt"); File fCopy = null; try { fCopy = (File)copyAction(f, d2); Assert.That(d2.GetChild("File1.txt"), Is.Not.Null); Assert.That(fCopy.Parent, Is.EqualTo(d2)); Assert.That(d1.GetChild("File1.txt"), Is.Not.Null); Assert.That(f.Parent, Is.EqualTo(d1)); } finally { if (fCopy != null) { fCopy.Delete(); } } }
public void MovingFile_TriggersEvent() { File f = (File)upload.GetChild("Folder 2/Folder 3/File 3.txt"); string sourcePath = MapPath(@"/Upload/Folder 2/Folder 3/File 3.txt"); string destinationPath = MapPath(@"/Upload/Folder1/File 3.txt"); Directory d = (Directory)upload.GetChild("Folder1"); try { f.AddTo(d); Assert.That(arguments[0].SourcePath, Is.EqualTo(@"/Upload/Folder 2/Folder 3/File 3.txt")); Assert.That(arguments[0].VirtualPath, Is.EqualTo(@"/Upload/Folder1/File 3.txt")); Assert.That(operations[0], Is.EqualTo("FileMoved")); } finally { if (System.IO.File.Exists(destinationPath)) { System.IO.File.Move(destinationPath, sourcePath); } } }
public ContentItem CopyTo(ContentItem destination) { AbstractDirectory d = AbstractDirectory.EnsureDirectory(destination); string to = Combine(d.Url, Name); if (FileSystem.FileExists(to)) throw new NameOccupiedException(this, d); FileSystem.CreateDirectory(to); Directory copy = new Directory(FileSystem.GetDirectory(to), d); copy.Set(FileSystem); foreach (File f in GetFiles()) f.CopyTo(copy); foreach (Directory childDir in GetDirectories()) childDir.CopyTo(copy); return copy; }
protected override void OnInit(EventArgs e) { FS = Engine.Resolve<IFileSystem>(); Register.JQueryUi(Page); var selected = Selection.SelectedItem; if (IsPostBack && !string.IsNullOrEmpty(inputFile.PostedFile.FileName)) { string uploadFolder = Request["inputLocation"]; if(!IsAvailable(uploadFolder)) throw new N2Exception("Cannot upload to " + Server.HtmlEncode(uploadFolder)); string fileName = System.IO.Path.GetFileName(inputFile.PostedFile.FileName); string filePath = Url.Combine(uploadFolder, fileName); FS.WriteFile(filePath, inputFile.PostedFile.InputStream); ClientScript.RegisterStartupScript(typeof(Tree), "select", "updateOpenerWithUrlAndClose('" + ResolveUrl(filePath) + "');", true); } else if (Request["location"] == "files" || Request["location"] == "filesselection") { IHost host = Engine.Resolve<IHost>(); HierarchyNode<ContentItem> root = new HierarchyNode<ContentItem>(Engine.Persister.Get(host.DefaultSite.RootItemID)); var selectionTrail = new List<ContentItem>(); if (selected is AbstractNode) { selectionTrail = new List<ContentItem>(Find.EnumerateParents(selected, null, true)); } else { TrySelectingPrevious(ref selected, ref selectionTrail); } foreach (string uploadFolder in Engine.EditManager.UploadFolders) { var dd = FS.GetDirectory(uploadFolder); var dir = new Directory(dd, root.Current); dir.Set(FS); var node = CreateDirectoryNode(FS, dir, root, selectionTrail); root.Children.Add(node); } AddSiteFilesNodes(root, host.DefaultSite, selectionTrail); foreach (var site in host.Sites) { AddSiteFilesNodes(root, site, selectionTrail); } siteTreeView.Nodes = root; siteTreeView.SelectedItem = selected; } else { var filter = Engine.EditManager.GetEditorFilter(Page.User); siteTreeView.Filter = filter; siteTreeView.RootNode = Engine.Resolve<Navigator>().Navigate(Request["root"] ?? "/"); siteTreeView.SelectedItem = selected; } siteTreeView.DataBind(); base.OnInit(e); }
private void AddSiteFilesNodes(HierarchyNode<ContentItem> parent, Site site, List<ContentItem> selectionTrail) { var siteNode = Engine.Persister.Get(site.StartPageID); HierarchyNode<ContentItem> node = null; foreach (DirectoryData dd in Engine.Resolve<IContentAdapterProvider>() .ResolveAdapter<NodeAdapter>(siteNode) .GetUploadDirectories(site)) { if(node == null) node = new HierarchyNode<ContentItem>(siteNode); var dir = new Directory(dd, parent.Current); dir.Set(FS); var directoryNode = CreateDirectoryNode(FS, dir, node, selectionTrail); node.Children.Add(directoryNode); } if (node != null) parent.Children.Add(node); }
private static void Apply(PermissionMap map, Directory dir) { if (map.IsAltered) DynamicPermissionMap.SetRoles(dir, map.Permissions, map.Roles); else DynamicPermissionMap.SetAllRoles(dir, map.Permissions); }
internal static Items.Directory New(DirectoryData dir, ContentItem parent, IDependencyInjector injector) { var node = new Directory(dir, parent); injector.FulfilDependencies(node); return node; }
private Directory CreateDirectory(FolderPair pair) { var dd = fs.GetDirectory(pair.FolderPath); var parent = persister.Get(pair.ParentID); var dir = new Directory(dd, parent); dir.Set(fs); dir.Title = pair.Path.Substring(pair.ParentPath.Length).Trim('/'); dir.Name = dir.Title; return dir; }
internal static Items.Directory New(DirectoryData dir, ContentItem parent, IFileSystem fs, ImageSizeCache sizes) { var node = new Directory(dir, parent); node.Set(fs); node.Set(sizes); return node; }