Exemplo n.º 1
0
        public void CreateDirectory(WorkspacePath path)
        {
            if (Exists(path))
            {
                throw new ArgumentException("The specified directory already exists.");
            }

            var fs = GetFirst(path.ParentPath);

            if (fs == null)
            {
                throw new ArgumentException("The directory-parent does not exist.");
            }

            fs.CreateDirectory(path);
        }
Exemplo n.º 2
0
        public static void Copy(this IFileSystem sourceFileSystem, WorkspacePath sourcePath,
                                IFileSystem destinationFileSystem, WorkspacePath destinationPath)
        {
            bool isFile;

            if ((isFile = sourcePath.IsFile) != destinationPath.IsFile)
            {
                throw new ArgumentException(
                          "The specified destination-path is of a different type than the source-path.");
            }

            if (isFile)
            {
                using (var sourceStream = sourceFileSystem.OpenFile(sourcePath, FileAccess.Read))
                {
                    using (var destinationStream = destinationFileSystem.CreateFile(destinationPath))
                    {
                        var buffer = new byte[BufferSize];
                        int readBytes;
                        while ((readBytes = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            destinationStream.Write(buffer, 0, readBytes);
                        }
                    }
                }
            }
            else
            {
                if (!destinationPath.IsRoot)
                {
                    destinationFileSystem.CreateDirectory(destinationPath);
                }
                foreach (var ep in sourceFileSystem.GetEntities(sourcePath))
                {
                    var destinationEntityPath = ep.IsFile
                        ? destinationPath.AppendFile(ep.EntityName)
                        : destinationPath.AppendDirectory(ep.EntityName);
                    Copy(sourceFileSystem, ep, destinationFileSystem, destinationEntityPath);
                }
            }

//            IEntityCopier copier;
//            if (!EntityCopiers.Registration.TryGetSupported(sourceFileSystem.GetType(), destinationFileSystem.GetType(),
//                out copier))
//                throw new ArgumentException("The specified combination of file-systems is not supported.");
//            copier.Copy(sourceFileSystem, sourcePath, destinationFileSystem, destinationPath);
        }
Exemplo n.º 3
0
        public WorkspacePath GetVirtualDirectoryPath(string physicalPath)
        {
            if (!physicalPath.StartsWith(PhysicalRoot, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("The specified path is not member of the PhysicalRoot.", "physicalPath");
            }

            var virtualPath = WorkspacePath.DirectorySeparator + physicalPath.Remove(0, PhysicalRoot.Length)
                              .Replace(Path.DirectorySeparatorChar, WorkspacePath.DirectorySeparator);

            if (virtualPath[virtualPath.Length - 1] != WorkspacePath.DirectorySeparator)
            {
                virtualPath += WorkspacePath.DirectorySeparator;
            }

            return(WorkspacePath.Parse(virtualPath));
        }
Exemplo n.º 4
0
        public static void CreateDirectoryRecursive(this IFileSystem fileSystem, WorkspacePath path)
        {
            if (!path.IsDirectory)
            {
                throw new ArgumentException("The specified path is not a directory.");
            }
            var currentDirectoryPath = WorkspacePath.Root;

            foreach (var dirName in path.GetDirectorySegments())
            {
                currentDirectoryPath = currentDirectoryPath.AppendDirectory(dirName);
                if (!fileSystem.Exists(currentDirectoryPath))
                {
                    fileSystem.CreateDirectory(currentDirectoryPath);
                }
            }
        }
Exemplo n.º 5
0
        public ICollection <WorkspacePath> GetEntities(WorkspacePath path)
        {
            var entities = new SortedList <WorkspacePath, WorkspacePath>();

            foreach (var fs in FileSystems.Where(fs => fs.Exists(path)))
            {
                foreach (var entity in fs.GetEntities(path))
                {
                    if (!entities.ContainsKey(entity))
                    {
                        entities.Add(entity, entity);
                    }
                }
            }

            return(entities.Values);
        }
Exemplo n.º 6
0
        public void CreateDirectory(WorkspacePath path)
        {
            if (!path.IsDirectory)
            {
                throw new ArgumentException("The specified path is no directory.", "path");
            }
            ISet <WorkspacePath> subentities;

            if (_directories.ContainsKey(path))
            {
                throw new ArgumentException("The specified directory-path already exists.", "path");
            }
            if (!_directories.TryGetValue(path.ParentPath, out subentities))
            {
                throw new DirectoryNotFoundException();
            }
            subentities.Add(path);
            _directories[path] = new HashSet <WorkspacePath>();
        }
Exemplo n.º 7
0
        public void Delete(WorkspacePath path)
        {
            if (path.IsRoot)
            {
                throw new ArgumentException("The root cannot be deleted.");
            }
            bool removed;

            if (path.IsDirectory)
            {
                removed = _directories.Remove(path);
            }
            else
            {
                removed = _files.Remove(path);
            }
            if (!removed)
            {
                throw new ArgumentException("The specified path does not exist.");
            }
            var parent = _directories[path.ParentPath];

            parent.Remove(path);
        }
Exemplo n.º 8
0
//        public static Stream Open(this File file, FileAccess access)
//        {
//            return file.FileSystem.OpenFile(file.Path, access);
//        }
//
//        public static void Delete(this FileSystemEntity entity)
//        {
//            entity.FileSystem.Delete(entity.Path);
//        }

//        public static ICollection<FileSystemPath> GetEntityPaths(this Directory directory)
//        {
//            return directory.FileSystem.GetEntities(directory.Path);
//        }

//        public static ICollection<FileSystemEntity> GetEntities(this Directory directory)
//        {
//            var paths = directory.GetEntityPaths();
//            return new EnumerableCollection<FileSystemEntity>(
//                paths.Select(p => FileSystemEntity.Create(directory.FileSystem, p)), paths.Count);
//        }

        public static IEnumerable <WorkspacePath> GetEntitiesRecursive(this IFileSystem fileSystem, WorkspacePath path)
        {
            if (!path.IsDirectory)
            {
                throw new ArgumentException("The specified path is not a directory.");
            }
            foreach (var entity in fileSystem.GetEntities(path))
            {
                yield return(entity);

                if (entity.IsDirectory)
                {
                    foreach (var subentity in fileSystem.GetEntitiesRecursive(entity))
                    {
                        yield return(subentity);
                    }
                }
            }
        }
Exemplo n.º 9
0
 public KeyValuePair <WorkspacePath, IFileSystem> Get(WorkspacePath path)
 {
     return(Mounts.First(pair => pair.Key == path || pair.Key.IsParentOf(path)));
 }
Exemplo n.º 10
0
        public Stream CreateFile(WorkspacePath path)
        {
            var pair = Get(path);

            return(pair.Value.CreateFile(path.RemoveParent(pair.Key)));
        }
Exemplo n.º 11
0
 public bool Exists(WorkspacePath path)
 {
     return(path.IsFile
         ? File.Exists(GetPhysicalPath(path))
         : Directory.Exists(GetPhysicalPath(path)));
 }
Exemplo n.º 12
0
 public bool Exists(WorkspacePath path)
 {
     return(path.IsDirectory ? _directories.ContainsKey(path) : _files.ContainsKey(path));
 }
Exemplo n.º 13
0
 public string GetPhysicalPath(WorkspacePath path)
 {
     return(Path.Combine(PhysicalRoot,
                         path.ToString().Remove(0, 1).Replace(WorkspacePath.DirectorySeparator, Path.DirectorySeparatorChar)));
 }
Exemplo n.º 14
0
        public Stream OpenFile(WorkspacePath path, FileAccess access)
        {
            var pair = Get(path);

            return(pair.Value.OpenFile(path.RemoveParent(pair.Key), access));
        }
Exemplo n.º 15
0
        public ICollection <WorkspacePath> GetEntities(WorkspacePath path)
        {
            var paths = FileSystem.GetEntities(AppendRoot(path));

            return(new EnumerableCollection <WorkspacePath>(paths.Select(p => RemoveRoot(p)), paths.Count));
        }
Exemplo n.º 16
0
        public void CreateDirectory(WorkspacePath path)
        {
            var pair = Get(path);

            pair.Value.CreateDirectory(path.RemoveParent(pair.Key));
        }
Exemplo n.º 17
0
 public bool Exists(WorkspacePath path)
 {
     return(FileSystems.Any(fs => fs.Exists(path)));
 }
Exemplo n.º 18
0
 public Stream OpenFile(WorkspacePath path, FileAccess access)
 {
     return(FileSystem.OpenFile(AppendRoot(path), access));
 }
Exemplo n.º 19
0
 public Stream CreateFile(WorkspacePath path)
 {
     return(FileSystem.CreateFile(AppendRoot(path)));
 }
Exemplo n.º 20
0
 public bool Exists(WorkspacePath path)
 {
     return(FileSystem.Exists(AppendRoot(path)));
 }
Exemplo n.º 21
0
        public void Delete(WorkspacePath path)
        {
            var pair = Get(path);

            pair.Value.Delete(path.RemoveParent(pair.Key));
        }
Exemplo n.º 22
0
 protected WorkspacePath RemoveRoot(WorkspacePath path)
 {
     return(path.RemoveParent(Root));
 }
Exemplo n.º 23
0
 public void CreateDirectory(WorkspacePath path)
 {
     FileSystem.CreateDirectory(AppendRoot(path));
 }
Exemplo n.º 24
0
 public SubFileSystem(IFileSystem fileSystem, WorkspacePath root)
 {
     FileSystem = fileSystem;
     Root       = root;
 }
Exemplo n.º 25
0
 public IFileSystem GetFirst(WorkspacePath path)
 {
     return(FileSystems.FirstOrDefault(fs => fs.Exists(path)));
 }
Exemplo n.º 26
0
 public void Delete(WorkspacePath path)
 {
     FileSystem.Delete(AppendRoot(path));
 }
Exemplo n.º 27
0
        public Stream CreateFile(WorkspacePath path)
        {
            var fs = GetFirst(path) ?? FileSystems.First();

            return(fs.CreateFile(path));
        }
Exemplo n.º 28
0
 protected WorkspacePath AppendRoot(WorkspacePath path)
 {
     return(Root.AppendPath(path));
 }