protected internal void MoveSubDirectory(DirectoryMock directory, DirectoryMock targetDir) { var r = _directories.Remove(directory.Name); //directory.Path = targetPath; //directory.Name = System.IO.Path.GetDirectoryName(targetPath); targetDir._directories.Add(directory.Name, directory); }
protected internal void MoveFile(FileMock file, string targetPath, DirectoryMock targetDir) { var r = _files.Remove(file.Name); file.Path = targetPath; file.Name = System.IO.Path.GetFileName(file.Path); targetDir._files.Add(file.Name, file); }
protected internal void DeleteDirectory(DirectoryMock directory, bool recursive) { var files = directory.Files.ToList(); var directories = directory.Directories.SelectMany(x => x.Value.Directories).ToList(); if (!recursive) { if (files.Any() || directories.Any()) throw new IOException(Lux.IO.Consts.ErrorMessages.ERROR_DIR_NOT_EMPTY); } foreach (var file in files.Select(x => x.Value)) { directory.DeleteFile(file); } foreach (var dir in directories.Select(x => x.Value)) { directory.DeleteDirectory(dir, true); } directory.IsDeleted = true; var r = _directories.Remove(directory.Name); }
private void MoveDirectory(DirectoryMock directory, DirectoryMock target) { var parentDirPath = PathHelper.GetParent(directory.Path); var parentDir = GetDirectory(parentDirPath); if (parentDir == null) { _log.Debug($"MoveDirectory() Source: {directory}, Target: {target}; " + $"Error: {Lux.IO.Consts.ErrorMessages.ERROR_DIR_NOT_FOUND}"); throw new DirectoryNotFoundException(Lux.IO.Consts.ErrorMessages.ERROR_DIR_NOT_FOUND); } parentDir.MoveSubDirectory(directory, target); var files = directory.Files.ToList(); var directories = directory.Directories.SelectMany(x => x.Value.Directories).ToList(); foreach (var file in files.Select(x => x.Value)) { var targetRelPath = PathHelper.Subtract(file.Path, directory.Path); var targetPath = PathHelper.Combine(target.Path, targetRelPath); directory.MoveFile(file, targetPath, target); } foreach (var dir in directories.Select(x => x.Value)) { var targetRelPath = PathHelper.Subtract(dir.Path, directory.Path); var targetPath = PathHelper.Combine(target.Path, targetRelPath); var targetDir = CreateDirectory(targetPath); MoveDirectory(dir, targetDir); } }
protected internal void AddDirectory(DirectoryMock dir) { _directories.Add(dir.Name, dir); }
public static DirectoryMock Copy(DirectoryMock directory, string targetPath) { var newDir = Create(targetPath); foreach (var dir in directory.Directories.Select(x => x.Value)) { var newSubDirPath = PathHelper.Combine(targetPath, dir.Name); var newSubDir = Copy(dir, newSubDirPath); newDir._directories.Add(newSubDir.Name, newSubDir); } foreach (var file in directory.Files.Select(x => x.Value)) { var newFilePath = PathHelper.Combine(directory.Path, file.Name); var newFile = FileMock.Copy(file, newFilePath); newDir._files.Add(newFile.Name, newFile); } return newDir; }
public static DirectoryMock Create(string path) { var file = new DirectoryMock(path); return file; }