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); }
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); }
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)); }
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); } } }
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); }
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>(); }
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); }
// 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); } } } }
public KeyValuePair <WorkspacePath, IFileSystem> Get(WorkspacePath path) { return(Mounts.First(pair => pair.Key == path || pair.Key.IsParentOf(path))); }
public Stream CreateFile(WorkspacePath path) { var pair = Get(path); return(pair.Value.CreateFile(path.RemoveParent(pair.Key))); }
public bool Exists(WorkspacePath path) { return(path.IsFile ? File.Exists(GetPhysicalPath(path)) : Directory.Exists(GetPhysicalPath(path))); }
public bool Exists(WorkspacePath path) { return(path.IsDirectory ? _directories.ContainsKey(path) : _files.ContainsKey(path)); }
public string GetPhysicalPath(WorkspacePath path) { return(Path.Combine(PhysicalRoot, path.ToString().Remove(0, 1).Replace(WorkspacePath.DirectorySeparator, Path.DirectorySeparatorChar))); }
public Stream OpenFile(WorkspacePath path, FileAccess access) { var pair = Get(path); return(pair.Value.OpenFile(path.RemoveParent(pair.Key), access)); }
public ICollection <WorkspacePath> GetEntities(WorkspacePath path) { var paths = FileSystem.GetEntities(AppendRoot(path)); return(new EnumerableCollection <WorkspacePath>(paths.Select(p => RemoveRoot(p)), paths.Count)); }
public void CreateDirectory(WorkspacePath path) { var pair = Get(path); pair.Value.CreateDirectory(path.RemoveParent(pair.Key)); }
public bool Exists(WorkspacePath path) { return(FileSystems.Any(fs => fs.Exists(path))); }
public Stream OpenFile(WorkspacePath path, FileAccess access) { return(FileSystem.OpenFile(AppendRoot(path), access)); }
public Stream CreateFile(WorkspacePath path) { return(FileSystem.CreateFile(AppendRoot(path))); }
public bool Exists(WorkspacePath path) { return(FileSystem.Exists(AppendRoot(path))); }
public void Delete(WorkspacePath path) { var pair = Get(path); pair.Value.Delete(path.RemoveParent(pair.Key)); }
protected WorkspacePath RemoveRoot(WorkspacePath path) { return(path.RemoveParent(Root)); }
public void CreateDirectory(WorkspacePath path) { FileSystem.CreateDirectory(AppendRoot(path)); }
public SubFileSystem(IFileSystem fileSystem, WorkspacePath root) { FileSystem = fileSystem; Root = root; }
public IFileSystem GetFirst(WorkspacePath path) { return(FileSystems.FirstOrDefault(fs => fs.Exists(path))); }
public void Delete(WorkspacePath path) { FileSystem.Delete(AppendRoot(path)); }
public Stream CreateFile(WorkspacePath path) { var fs = GetFirst(path) ?? FileSystems.First(); return(fs.CreateFile(path)); }
protected WorkspacePath AppendRoot(WorkspacePath path) { return(Root.AppendPath(path)); }