public void Move(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath 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 = source.OpenFile(sourcePath, FileAccess.Read)) { using (var destinationStream = destination.CreateFile(destinationPath)) { byte[] buffer = new byte[BufferSize]; int readBytes; while ((readBytes = sourceStream.Read(buffer, 0, buffer.Length)) > 0) destinationStream.Write(buffer, 0, readBytes); } } source.Delete(sourcePath); } else { destination.CreateDirectory(destinationPath); foreach (var ep in source.GetEntities(sourcePath).ToArray()) { var destinationEntityPath = ep.IsFile ? destinationPath.AppendFile(ep.EntityName) : destinationPath.AppendDirectory(ep.EntityName); Move(source, ep, destination, destinationEntityPath); } if (!sourcePath.IsRoot) source.Delete(sourcePath); } }
public void AppendFileTest() { Directories.All(d => d.AppendFile("file").IsFile); Directories.All(d => d.AppendFile("file").EntityName == "file"); Directories.All(d => d.AppendFile("file").ParentPath == d); EAssert.Throws <InvalidOperationException>(() => fileA.AppendFile("file")); EAssert.Throws <ArgumentException>(() => directoryA.AppendFile("dir/file")); }
public void ParentPathTest() { Assert.IsTrue( Directories .Where(d => d.GetDirectorySegments().Length == 1) .All(d => d.ParentPath == root) ); Assert.IsFalse(!Files.All(f => f.RemoveChild(root.AppendFile(f.EntityName)) == f.ParentPath)); EAssert.Throws <InvalidOperationException>(() => Assert.AreEqual(root.ParentPath, root.ParentPath)); }
public void ParentPathTest() { Assert.True( Directories .Where(d => d.GetDirectorySegments().Length == 1) .All(d => d.ParentPath == _root) ); Assert.False(Files != null && Files.Any(f => f.RemoveChild(_root.AppendFile(f.EntityName)) != f.ParentPath)); EAssert.Throws <InvalidOperationException>(() => Assert.Equal(_root.ParentPath, _root.ParentPath)); }
public void Copy(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath) { var pSource = (PhysicalFileSystem)source; var pDestination = (PhysicalFileSystem)destination; var pSourcePath = pSource.GetPhysicalPath(sourcePath); var pDestinationPath = pDestination.GetPhysicalPath(destinationPath); if (sourcePath.IsFile) System.IO.File.Copy(pSourcePath, pDestinationPath); else { destination.CreateDirectory(destinationPath); foreach(var e in source.GetEntities(sourcePath)) source.Copy(e, destination, e.IsFile ? destinationPath.AppendFile(e.EntityName) : destinationPath.AppendDirectory(e.EntityName)); } }
public void AppendFileTest() { foreach (var d in Directories) { Assert.IsTrue(d.AppendFile("file").IsFile); } foreach (var d in Directories) { Assert.IsTrue(d.AppendFile("file").EntityName == "file"); } foreach (var d in Directories) { Assert.IsTrue(d.AppendFile("file").ParentPath == d); } EAssert.Throws <InvalidOperationException>(() => fileA.AppendFile("file")); EAssert.Throws <ArgumentException>(() => directoryA.AppendFile("dir/file")); }
public void AppendFileTest() { foreach (var d in Directories) { Assert.True(d.AppendFile("file").IsFile); } foreach (var d in Directories) { Assert.True(d.AppendFile("file").EntityName == "file"); } foreach (var d in Directories) { Assert.True(d.AppendFile("file").ParentPath == d); } // ReSharper disable ReturnValueOfPureMethodIsNotUsed EAssert.Throws <InvalidOperationException>(() => _fileA.AppendFile("file")); EAssert.Throws <ArgumentException>(() => DirectoryA.AppendFile("dir/file")); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
/// <summary> /// Copies an entity from a source file system to a destination file system (async with cancellation token). /// </summary> public async Task CopyAsync(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath, CancellationToken cancellationToken) { var pSource = (PhysicalFileSystem)source; var pDestination = (PhysicalFileSystem)destination; var pSourcePath = pSource.GetPhysicalPath(sourcePath); var pDestinationPath = pDestination.GetPhysicalPath(destinationPath); if (sourcePath.IsFile) { await CopyFileAsyncInternal(pSourcePath, pDestinationPath, cancellationToken, BufferSize); } else { destination.CreateDirectory(destinationPath); foreach (var e in source.GetEntities(sourcePath)) { await source.CopyAsync(e, destination, e.IsFile?destinationPath.AppendFile(e.EntityName) : destinationPath.AppendDirectory(e.EntityName), cancellationToken); } } }
/// <summary> /// Copies an entity from a source file system to a destination file system. /// </summary> public void Copy(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath) { var pSource = (PhysicalFileSystem)source; var pDestination = (PhysicalFileSystem)destination; var pSourcePath = pSource.GetPhysicalPath(sourcePath); var pDestinationPath = pDestination.GetPhysicalPath(destinationPath); if (sourcePath.IsFile) { System.IO.File.Copy(pSourcePath, pDestinationPath); } else { destination.CreateDirectory(destinationPath); foreach (var e in source.GetEntities(sourcePath)) { source.Copy(e, destination, e.IsFile ? destinationPath.AppendFile(e.EntityName) : destinationPath.AppendDirectory(e.EntityName)); } } }