Exemple #1
0
        public void AddFile_LongFilename()
        {
            string filename  = "TestPattern_Palette_16.dcm";
            var    dicomFile = DicomFile.Open(TestData.Resolve(filename));

            var dicomDir = new DicomDirectory();

            Assert.True(dicomDir.ValidateItems);
            Assert.Throws <DicomValidationException>(()
                                                     => dicomDir.AddFile(dicomFile, filename));

            dicomDir.AutoValidate = false;
            dicomDir.AddFile(dicomFile, filename);
            Assert.Single(dicomDir.RootDirectoryRecordCollection);
        }
Exemple #2
0
        public void AddFile_AnonymizedSeries_AllFilesAddedToSameStudySeriesNode()
        {
            var dicomFiles = GetDicomFilesFromZip(TestData.Resolve("abd1.zip"));

            // Anonymize all files
            var anonymizer = new DicomAnonymizer();

            foreach (var dicomFile in dicomFiles)
            {
                anonymizer.AnonymizeInPlace(dicomFile);
            }

            // Create DICOM directory
            var dicomDir = new DicomDirectory();

            foreach (var dicomFile in dicomFiles)
            {
                var entry = dicomDir.AddFile(dicomFile);
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.SOPInstanceUID), entry.InstanceRecord.GetSingleValue <string>(DicomTag.ReferencedSOPInstanceUIDInFile));
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.SeriesInstanceUID), entry.SeriesRecord.GetSingleValue <string>(DicomTag.SeriesInstanceUID));
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID), entry.StudyRecord.GetSingleValue <string>(DicomTag.StudyInstanceUID));
            }

            var imageNodes = dicomDir.RootDirectoryRecord.LowerLevelDirectoryRecord.LowerLevelDirectoryRecord
                             .LowerLevelDirectoryRecordCollection;

            Assert.Equal(dicomFiles.Count, imageNodes.Count());
        }
Exemple #3
0
        public void AddFile_AnonymizedSeries_AllFilesAddedToDifferentPatientNodes()
        {
            var dicomFiles = GetDicomFilesFromZip(TestData.Resolve("abd1.zip"));

            // Anonymize all files
            var patname    = "Pat^Name";
            var patname2   = "Pat^^Name^^";
            var patname3   = "PAT Name";
            var patname4   = "Name^Pat";
            var anonymizer = new DicomAnonymizer();

            foreach (var dicomFile in dicomFiles)
            {
                anonymizer.AnonymizeInPlace(dicomFile);
                dicomFile.Dataset.AddOrUpdate(DicomTag.PatientName, patname);
            }
            // the name of the first image is slightly different
            dicomFiles.First().Dataset.AddOrUpdate(DicomTag.PatientName, patname2);
            dicomFiles.ElementAt(1).Dataset.AddOrUpdate(DicomTag.PatientName, patname3);
            dicomFiles.ElementAt(2).Dataset.AddOrUpdate(DicomTag.PatientName, patname4);

            // Create DICOM directory
            var dicomDir = new DicomDirectory();

            foreach (var dicomFile in dicomFiles)
            {
                var entry = dicomDir.AddFile(dicomFile);
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.SOPInstanceUID), entry.InstanceRecord.GetSingleValue <string>(DicomTag.ReferencedSOPInstanceUIDInFile));
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.SeriesInstanceUID), entry.SeriesRecord.GetSingleValue <string>(DicomTag.SeriesInstanceUID));
                Assert.Equal(dicomFile.Dataset.GetSingleValue <string>(DicomTag.StudyInstanceUID), entry.StudyRecord.GetSingleValue <string>(DicomTag.StudyInstanceUID));
            }

            // there shall be only one patient record
            Assert.Equal(4, dicomDir.RootDirectoryRecordCollection.Count());
        }
        public void CreateDicomdirTest()
        {
            DicomFile file = new DicomFile("CreateFileTest.dcm");

            SetupMR(file.DataSet);
            SetupMetaInfo(file);

            DicomDirectory writer    = new DicomDirectory("");
            int            fileCount = 1;

            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 256, 256, 10);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            DicomFile newfile = new DicomFile("test2.dcm");

            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            IList <DicomAttributeCollection> seriesList = SetupMRSeries(2, 2, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                fileCount++;
                SetupMetaInfo(file);

                writer.AddFile(file, String.Format("DIR001\\FILE{0}", fileCount));
            }

            writer.FileSetId = "TestDicomdir";
            writer.Save("DICOMDIR");


            DicomDirectory reader = new DicomDirectory("");

            reader.Load("DICOMDIR");


            string failureReason;

            Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);
        }
Exemple #5
0
        /// <summary>
        /// Scan files and write to <see cref="DicomDirectory"/>.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static DicomDirectory WriteMedia(string path)
        {
            var dirInfo = new DirectoryInfo(path);

            var dicomDir = new DicomDirectory();

            foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var dicomFile = DicomFile.Open(file.FullName);
                dicomDir.AddFile(dicomFile, string.Format(@"00001\{0}", file.Name));
            }
            return(dicomDir);
        }
