/// <summary> /// Creates an object representation of a bcf zip file. /// </summary> /// <param name="BCFZipData">A Stream of bytes representing a bcf .zip file</param> /// <returns>A new BCF object</returns> public static BCF Deserialize(Stream BCFZipData) { BCF bcf = new BCF(); Topic currentTopic = null; Guid currentGuid = Guid.Empty; ZipArchive archive = new ZipArchive(BCFZipData); foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith(".bcfp", StringComparison.OrdinalIgnoreCase)) { bcf.Project = new ProjectXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".version", StringComparison.OrdinalIgnoreCase)) { bcf.Version = new VersionXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } currentTopic.Markup = new MarkupXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".bcfv", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } currentTopic.Visualization = new VisualizationXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } using (MemoryStream ms = new MemoryStream()) { entry.Open().CopyTo(ms); currentTopic.Snapshots.Add(new KeyValuePair<string, byte[]>(entry.FullName, ms.ToArray())); } } } if (currentTopic != null) { bcf.Topics.Add(currentTopic); } return bcf; }
/// <summary> /// Creates an object representation of a bcf zip file. /// </summary> /// <param name="BCFZipData">A Stream of bytes representing a bcf .zip file</param> /// <returns>A new BCF object</returns> public static BCF Deserialize(Stream BCFZipData) { BCF bcf = new BCF(); Topic currentTopic = null; Guid currentGuid = Guid.Empty; ZipArchive archive = new ZipArchive(BCFZipData); foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith(".bcfp", StringComparison.OrdinalIgnoreCase)) { bcf.Project = new ProjectXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".version", StringComparison.OrdinalIgnoreCase)) { bcf.Version = new VersionXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } currentTopic.Markup = new MarkupXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".bcfv", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } currentTopic.Vizualization = new VisualizationXMLFile(XDocument.Load(entry.Open())); } else if (entry.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { if (entry.ExtractGuidFolderName() != currentGuid) { if (currentTopic != null) { bcf.Topics.Add(currentTopic); } currentGuid = entry.ExtractGuidFolderName(); currentTopic = new Topic(); } using (MemoryStream ms = new MemoryStream()) { entry.Open().CopyTo(ms); currentTopic.Snapshots.Add(new KeyValuePair <string, byte[]>(entry.FullName, ms.ToArray())); } } } if (currentTopic != null) { bcf.Topics.Add(currentTopic); } return(bcf); }