private FileSystemCommandResult WriteCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject write_file = CurrentDirectory.GetRelativeFileSystemObject(path); if (write_file is File) { if (((File)write_file).Write(GetContentArgument(arguments))) { ret = new FileSystemCommandResult(EFileSystemStatusCode.WrittenFileContents, write_file.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedWritingFileContents, write_file.FullPath); } } else if (write_file != null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsFileMissing, write_file.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsFileMissing, path); } } return(ret); }
public FilesDirectoryPath(string name, IFileSystemObject parentDirectory, string filesStorage) : base(name, parentDirectory) { if (filesStorage != null) { // TODO } }
private FileSystemCommandResult ChangeDirectoryCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject result_file_system_object = CurrentDirectory.GetRelativeFileSystemObject(path); if (result_file_system_object is Directory) { CurrentDirectory = (Directory)result_file_system_object; ret = new FileSystemCommandResult(EFileSystemStatusCode.ChangedDirectory, result_file_system_object.FullPath); } else if (result_file_system_object != null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedChangingDirectory, result_file_system_object.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedChangingDirectory, path); } } return(ret); }
private FileSystemCommandResult ReadCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject read_file = CurrentDirectory.GetRelativeFileSystemObject(path); if (read_file is File) { Me.CustomData = ((File)read_file).Read(); standardOutputLogger.AppendLine("Read file \"" + read_file.FullPath + "\"."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } else if (read_file != null) { Me.CustomData = string.Empty; path = read_file.FullPath; errorOutputLogger.AppendLine("\"" + read_file.FullPath + "\" is not a file."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } else { Me.CustomData = string.Empty; errorOutputLogger.AppendLine("\"" + path + "\" does not exist."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } } return(ret); }
private bool Matches(IFileSystemObject obj, IExecutionContext context) { var result = FileSystemPath.Compare(obj.Path, _path, StringComparison.OrdinalIgnoreCase); return(result == FileSystemPath.ComparisonResult.YSubsetOfX || result == FileSystemPath.ComparisonResult.Equal); }
public void GetObjects_MultiRoot() { var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer)); var context = new ExecutionContext(serviceContainer); var fileSystem = new MockFileSystem(); fileSystem.RegisterFile(@"C:\file1"); fileSystem.RegisterFile(@"C:\file2"); var root1 = new FileRoot(@"C:\file1", fileSystem); var root2 = new FileRoot(@"C:\file2", fileSystem); var roots = new IFileSystemRoot[] { root1, root2 }; var objectProvider = new FileSystemObjectProvider(roots, null, null); var result = objectProvider.GetObjects(context).ToArray(); var expected = new IFileSystemObject[] { new FileObject(@"C:\file1", fileSystem), new FileObject(@"C:\file2", fileSystem) }; CollectionAssert.AreEqual(expected, result); }
public void GetObjects() { var fileSystem = new MockFileSystem(); fileSystem.RegisterDirectory(@"C:\dir"); fileSystem.RegisterDirectory(@"C:\dir\dir1"); fileSystem.RegisterDirectory(@"C:\dir\dir2"); fileSystem.RegisterFile(@"C:\dir\file1"); fileSystem.RegisterFile(@"C:\dir\file2"); var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <IFileSystem>(fileSystem); var executionContext = new ExecutionContext(serviceContainer); var directoryContainer = new DirectoryContainer(@"C:\dir"); var directoryContainerInstance = directoryContainer.CreateInstance(executionContext); var syncContext = new SyncContext(null, executionContext); var result = directoryContainerInstance.GetObjects(syncContext).ToArray(); var expected = new IFileSystemObject[] { new FileObject(@"C:\dir\file1", fileSystem), new FileObject(@"C:\dir\file2", fileSystem), new DirectoryObject(@"C:\dir\dir1", fileSystem), new DirectoryObject(@"C:\dir\dir2", fileSystem) }; CollectionAssert.AreEqual(expected, result); }
private ImageSource ReadFromDisk(IFileSystemObject fileSystemObject) { ImageSource bitmap = null; //lock (locker) { #if DISPLAY_DEBUG System.Diagnostics.Debug.WriteLine("Cache read from disk " + fileSystemObject.Name); #endif if (fileSystemObject is IDirectoryObject) { bitmap = _Converter.GetImage(fileSystemObject.FullName); } else if (ImageDirectory.IsImage(fileSystemObject as IFileObject)) { using (var stream = (fileSystemObject as IFileObject).OpenRead()) { bitmap = GetBitmap(stream); } } else { bitmap = _Converter.GetImage(fileSystemObject.FullName); } bitmap.Freeze(); } return bitmap; }
public void GetObjects_SingleRoot_TrueInclude_NoExclude() { var serviceContainer = new ManualServiceContainer(); serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer)); var context = new ExecutionContext(serviceContainer); var fileSystem = new MockFileSystem(); fileSystem.RegisterFile(@"C:\file1"); var root = new FileRoot(@"C:\file1", fileSystem); var include = new IRule[] { new TrueRule() }; var objectProvider = new FileSystemObjectProvider(root, include, null); var result = objectProvider.GetObjects(context).ToArray(); var expected = new IFileSystemObject[] { new FileObject(@"C:\file1", fileSystem), }; CollectionAssert.AreEqual(expected, result); }
private ImageSource ReadFromDisk(IFileSystemObject fileSystemObject) { ImageSource bitmap = null; //lock (locker) { #if DISPLAY_DEBUG System.Diagnostics.Debug.WriteLine("Cache read from disk " + fileSystemObject.Name); #endif if (fileSystemObject is IDirectoryObject) { bitmap = _Converter.GetImage(fileSystemObject.FullName); } else if (ImageDirectory.IsImage(fileSystemObject as IFileObject)) { using (var stream = (fileSystemObject as IFileObject).OpenRead()) { bitmap = GetBitmap(stream); } } else { bitmap = _Converter.GetImage(fileSystemObject.FullName); } bitmap.Freeze(); } return(bitmap); }
public FileService(IFileSystemObject fs) { if (fs is null) { throw new ArgumentNullException("Передан null"); } _fs = fs; }
internal FileInfo(String fullPath, IFileSystemObject fileSystemObject) : base(fileSystemObject) { Debug.Assert(Path.IsPathRooted(fullPath), "fullPath must be fully qualified!"); _name = Path.GetFileName(fullPath); OriginalPath = _name; FullPath = fullPath; DisplayPath = _name; }
public override void SetLastWriteTime(string fullPath, DateTimeOffset time, bool asDirectory) { IFileSystemObject info = asDirectory ? (IFileSystemObject) new DirectoryInfo(fullPath, null) : (IFileSystemObject) new FileInfo(fullPath, null); info.LastWriteTime = time; }
internal FileInfo(String fullPath, IFileSystemObject fileSystemObject) : base(fileSystemObject) { Debug.Assert(Path.IsPathRooted(fullPath), "fullPath must be fully qualified!"); _name = Path.GetFileName(fullPath); OriginalPath = _name; FullPath = fullPath; DisplayPath = _name; }
private void AddToCache(IFileSystemObject fileSystemObject, ImageSource bitmap) { #if DISPLAY_DEBUG System.Diagnostics.Debug.WriteLine("Cache add: " + fileSystemObject.FullName); #endif _cache.Add(new CacheItem(fileSystemObject.FullName, bitmap), new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromMinutes(10) }); }
internal DirectoryInfo(String fullPath, IFileSystemObject fileSystemObject) : base(fileSystemObject) { Debug.Assert(PathInternal.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; DisplayPath = GetDisplayName(OriginalPath, FullPath); }
public CommandsDirectoryFileSystemObject(string name, IFileSystemObject parentFileSystemObject) : base(name, parentFileSystemObject) { children = new Dictionary <string, IFileSystemObject> { { "list", new CommandFileSystemObject("list", this, ListCommand) }, { "ls", new CommandFileSystemObject("ls", this, ListCommand) }, { "dir", new CommandFileSystemObject("dir", this, ListCommand) } }; }
public AFileSystemObject(string name, IFileSystemObject parent) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Parent = parent; }
internal DirectoryInfo(String fullPath, IFileSystemObject fileSystemObject) : base(fileSystemObject) { Debug.Assert(PathHelpers.GetRootLength(fullPath) > 0, "fullPath must be fully qualified!"); // Fast path when we know a DirectoryInfo exists. OriginalPath = Path.GetFileName(fullPath); FullPath = fullPath; DisplayPath = GetDisplayName(OriginalPath, FullPath); }
public static IFileSystemObject TraversePath(IFileSystemObject beginFileSystemObject, string path, TraversePathDelegate onTraversePath) { if (beginFileSystemObject == null) { throw new ArgumentNullException(nameof(beginFileSystemObject)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } if (path.Contains("|")) { throw new ArgumentException("Illegal path character \"|\"", nameof(path)); } IFileSystemObject ret = beginFileSystemObject; string[] path_parts = path.Split('/'); bool traverse_to_root_directory = ((path_parts.Length > 0) ? string.IsNullOrEmpty(path_parts[0].Trim()) : false); foreach (string path_part in path_parts) { string trimmed_path_part = path_part.Trim(); if ((onTraversePath == null) ? true : onTraversePath.Invoke(ret, trimmed_path_part)) { if (traverse_to_root_directory) { traverse_to_root_directory = false; while (ret.Parent != null) { ret = ret.Parent; } } else { switch (trimmed_path_part) { case ".": break; case "..": ret = ret.Parent; break; default: ret = (ret.Children.ContainsKey(trimmed_path_part) ? ret.Children[trimmed_path_part] : null); break; } } if (ret == null) { break; } } } return(ret); }
private void SetSelectedItemInList(IFileSystemObject fileSystemObject) { var itemToSelect = DataContext.Contents.FirstOrDefault(c => c.SystemObject.Name == fileSystemObject.Name); if (itemToSelect == null) { return; } DataContext.SetSelected(itemToSelect); }
private void AddToCache(IFileSystemObject fileSystemObject, ImageSource bitmap) { #if DISPLAY_DEBUG System.Diagnostics.Debug.WriteLine("Cache add: " + fileSystemObject.FullName); #endif _cache.Add(new CacheItem(fileSystemObject.FullName, bitmap), new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromMinutes(10) }); }
public IFileSystemObject GetPath(string path) { IFileSystemObject ret = CurrentDirectoryPath; if (path != null) { string trimmed_path = path.Trim(); if (trimmed_path.Length > 0) { if (trimmed_path[0] == '/') { ret = RootDirectory; } } string[] parts = trimmed_path.Split('/'); if (parts != null) { foreach (string part in parts) { switch (part) { case ".": break; case "..": ret = ret.ParentFileSystemObject; break; default: if (ret.Children.ContainsKey(part)) { ret = ret.Children[part]; } else { ret = null; } break; } if (ret == null) { break; } } } else { ret = CurrentDirectoryPath; } } return(ret); }
public IFileSystemObject ChangeDirectory(string path) { IFileSystemObject ret = GetPath(path); if (ret != null) { if (ret.IsDirectory) { CurrentDirectoryPath = ret; } } return(ret); }
public void GetIconImageAsync(IFileSystemObject fileSystemObject, Action <ImageSource> returnAction) { lock (lockObject) { ActionQueue.Enqueue(new ActionQueueItem() { FileSystemObject = fileSystemObject, ReturnAction = returnAction } ); } RunQueue(); }
public void GetObjects_NoDrives() { var fileSystem = new MockFileSystem(); var root = new AllDrivesRoot(fileSystem); var result = root.GetObjects(null).ToArray(); var expected = new IFileSystemObject[] { }; CollectionAssert.AreEqual(expected, result); }
public DateTime GetCreationTimeUtc(IFileSystemObject obj) { if (obj is IFileObject) { return(GetFileCreationTimeUtc((IFileObject)obj)); } if (obj is IDirectoryObject) { return(GetDirectoryCreationTimeUtc((IDirectoryObject)obj)); } throw new NotSupportedException(); }
public DateTime GetLastAccessTimeUtc(IFileSystemObject obj) { if (obj is IFileObject) { return(GetLastFileAccessTimeUtc((IFileObject)obj)); } if (obj is IDirectoryObject) { return(GetLastDirectoryAccessTimeUtc((IDirectoryObject)obj)); } throw new NotSupportedException(); }
public FileAttributes GetAttributes(IFileSystemObject obj) { if (obj is IFileObject) { return(GetFileAttributes((IFileObject)obj)); } if (obj is IDirectoryObject) { return(GetDirectoryAttributes((IDirectoryObject)obj)); } throw new NotSupportedException(); }
private MainWindowFile CreateNewFile(IFileSystemObject fileSystemObject) { MainWindowFile file = new MainWindowFile(fileSystemObject, IconCache); file.PropertyChanged += (sender, eventArgs) => { if (eventArgs.PropertyName == "Selected") { _SelectedFile = sender as MainWindowFile; NotifyPropertyChanged("SelectedFile"); } }; return(file); }
public override bool Delete(string path) { bool ret = false; IFileSystemObject delete_file_system_object = GetRelativeFileSystemObject(path); if (delete_file_system_object != null) { delete_file_system_object.Clear(); if (delete_file_system_object.Parent is Directory) { ret = ((Directory)(delete_file_system_object.Parent)).children.Remove(delete_file_system_object.Name); } } return(ret); }
private void EnsureParent(IFileSystemObject parent) { if (parent == null) return; if (Exists(parent)) return; EnsureParent(parent.Parent); if (parent is DriveObject) RegisterDrive(parent.Path); else if (parent is DirectoryObject) RegisterDirectory(parent.Path); }
public void Rename(IFileSystemObject obj, string newName) { if (obj is IFileObject) { RenameFile((IFileObject)obj, newName); } else if (obj is IDirectoryObject) { RenameDirectory((IDirectoryObject)obj, newName); } else { throw new NotSupportedException(); } }
public void Delete(IFileSystemObject obj) { if (obj is IFileObject) { DeleteFile((IFileObject)obj); } else if (obj is IDirectoryObject) { DeleteDirectory((IDirectoryObject)obj); } else { throw new NotSupportedException(); } }
public ImageSource GetIconImage(IFileSystemObject fileSystemObject) { if (_cache[fileSystemObject.FullName] != null) { #if DISPLAY_DEBUG System.Diagnostics.Debug.WriteLine("Cache HIT: " + fileSystemObject.FullName); #endif return _cache[fileSystemObject.FullName] as ImageSource; } ImageSource bitmap = ReadFromDisk(fileSystemObject); AddToCache(fileSystemObject, bitmap); return bitmap; }
public virtual bool IsAncestorOf(IFileSystemObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } //Check our children collection, recursively foreach (IFileSystemObject fso in Children) { if (fso == obj) { return true; } else if (fso is IFolder) { //This is a child folder; see if it contains obj somewhere if (((IFolder)fso).IsAncestorOf(obj)) { return true; } } } //Not an ancestor of obj return false; }
internal FileSystemInfo(IFileSystemObject fileSystemObject) { _fileSystemObject = fileSystemObject; }
private MainWindowFile CreateNewFile(IFileSystemObject fileSystemObject) { MainWindowFile file = new MainWindowFile(fileSystemObject, IconCache); file.PropertyChanged += (sender, eventArgs) => { if (eventArgs.PropertyName == "Selected") { _SelectedFile = sender as MainWindowFile; NotifyPropertyChanged("SelectedFile"); } }; return file; }
internal void Invalidate() { _fileSystemObject = null; }
private void SetSelectedItemInList(IFileSystemObject fileSystemObject) { var itemToSelect = DataContext.Contents.FirstOrDefault(c => c.SystemObject.Name == fileSystemObject.Name); if (itemToSelect == null) return; DataContext.SetSelected(itemToSelect); }
internal void Invalidate() { _dataInitialized = -1; _fileSystemObject = null; }
public MainWindowFile(IFileSystemObject fileSystemObject, IconCacheQueue iconCacheQueue) { _FileSystemObject = fileSystemObject; _IconCache = iconCacheQueue; }
public void GetIconImageAsync(IFileSystemObject fileSystemObject, Action<ImageSource> returnAction) { lock (lockObject) { ActionQueue.Enqueue(new ActionQueueItem() { FileSystemObject = fileSystemObject, ReturnAction = returnAction } ); } RunQueue(); }