public static MetadataNode Load(BlobStore blobs, byte[] hash, MetadataNode?parent = null) { var curmn = new MetadataNode(); Dictionary <string, byte[]> savedobjects = BinaryEncoding.dict_decode(blobs.RetrieveData(hash)); FileMetadata dirmetadata = FileMetadata.deserialize(savedobjects["DirMetadata-v1"]); curmn.DirMetadata = dirmetadata; ConcurrentDictionary <string, FileMetadata> files = new ConcurrentDictionary <string, FileMetadata>(); var encodedFiles = BinaryEncoding.enum_decode(savedobjects["Files-v1"]) ?? new List <byte[]?>(); foreach (var binfm in encodedFiles) { if (binfm == null) { throw new NullReferenceException("Encoded file metadatas cannot be null"); } FileMetadata newfm = FileMetadata.deserialize(binfm); files[newfm.FileName] = newfm; } curmn.Files = files; ConcurrentDictionary <string, MetadataNode> directories = new ConcurrentDictionary <string, MetadataNode>(); var dirs = BinaryEncoding.enum_decode(savedobjects["Directories-v2"]) ?? new List <byte[]?>(); for (int i = 0; i < dirs.Count; i++) { var dir = dirs[i] ?? throw new NullReferenceException("Encoded directory cannot be null"); MetadataNode newmn = Load(blobs, dir, curmn); directories[newmn.DirMetadata.FileName] = newmn; } curmn.Parent = parent; curmn.Directories = directories; return(curmn); }
public static MetadataNode Load(BlobStore blobs, byte[] hash, MetadataNode parent = null) { var curmn = new MetadataNode(); Dictionary <string, byte[]> savedobjects = BinaryEncoding.dict_decode(blobs.RetrieveData(hash)); FileMetadata dirmetadata = FileMetadata.deserialize(savedobjects["DirMetadata-v1"]); curmn.DirMetadata = dirmetadata; ConcurrentDictionary <string, FileMetadata> files = new ConcurrentDictionary <string, FileMetadata>(); foreach (var binfm in BinaryEncoding.enum_decode(savedobjects["Files-v1"])) { FileMetadata newfm = FileMetadata.deserialize(binfm); files[newfm.FileName] = newfm; } curmn.Files = files; ConcurrentDictionary <string, MetadataNode> directories = new ConcurrentDictionary <string, MetadataNode>(); var dirs = BinaryEncoding.enum_decode(savedobjects["Directories-v2"]); for (int i = 0; i < dirs.Count; i++) { MetadataNode newmn = Load(blobs, dirs[i], curmn); directories[newmn.DirMetadata.FileName] = newmn; } curmn.Parent = parent; curmn.Directories = directories; return(curmn); }