Exemple #6
0
        public void AddFile_LongFilename_WithGlobalValidationSupression()
        {
            string filename  = "TestPattern_Palette_16.dcm";
            var    dicomFile = DicomFile.Open(TestData.Resolve(filename));

            var dicomDir = new DicomDirectory()
            {
                AutoValidate = false
            };

            Assert.Null(Record.Exception(()
                                         => dicomDir.AddFile(dicomFile, filename)));
            Assert.Single(dicomDir.RootDirectoryRecordCollection);
        }
Exemple #7
0
        static void WriteMedia(string path)
        {
            var dicomDirPath = Path.Combine("D:\\", "DICOMDIR.dcm");
            var dirInfo      = new DirectoryInfo(path);

            var dicomDir = new DicomDirectory();

            foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var dicomFile = DicomFile.Open(file.FullName);
                dicomDir.AddFile(dicomFile, file.FullName);
            }
            dicomDir.Save(dicomDirPath);
        }
        private static void WriteMedia(string path)
        {
            var dicomDirPath = Path.Combine(path, "DICOMDIR");

            var dirInfo = new DirectoryInfo(path);

            var dicomDir = new DicomDirectory();
            foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var dicomFile = DicomFile.Open(file.FullName);

                dicomDir.AddFile(dicomFile, string.Format(@"000001\{0}", file.Name));
            }

            dicomDir.Save(dicomDirPath);
        }
Exemple #9
0
        private static void updateDatabase()
        {
            var    configuration   = new Configuration();
            string fileDestination = configuration.fileDestination;
            string dicomDirPath    = Path.Combine(fileDestination, "DICOMDIR");

            using (var fileStream = new FileStream(dicomDirPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                var dicomDir = new DicomDirectory();
                int i        = 0;
                foreach (string file in Directory.EnumerateFiles(fileDestination, "*.dcm*", SearchOption.AllDirectories))
                {
                    var dicomFile = DicomFile.Open(file);
                    dicomDir.AddFile(dicomFile, i.ToString()); i++;
                }
                dicomDir.Save(fileStream);
            }
        }
Exemple #10
0
        private void CreateDirFile(string fileRootPath)
        {
            var path = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + "\\dicomviewer";

            var dirInfo  = new DirectoryInfo(fileRootPath);
            var dicomDir = new DicomDirectory();

            foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var dicomFile = Dicom.DicomFile.Open(file.FullName);
                if (file.Length > (1024 * 10))
                {
                    dicomDir.AddFile(dicomFile, String.Format(@"DICOMOBJ\{0}", file.Name));
                }
            }

            var dicomDirPath = Path.Combine(path, "DICOMDIR");

            dicomDir.Save(dicomDirPath);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            LogToDebugConsole("Creating Dicom directory...");

            try
            {
                //location where we will create the DICOMDIR file from the images
                var pathToOutputDicomDirectoryFile = Path.Combine(PathToDicomImages, "DICOMDIR");

                if (File.Exists(pathToOutputDicomDirectoryFile))
                {
                    LogToDebugConsole($"Dicom directory file already exists at '{pathToOutputDicomDirectoryFile}'. Deleting...");
                    File.Delete(pathToOutputDicomDirectoryFile);
                }

                var directoryInfoForDicomImagesFolder = new DirectoryInfo(PathToDicomImages);

                var dicomDir = new DicomDirectory();

                foreach (var file in directoryInfoForDicomImagesFolder.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var dicomFile = Dicom.DicomFile.Open(file.FullName);

                    dicomDir.AddFile(dicomFile, $@"000001\{file.Name}");
                }

                dicomDir.Save(pathToOutputDicomDirectoryFile);

                LogToDebugConsole($"Dicom directory creation was successful. DICOMDIR file created at '{pathToOutputDicomDirectoryFile}'");

                var dicomDirectory = DicomDirectory.Open(pathToOutputDicomDirectoryFile);

                LogToDebugConsole("Outputing the newly created DICOM directory information to console");

                LogToDebugConsole(dicomDirectory.WriteToString());
            }
            catch (Exception ex)
            {
                LogToDebugConsole($"Error occured during Dicom directory dump. Error:{ex.Message}");
            }
        }
