public static Unit CopyTo(this VirtualDir dir, Tuple <VirtualDir, string> d) { if (dir == null) { throw new IOException("source directory does not exist"); } if (d == null) { throw new DirectoryNotFoundException(); } if (d.Item1.DirectoryExists(d.Item2) || d.Item1.FileExists(d.Item2)) { throw new IOException("name in target exists"); } var newDir = dir.Clone(); newDir.Name = d.Item2; newDir.Parent = d.Item1; d.Item1.Directories[newDir.Name] = newDir; return(Unit.Default); }
public static Dir ToDir(this VirtualDir dir) { if (dir == null) { throw new IOException("does not exist"); } var path = dir.GetPath(); var fs = dir.Files.Select(x => Path.Combine(path, x.Key)); var ds = dir.Directories.Select(x => Path.Combine(path, x.Key)); return(Dir.Create(path, ds, fs)); }
public static Unit Remove(this VirtualDir dir) { if (dir == null) { throw new DirectoryNotFoundException(); } if (dir.Parent != null) { dir.Parent.RemoveDir(dir); dir.Parent = null; } return(Unit.Default); }
public VirtualDir Clone() { var dir = new VirtualDir(); foreach (var sd in Directories) { dir.Directories[sd.Key] = sd.Value.Clone(); } foreach (var sf in Files) { dir.Files[sf.Key] = sf.Value.ConvertAll(_ => _); } return(dir); }
public static Tuple <VirtualDir, string> GetNameInExistingDirectory(this VirtualDir dir, IEnumerable <string> path) { if (dir == null) { throw new DirectoryNotFoundException("directory does not exist"); } if (!path.Any()) { throw new Exception("GetNameInDirectory called with an empty string"); } if (path.Count() == 1) { return(new Tuple <VirtualDir, string>(dir, path.Last())); } VirtualDir directory; dir.Directories.TryGetValue(path.First(), out directory); return(directory.GetNameInExistingDirectory(path.Skip(1))); }
public static Unit MoveTo(this VirtualDir dir, Tuple <VirtualDir, string> d) { if (dir == null) { throw new DirectoryNotFoundException("source directory does not exist"); } if (d == null) { throw new DirectoryNotFoundException("target directory does not exist"); } if (d.Item1.DirectoryExists(d.Item2) || d.Item1.FileExists(d.Item2)) { throw new IOException("name in target exists"); } dir.Parent.Directories.Remove(dir.Name); dir.Name = d.Item2; dir.Parent = d.Item1; d.Item1.Directories[dir.Name] = dir; return(Unit.Default); }
public static Tuple <VirtualDir, string> GetNameInExistingDirectory(this VirtualDir dir, string path) { return(dir.GetNameInExistingDirectory(path.Split(Path.DirectorySeparatorChar))); }
internal void RemoveDir(VirtualDir virtualDir) { Directories.Remove(virtualDir.Name); }
private VirtualFileSystem() { Root = new VirtualDir(); }