コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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)));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 public static Tuple <VirtualDir, string> GetNameInExistingDirectory(this VirtualDir dir, string path)
 {
     return(dir.GetNameInExistingDirectory(path.Split(Path.DirectorySeparatorChar)));
 }
コード例 #8
0
 internal void RemoveDir(VirtualDir virtualDir)
 {
     Directories.Remove(virtualDir.Name);
 }
コード例 #9
0
 private VirtualFileSystem()
 {
     Root = new VirtualDir();
 }