private void Initialize() { foreach (var item in _study.GetSeries()) { SeriesTreeItem seriesitem = new SeriesTreeItem(item, this); _tree.Items.Add(seriesitem); } }
/// <summary> /// 选择文件的大小 /// </summary> private void selectFilesSize(object sender, DoWorkEventArgs e) { long size = 0; if (Tree != null) { foreach (IStudyTreeItem item in Tree.Items) { StudyTreeItem treeitem = (StudyTreeItem)item; if (!treeitem.Ischecked) { continue; } foreach (ISeriesTreeItem seriss in treeitem.Tree.Items) { SeriesTreeItem seriesitem = (SeriesTreeItem)seriss; if (!seriesitem.Ischecked) { continue; } foreach (var sop in seriesitem.Series.GetSopInstances()) { if (LoadImageWorker.CancellationPending == true) { break; } if (File.Exists(sop.FilePath)) { FileInfo info = new FileInfo(sop.FilePath); size += info.Length; } LoadImageWorker.ReportProgress(0, size); } } } if (MediaWriterSettings.Default.PortablePath != null) { GetFilesSize(MediaWriterSettings.Default.PortablePath, ref size); LoadImageWorker.ReportProgress(0, size); } } }
/// <summary> /// 刻录 /// </summary> private void Writing() { List <IBurnMediaData> data = new List <IBurnMediaData>(); MediaFileSet mediaFileSet = new MediaFileSet(); mediaFileSet.Id = "Gold"; List <MediaFileSetStudy> fileSetStudies = new List <MediaFileSetStudy>(); string RootPath = "CD"; string studysPath = "IMAGES"; string studyitemPath = "Study{0}"; string seriesitemPath = "Series{0}"; string filename = "IM{0}"; string xmlSavePath = "studies"; string XmlName = "Study{0}.xml"; int study = -1; int series = -1; int Sopcount = -1; string studyIndexName = "index.xml"; string xmlPath = Path.Combine(this.StagingFolderPath, xmlSavePath); if (Directory.Exists(xmlPath)) { Directory.Delete(xmlPath, true); } Directory.CreateDirectory(xmlPath); if (MediaWriterSettings.Default.PortablePath == null || !Directory.Exists(MediaWriterSettings.Default.PortablePath)) { this.Host.ShowMessageBox("指定光盘浏览器目录不存在", MessageBoxActions.Ok); return; } FileDirectoryUtility.CopyFiles(MediaWriterSettings.Default.PortablePath, this.StagingFolderPath, true, true); RootPath = Path.Combine(this.StagingFolderPath, studysPath); DicomDirectory dicomDirectory = new DicomDirectory(VolumeName); dicomDirectory.SourceApplicationEntityTitle = VolumeName; dicomDirectory.FileSetId = "File Set Desc"; try { foreach (IStudyTreeItem item in Tree.Items) { StudyTreeItem treeitem = (StudyTreeItem)item; if (!treeitem.Ischecked) { continue; } study++; MediaFileSetStudy fileSet = new MediaFileSetStudy(); string tempstudypath = Path.Combine(RootPath, string.Format(studyitemPath, study)); StudyXml studyXml = new StudyXml(); foreach (ISeriesTreeItem seriss in treeitem.Tree.Items) { SeriesTreeItem seriesitem = (SeriesTreeItem)seriss; if (!seriesitem.Ischecked) { continue; } series++; string tempseriespath = Path.Combine(tempstudypath, string.Format(seriesitemPath, series)); if (Directory.Exists(tempseriespath)) { Directory.Delete(tempseriespath, true); } Directory.CreateDirectory(tempseriespath); foreach (var sop in seriesitem.Series.GetSopInstances()) { if (LoadImageWorker.CancellationPending == true) { break; } if (File.Exists(sop.FilePath)) { Sopcount++; string temp = Path.Combine(tempseriespath, string.Format(filename, Sopcount)); File.Copy(sop.FilePath, temp); int start = temp.IndexOf(studysPath); string dirFilePath = temp.Substring(start); dicomDirectory.AddFile(temp, dirFilePath); string fileName = string.Format("..\\{0}", dirFilePath); DicomFile file = new DicomFile(temp); file.Load(); file.Filename = fileName; studyXml.AddFile(file); fileSet.UID = sop.StudyInstanceUid; } } } //保存studyXml string xmlFileName = string.Format(XmlName, study); string path = Path.Combine(xmlPath, xmlFileName); StudyXmlOutputSettings settings = new StudyXmlOutputSettings(); settings.IncludeSourceFileName = true; XmlDocument document = studyXml.GetMemento(settings); // Create an XML declaration. XmlDeclaration xmldecl; xmldecl = document.CreateXmlDeclaration("1.0", null, null); xmldecl.Encoding = "UTF-8"; document.Save(path); fileSet.Value = Path.Combine(xmlSavePath, xmlFileName);; fileSetStudies.Add(fileSet); } if (!Directory.Exists(RootPath)) { throw new Exception(string.Format("复制检查图像到{0}目录出错", StagingFolderPath)); } IBurnMediaData info = new BurnMediaData(); info.Type = MediaType.Dir; info.Path = RootPath; data.Add(info); IBurnMediaData xml = new BurnMediaData(); xml.Path = xmlPath; xml.Type = MediaType.Dir; data.Add(xml); string studyindexfilename = Path.Combine(this.StagingFolderPath, studyIndexName); if (File.Exists(studyindexfilename)) { File.Delete(studyindexfilename); } Stream stream = File.Open(studyindexfilename, FileMode.Create); mediaFileSet.StudyIndex = fileSetStudies.ToArray(); XmlSerializer serializer = new XmlSerializer(typeof(MediaFileSet)); serializer.Serialize(stream, mediaFileSet); IBurnMediaData studyindex = new BurnMediaData(); studyindex.Path = studyindexfilename; studyindex.Type = MediaType.File; data.Add(studyindex); string dirfilename = Path.Combine(this.StagingFolderPath, "DICOMDIR"); dicomDirectory.Save(dirfilename); info = new BurnMediaData(); info.Type = MediaType.File; info.Path = dirfilename; data.Add(info); DoBurn(data); } catch (COMException ex) { this.Host.ShowMessageBox(ImapiReturnValues.GetName(ex.ErrorCode), MessageBoxActions.Ok); } catch (Exception e) { this.Host.ShowMessageBox(e.Message, MessageBoxActions.Ok); } finally { this.IsWriting = false; } }