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);
        }
Example #2
0
        private StorageDirectory CreateRooDir()
        {
            var root = new StorageDirectory {
                Id = 0, ParentId = 0, CreateDate = DateTime.Now, DirectoryName = "FSRootDir"
            };

            _directoryIdSet.Add(_nextDirectoryId++);
            return(root);
        }
Example #3
0
 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;
 }
Example #4
0
 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);
 }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }