Esempio n. 1
0
        public void SaveToFile(string directoryPath)
        {
            FileStream fs = null;

            try
            {
                fs = File.OpenWrite(directoryPath + "\\" + fsStructureFileName);
                var binaryFormatter   = new BinaryFormatter();
                var fileSystemContent = new StorageFileContent
                {
                    Directories     = _directories,
                    DirectoryIdSet  = _directoryIdSet,
                    FileIdSet       = _fileIdSet,
                    Files           = _files,
                    NextDirectoryId = _nextDirectoryId,
                    NextFileId      = _nextFileId
                };

                binaryFormatter.Serialize(fs, fileSystemContent);
                fs.Flush();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception in SaveToFile() + {Message}", ex.Message);
            }
            finally
            {
                fs?.Close();
            }
        }
Esempio n. 2
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;
 }