Exemple #12
0
        public void AddFile_InvalidUIDInExistingFileShouldNotThrow()
        {
            // first create a file with invalid UIDs
            string filename  = "TestPattern_Palette_16.dcm";
            var    dicomFile = DicomFile.Open(TestData.Resolve(filename));

            var invalidDs = dicomFile.Dataset.NotValidated();

            invalidDs.AddOrUpdate(DicomTag.SOPInstanceUID, "1.2.4.100000.94849.4239.32.00121");
            invalidDs.AddOrUpdate(DicomTag.SeriesInstanceUID, "1.2.4.100000.94849.4239.32.00122");
            invalidDs.AddOrUpdate(DicomTag.StudyInstanceUID, "1.2.4.100000.94849.4239.32.00123");

            var invalidFile = new DicomFile(invalidDs);

            var ex = Record.Exception(() =>
            {
                var dicomDir = new DicomDirectory();
                dicomDir.AddFile(invalidFile, "FILE1");
            });

            Assert.Null(ex);
        }
        /// <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;
            }
        }
		public void CreateDicomdirTest()
		{
			DicomFile file = new DicomFile("CreateFileTest.dcm");

			SetupMR(file.DataSet);
			SetupMetaInfo(file);

			DicomDirectory writer = new DicomDirectory("");
			int fileCount = 1;

			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 256, 256, 10);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			DicomFile newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			IList<DicomAttributeCollection> seriesList = SetupMRSeries(2, 2, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				fileCount++;
				SetupMetaInfo(file);

				writer.AddFile(file, String.Format("DIR001\\FILE{0}", fileCount));
			}

			writer.FileSetId = "TestDicomdir";
			writer.Save("DICOMDIR");


			DicomDirectory reader = new DicomDirectory("");

			reader.Load("DICOMDIR");


			string failureReason;
			Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);
		}
		public void ComparisonTest()
		{
			DicomDirectory writer = new DicomDirectory("DICOMDIR");

			int fileCount = 1;

			DicomFile file = new DicomFile("CreateFileTest.dcm");
			SetupMR(file.DataSet);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateFileTest.dcm");
			SetupMR(file.DataSet);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			DicomFile newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 128, 128, 4);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));


			file = new DicomFile("CreateXaFileTest.dcm");
			SetupMultiframeXA(file.DataSet, 64, 64, 4);
			SetupMetaInfo(file);
			writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

			newfile = new DicomFile("test2.dcm");
			SetupKoForImage(newfile.DataSet, file.DataSet);
			SetupMetaInfo(newfile);
			writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

			IList<DicomAttributeCollection> seriesList = SetupMRSeries(3, 1, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(10, 1, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			seriesList = SetupMRSeries(4, 3, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			writer.FileSetId = "TestDicomdir";
			writer.Save("DICOMDIR");


			DicomDirectory reader = new DicomDirectory("DICOMDIR");
			reader.Load("DICOMDIR");


			string failureReason;
			Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);

			// Test Append
			// Add a few more files to the file read in, then rewrite and read and compare
			seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
			foreach (DicomAttributeCollection collection in seriesList)
			{
				file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
				SetupMetaInfo(file);
				reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

				file = new DicomFile("test2.dcm");
				SetupKoForImage(file.DataSet, collection);
				SetupMetaInfo(file);
				reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
			}

			reader.FileSetId = "TestDicomdir";
			reader.Save("DICOMDIR");


			DicomDirectory reader2 = new DicomDirectory("DICOMDIR");
			reader2.Load("DICOMDIR");


			Assert.IsTrue(Compare(reader.RootDirectoryRecord, reader2.RootDirectoryRecord, out failureReason), failureReason);
		}
        public void ComparisonTest()
        {
            DicomDirectory writer = new DicomDirectory("DICOMDIR");

            int fileCount = 1;

            DicomFile file = new DicomFile("CreateFileTest.dcm");

            SetupMR(file.DataSet);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateFileTest.dcm");
            SetupMR(file.DataSet);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            DicomFile newfile = new DicomFile("test2.dcm");

            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 128, 128, 4);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            newfile = new DicomFile("test2.dcm");
            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));


            file = new DicomFile("CreateXaFileTest.dcm");
            SetupMultiframeXA(file.DataSet, 64, 64, 4);
            SetupMetaInfo(file);
            writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

            newfile = new DicomFile("test2.dcm");
            SetupKoForImage(newfile.DataSet, file.DataSet);
            SetupMetaInfo(newfile);
            writer.AddFile(newfile, String.Format("DICOM\\FILE{0}", fileCount++));

            IList <DicomAttributeCollection> seriesList = SetupMRSeries(3, 1, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(10, 1, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            seriesList = SetupMRSeries(4, 3, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                writer.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            writer.FileSetId = "TestDicomdir";
            writer.Save("DICOMDIR");


            DicomDirectory reader = new DicomDirectory("DICOMDIR");

            reader.Load("DICOMDIR");


            string failureReason;

            Assert.IsTrue(Compare(writer.RootDirectoryRecord, reader.RootDirectoryRecord, out failureReason), failureReason);

            // Test Append
            // Add a few more files to the file read in, then rewrite and read and compare
            seriesList = SetupMRSeries(4, 4, DicomUid.GenerateUid().UID);
            foreach (DicomAttributeCollection collection in seriesList)
            {
                file = new DicomFile("test.dcm", new DicomAttributeCollection(), collection);
                SetupMetaInfo(file);
                reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));

                file = new DicomFile("test2.dcm");
                SetupKoForImage(file.DataSet, collection);
                SetupMetaInfo(file);
                reader.AddFile(file, String.Format("DICOM\\FILE{0}", fileCount++));
            }

            reader.FileSetId = "TestDicomdir";
            reader.Save("DICOMDIR");


            DicomDirectory reader2 = new DicomDirectory("DICOMDIR");

            reader2.Load("DICOMDIR");


            Assert.IsTrue(Compare(reader.RootDirectoryRecord, reader2.RootDirectoryRecord, out failureReason), failureReason);
        }