public bool RenameDirectory(int directoryId, string newDirectoryName) { if (!IsValidDirectoryName(newDirectoryName)) { return(false); } StorageDirectory storageDirectory = _directories.FirstOrDefault(d => d.Id == directoryId); if (storageDirectory == null) { return(false); } storageDirectory.DirectoryName = newDirectoryName; if (DirectoryStructureChanged != null) { DirectoryStructureChanged.Invoke(this, new StorageDirectorySystemEventArgs { DirectoryEventType = StorageFileSystemEventTypes.Renamed, DirectoryId = directoryId, ParentDirectoryId = storageDirectory.ParentId }); } return(true); }
private StorageDirectory CreateRooDir() { var root = new StorageDirectory { Id = 0, ParentId = 0, CreateDate = DateTime.Now, DirectoryName = "FSRootDir" }; _directoryIdSet.Add(_nextDirectoryId++); return(root); }
private StorageFileSystem(StorageFileContent storageFileSystemContent) { fileSystemMemoryCache = new MemoryStream(); _directories = storageFileSystemContent.Directories; _files = storageFileSystemContent.Files; _directoryIdSet = storageFileSystemContent.DirectoryIdSet; _fileIdSet = storageFileSystemContent.FileIdSet; _rootDirectory = _directories.First(d => d.Id == 0); _nextFileId = storageFileSystemContent.NextFileId; _nextDirectoryId = storageFileSystemContent.NextDirectoryId; }
private StorageFileSystem() { fileSystemMemoryCache = new MemoryStream(); _directories = new HashSet <StorageDirectory>(); _files = new HashSet <StorageFile>(); _directoryIdSet = new HashSet <int>(); _fileIdSet = new HashSet <int>(); _rootDirectory = CreateRooDir(); _nextFileId = 0; _validDirNameRegex = new Regex(validDirectoryNameRegExp); }
public bool DeleteDirectory(int directoryId) { StorageDirectory storageDirectory = _directories.FirstOrDefault(d => d.Id == directoryId); if (storageDirectory == null) { return(false); } _directories.Remove(storageDirectory); _directoryIdSet.Remove(storageDirectory.Id); DirectoryStructureChanged?.Invoke(this, new StorageDirectorySystemEventArgs { DirectoryEventType = StorageFileSystemEventTypes.Deleted, DirectoryId = directoryId, ParentDirectoryId = storageDirectory.ParentId }); return(true); }
public int CreateFile(StorageDirectory parentDirectory, string fileName) { var storageFile = new StorageFile { CreateDate = DateTime.Now, ModifiedDate = DateTime.Now, Id = _nextFileId++, DirectoryId = parentDirectory.Id, FileName = fileName }; _fileIdSet.Add(storageFile.Id); _files.Add(storageFile); FileStructureChanged?.Invoke(this, new StorageFileSystemEventArgs { DirectoryId = storageFile.DirectoryId, FileId = storageFile.Id, FileEvent = StorageFileSystemEventTypes.Created }); return(storageFile.Id); }
public int CreateDirectory(StorageDirectory parentDirectory, string directoryName) { var storageDirectory = new StorageDirectory { Id = _nextDirectoryId++, ParentId = parentDirectory.Id, DirectoryName = directoryName, CreateDate = DateTime.Now, ModifiedDate = DateTime.Now }; _directories.Add(storageDirectory); _directoryIdSet.Add(storageDirectory.Id); DirectoryStructureChanged?.Invoke(this, new StorageDirectorySystemEventArgs { DirectoryEventType = StorageFileSystemEventTypes.Created, DirectoryId = storageDirectory.Id, ParentDirectoryId = storageDirectory.ParentId }); return(storageDirectory.Id); }