public bool WriteBCF(BCFComponent bcfComponent) { bool result = false; try { string guidFolder = bcfComponent.DirectoryPath; if (Directory.Exists(guidFolder)) { string markupPath = Path.Combine(guidFolder, "markup.bcf"); string imagePath = Path.Combine(guidFolder, "snapshot.png"); string viewPath = Path.Combine(guidFolder, "viewpoint.bcfv"); string colorPath = Path.Combine(guidFolder, "colorscheme.xml"); bool markupResult = WriteMarkup(markupPath, bcfComponent.Markup); bool viewResult = WriteVisualizationInfo(viewPath, bcfComponent.VisualizationInfo); bool colorResult = WriteColorSchemeInfo(colorPath, bcfComponent.ColorSchemeInfo); result = true; } } catch (Exception ex) { MessageBox.Show("Failed to write bcf.\n" + ex.Message, "Write BCF", MessageBoxButton.OK, MessageBoxImage.Warning); result = false; } return(result); }
public BCFComponent CreateBCF(string bcfPath) { BCFComponent bcfComponent = new BCFComponent(); try { string[] directories = bcfPath.Split(Path.DirectorySeparatorChar); string tempBcfPath = ""; string tempZipPath = ""; string tempZipFolder = ""; FindFilePaths(bcfPath, out tempBcfPath, out tempZipPath, out tempZipFolder); if (!Directory.Exists(tempZipFolder)) { Directory.CreateDirectory(tempZipFolder); } bcfComponent.Markup = WriteDefaultMarkup(); string guidFolder = Path.Combine(tempZipFolder, bcfComponent.Markup.Topic.Guid); if (!Directory.Exists(guidFolder)) { Directory.CreateDirectory(guidFolder); } bcfComponent.DirectoryPath = guidFolder; } catch (Exception ex) { MessageBox.Show("Failed to create BCF.\n" + ex.Message, "Create BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } return(bcfComponent); }
public BCFZIP ReadBCF(string bcfPath) { BCFZIP bcfZip = new BCFZIP(); try { string tempBcfPath = ""; string tempZipPath = ""; string tempZipFolder = ""; FindFilePaths(bcfPath, out tempBcfPath, out tempZipPath, out tempZipFolder); bcfZip.FileName = bcfPath; byte[] buf; using (FileStream fileStream = new FileStream(bcfPath, FileMode.Open)) { buf = new byte[fileStream.Length]; fileStream.Read(buf, 0, buf.Length); fileStream.Close(); } if (File.Exists(tempBcfPath)) { File.Delete(tempBcfPath); } if (null != buf) { using (FileStream fileStream = new FileStream(tempBcfPath, FileMode.OpenOrCreate)) { fileStream.Write(buf, 0, buf.Length); fileStream.Close(); } } if (File.Exists(tempZipPath)) { File.Delete(tempZipPath); } File.Move(tempBcfPath, tempZipPath); if (Directory.Exists(tempZipFolder)) { Directory.Delete(tempZipFolder, true); } if (DecompressFiles(tempZipPath, tempZipFolder)) { string[] directories = Directory.GetDirectories(tempZipFolder); if (directories.Length > 0) { BCFComponent[] bcfComponents = new BCFComponent[directories.Length]; for (int i = 0; i < directories.Length; i++) { DirectoryInfo directoryInfo = new DirectoryInfo(directories[i]); string guidFolder = directoryInfo.FullName; string markupPath = Path.Combine(guidFolder, "markup.bcf"); string imagePath = Path.Combine(guidFolder, "snapshot.png"); string viewPath = Path.Combine(guidFolder, "viewpoint.bcfv"); string colorPath = Path.Combine(guidFolder, "colorscheme.xml"); BCFComponent bcfComponent = new BCFComponent(); bool isReadable = false; bcfComponent.DirectoryPath = guidFolder; bcfComponent.GUID = directoryInfo.Name; bcfComponent.Markup = ReadMarkup(markupPath, out isReadable); bcfComponent.Snapshot = ReadSnapshot(imagePath, out isReadable); bcfComponent.VisualizationInfo = ReadVisualizationInfo(viewPath, out isReadable); bcfComponent.ColorSchemeInfo = ReadColorSchemeInfo(colorPath, out isReadable); bcfComponents[i] = bcfComponent; } bcfZip.BCFComponents = bcfComponents; } } } catch (Exception ex) { MessageBox.Show("Failed to read BCF.\n" + ex.Message, "Read BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } return(bcfZip); }