当前位置: 首页>>代码示例>>C#>>正文


C# StudyXml.AddFile方法代码示例

本文整理汇总了C#中StudyXml.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# StudyXml.AddFile方法的具体用法?C# StudyXml.AddFile怎么用?C# StudyXml.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StudyXml的用法示例。


在下文中一共展示了StudyXml.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTestStudy1

        protected Study CreateTestStudy1()
        {
            var studyUid = "1.2.3";
            var sops = base.SetupMRSeries(4, 5, studyUid);
            var xml = new StudyXml(studyUid);

            var seriesUids = new Dictionary<string, string>();
            var seriesModalities = new Dictionary<string, string>();
            var modalities = new[] { "MR", "MR", "SC", "KO" };

            foreach (var sop in sops)
            {
                //Make the UIDs constant.
                var seriesUid = sop[DicomTags.SeriesInstanceUid].ToString();
                if (!seriesUids.ContainsKey(seriesUid))
                {
                    seriesModalities[seriesUid] = modalities[seriesUids.Count];
                    seriesUids[seriesUid] = string.Format("1.2.3.{0}", seriesUids.Count + 1);
                }

                var modality = seriesModalities[seriesUid];
                seriesUid = seriesUids[seriesUid];

                sop[DicomTags.SeriesInstanceUid].SetString(0, seriesUid);
                sop[DicomTags.Modality].SetString(0, modality);

                var file = new DicomFile("", new DicomAttributeCollection(), sop);
                xml.AddFile(file);
            }

            var study = new Study();
            study.Update(xml);
            return study;
        }
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:34,代码来源:TestBase.cs

示例2: TestSopClass

		public void TestSopClass()
		{
			List<DicomFile> images = SetupImages(4);

			string seriesUid = images[0].DataSet[DicomTags.SeriesInstanceUid].ToString();

			images[0].MediaStorageSopClassUid = SopClass.EnhancedCtImageStorageUid;
			images[1].MediaStorageSopClassUid = SopClass.EnhancedMrImageStorageUid;
			images[2].MediaStorageSopClassUid = SopClass.EnhancedSrStorageUid;
			images[3].MediaStorageSopClassUid = SopClass.EnhancedXaImageStorageUid;
		
			StudyXml xml = new StudyXml();
			foreach (DicomFile file in images)
				xml.AddFile(file);
	
			XmlDocument doc = xml.GetMemento(new StudyXmlOutputSettings());

			Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedCtImageStorageUid);
			Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedMrImageStorageUid);
			Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedSrStorageUid);
			Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedXaImageStorageUid);

			xml = new StudyXml();
			xml.SetMemento(doc);

			Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedCtImageStorageUid);
			Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedMrImageStorageUid);
			Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedSrStorageUid);
			Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedXaImageStorageUid);
		}
开发者ID:khaha2210,项目名称:radio,代码行数:30,代码来源:StudyXmlTests.cs

示例3: Create

		public void Create()
		{
			
			SelectFolderDialogCreationArgs args = new SelectFolderDialogCreationArgs();
			args.Path = _lastFolder ?? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

			FileDialogResult result = base.Context.DesktopWindow.ShowSelectFolderDialogBox(args);
			if (result.Action == DialogBoxAction.Ok)
			{
				_lastFolder = result.FileName;

				StudyLoaderExtensionPoint xp = new StudyLoaderExtensionPoint();
				IStudyLoader loader = (IStudyLoader)CollectionUtils.SelectFirst(xp.CreateExtensions(),
					delegate(object extension) { return ((IStudyLoader) extension).Name == "DICOM_LOCAL";});

				var selected = base.Context.SelectedStudy;

				loader.Start(new StudyLoaderArgs(selected.StudyInstanceUid, selected.Server, null));
				StudyXml xml = new StudyXml();
				Sop sop;
				
				while (null != (sop = loader.LoadNextSop()))
				{
					xml.AddFile(((ILocalSopDataSource) sop.DataSource).File);
				}

				StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
				settings.IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag;
				settings.IncludeUnknownTags = StudyXmlTagInclusion.IgnoreTag;
				settings.MaxTagLength = 100 * 1024;
				settings.IncludeSourceFileName = true;

				XmlDocument doc = xml.GetMemento(settings);
				string fileName = System.IO.Path.Combine(result.FileName, "studyxml.xml");

				XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8);
				writer.Formatting = Formatting.Indented;
				writer.Indentation = 5;
				
				doc.Save(writer);
			}
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:42,代码来源:StudyXmlTestTool.cs

示例4: GetInstanceXml

        private InstanceXml GetInstanceXml(StudyXmlOutputSettings outputSettings, out DicomFile real)
        {
            var xml = new StudyXml();
            real = new DicomFile();
            SetupMR(real.DataSet);
            real.MediaStorageSopClassUid = real.DataSet[DicomTags.SopClassUid].ToString();
            real.MetaInfo[DicomTags.SopClassUid].SetString(0, real.DataSet[DicomTags.SopClassUid].ToString());
            
            var bytes = new Byte[2048];
            real.DataSet[DicomTags.RedPaletteColorLookupTableData].Values = bytes;

            var privateTag = new DicomTag(0x00111301, "Private Tag", "PrivateTag", DicomVr.CSvr, false, 1, 1, false);
            real.DataSet[privateTag].SetString(0, "Private");

            var sequences = (DicomSequenceItem[])real.DataSet[DicomTags.RequestAttributesSequence].Values;
            var firstItem = sequences.First();
            firstItem[DicomTags.RedPaletteColorLookupTableData].Values = bytes;

            var attr = real.DataSet[DicomTags.ReferencedStudySequence];
            var sequenceItem = new DicomSequenceItem();
            attr.AddSequenceItem(sequenceItem);
            sequenceItem[privateTag].SetString(0, "Private");

            xml.AddFile(real);
            
            var memento = xml.GetMemento(outputSettings ?? new StudyXmlOutputSettings
            {
                IncludeLargeTags = StudyXmlTagInclusion.IncludeTagExclusion,
                IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag,
                MaxTagLength = 1024
            });

            xml = new StudyXml();
            xml.SetMemento(memento);
            return xml.First().First();
        }
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:36,代码来源:XmlSopDataSourceTests.cs

示例5: TestTransferSyntax

		public void TestTransferSyntax()
		{
			List<DicomFile> images = SetupImages(4);

			string seriesUid = images[0].DataSet[DicomTags.SeriesInstanceUid].ToString();

			images[0].TransferSyntax = TransferSyntax.Jpeg2000ImageCompression;
			images[1].TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
			images[2].TransferSyntax = TransferSyntax.ExplicitVrBigEndian;
			images[3].TransferSyntax = TransferSyntax.Jpeg2000ImageCompressionLosslessOnly;

			StudyXml xml = new StudyXml();
			foreach (DicomFile file in images)
				xml.AddFile(file);

			XmlDocument doc = xml.GetMemento(new StudyXmlOutputSettings());

			Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.Jpeg2000ImageCompression);
			Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.ExplicitVrLittleEndian);
			Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.ExplicitVrBigEndian);
			Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.Jpeg2000ImageCompressionLosslessOnly);

			xml = new StudyXml();
			xml.SetMemento(doc);

			Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.Jpeg2000ImageCompression);
			Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.ExplicitVrLittleEndian);
			Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.ExplicitVrBigEndian);
			Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].TransferSyntax, TransferSyntax.Jpeg2000ImageCompressionLosslessOnly);
		}
开发者ID:khaha2210,项目名称:radio,代码行数:30,代码来源:StudyXmlTests.cs

示例6: GetInstanceXmlDataSets

		private static List<InstanceXmlDicomAttributeCollection> GetInstanceXmlDataSets(IEnumerable<DicomFile> images, out StudyXml newStudyXml, StudyXmlOutputSettings settings)
		{
			StudyXml xml = new StudyXml();
			foreach (DicomFile image in images)
				xml.AddFile(image);

			XmlDocument doc = xml.GetMemento(settings);
			//SaveStudyXml(doc, @"c:\stewart\LastStudyXml.xml");

			newStudyXml = new StudyXml();
			newStudyXml.SetMemento(doc);

			doc = newStudyXml.GetMemento(settings);
			//SaveStudyXml(doc, @"c:\stewart\LastStudyXml2.xml");

			return GetInstanceXmlDataSets(newStudyXml);
		}
开发者ID:khaha2210,项目名称:radio,代码行数:17,代码来源:StudyXmlTests.cs

示例7: TestBaseInstanceExclusionAfterSerialization

		public void TestBaseInstanceExclusionAfterSerialization()
		{
			foreach (string[] testSet in _overlappingTagTestSets)
			{
				List<DicomFile> images = SetupImages(testSet.Length);
				SetTestAttribute(images, testSet);

				StudyXml xml = new StudyXml();

				StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
				xml = new StudyXml();

				xml.AddFile(images[0]);
				xml.AddFile(images[1]);

				XmlDocument doc = xml.GetMemento(settings);

				settings.MaxTagLength = 1024;

				xml.AddFile(images[2]); //re-add
				doc = xml.GetMemento(settings);

				xml = new StudyXml();
				xml.SetMemento(doc);
				doc = xml.GetMemento(settings);
				xml.AddFile(images[2]); //re-add
				doc = xml.GetMemento(settings);

				xml = new StudyXml();
				xml.SetMemento(doc);
				xml.AddFile(images[1]); //re-add
				doc = xml.GetMemento(settings);
			}
		}
开发者ID:khaha2210,项目名称:radio,代码行数:34,代码来源:StudyXmlTests.cs

示例8: TestMultipleSerializations

		public void TestMultipleSerializations()
		{
			List<DicomFile> images = SetupImages(4);

			XmlDocument doc = null;
			StudyXml xml;
			int i;
			for(i = 0; i < images.Count; ++i)
			{
				xml = new StudyXml();

				if (doc != null)
					xml.SetMemento(doc);

				xml.AddFile(images[i]);
				StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
				doc = xml.GetMemento(settings);
			}

			xml = new StudyXml();
			xml.SetMemento(doc);
			List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
			i = 0;
			foreach (DicomFile file in images)
				ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
		}
开发者ID:khaha2210,项目名称:radio,代码行数:26,代码来源:StudyXmlTests.cs

示例9: TestExcludeBinaryTags

		public void TestExcludeBinaryTags()
		{
			List<DicomFile> images = SetupImages(3);
			images[2].DataSet[DicomTags.SpectroscopyData].Values = new float[6];

			StudyXml xml = new StudyXml();
			foreach (DicomFile file in images)
			{
				file.DataSet[DicomTags.RedPaletteColorLookupTableData].Values = new byte[256];
				file.DataSet[DicomTags.GreenPaletteColorLookupTableData].Values = new byte[256];
				file.DataSet[DicomTags.BluePaletteColorLookupTableData].Values = new byte[256];
				xml.AddFile(file);
			}

			StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
			settings.MaxTagLength = 100;
			XmlDocument doc = xml.GetMemento(settings);

			//SaveStudyXml(doc, @"C:\stewart\testxml.xml");
			List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
			foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
			{
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.RedPaletteColorLookupTableData));
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.GreenPaletteColorLookupTableData));
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.BluePaletteColorLookupTableData));
			}

			//This attribute has a short value, so it should not be excluded.
			Assert.IsFalse(dataSets[2].IsTagExcluded(DicomTags.SpectroscopyData));

			xml = new StudyXml();
			xml.SetMemento(doc);

			dataSets = GetInstanceXmlDataSets(xml);
			foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
			{
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.RedPaletteColorLookupTableData));
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.GreenPaletteColorLookupTableData));
				Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.BluePaletteColorLookupTableData));
			}

			//This attribute has a short value, so it should not be excluded.
			Assert.IsFalse(dataSets[2].IsTagExcluded(DicomTags.SpectroscopyData));
		}
开发者ID:khaha2210,项目名称:radio,代码行数:44,代码来源:StudyXmlTests.cs

示例10: TestExcludePrivateTags

		public void TestExcludePrivateTags()
		{
			List<DicomFile> images = SetupImages(2);
			StudyXml xml = new StudyXml();
			DicomTag privateTag =
				new DicomTag(0x00210010, "Private Tag", "Private Tag", DicomVr.LTvr, false, 1, uint.MaxValue, false);
			
			foreach (DicomFile file in images)
			{
				file.DataSet[privateTag].SetStringValue("My Private Tag");
				xml.AddFile(file);
			}

			StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
			XmlDocument doc = xml.GetMemento(settings);

			List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
			foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
				Assert.IsFalse(dataSet.Contains(privateTag));

			xml = new StudyXml();
			xml.SetMemento(doc);

			dataSets = GetInstanceXmlDataSets(xml);
			foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
				Assert.IsFalse(dataSet.Contains(privateTag));
		}
开发者ID:khaha2210,项目名称:radio,代码行数:27,代码来源:StudyXmlTests.cs

示例11: TestBaseInstanceTagsPastEnd

		public void TestBaseInstanceTagsPastEnd()
		{
			//NOTE: previously, this test failed because, during xml serialization, only the
			//instance's own attributes were iterated over; if there were tags in the base instance
			//that went past the end of the individual instances, no 'EmptyAttributes' got added
			//to the xml and there would be extra attributes in the instances on deserialization.
			List<DicomFile> images = SetupImages(2);
			DicomFile smallFile = new DicomFile(null);
			images.Add(smallFile);
			base.SetupMetaInfo(smallFile);

			DicomAttributeCollection theSet = smallFile.DataSet;
			theSet[DicomTags.SpecificCharacterSet].SetStringValue("ISO_IR 100");
			theSet[DicomTags.ImageType].SetStringValue("ORIGINAL\\PRIMARY\\OTHER\\M\\FFE");
			theSet[DicomTags.InstanceCreationDate].SetStringValue("20070618");
			theSet[DicomTags.InstanceCreationTime].SetStringValue("133600");
			theSet[DicomTags.SopClassUid].SetStringValue(SopClass.MrImageStorageUid);
			theSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
			theSet[DicomTags.StudyDate].SetStringValue("20070618");
			theSet[DicomTags.StudyTime].SetStringValue("133600");
			theSet[DicomTags.SeriesDate].SetStringValue("20070618");
			theSet[DicomTags.SeriesTime].SetStringValue("133700");
			theSet[DicomTags.AccessionNumber].SetStringValue("A1234");
			theSet[DicomTags.Modality].SetStringValue("MR");
			theSet[DicomTags.Manufacturer].SetStringValue("ClearCanvas");
			theSet[DicomTags.ManufacturersModelName].SetNullValue();
			theSet[DicomTags.InstitutionName].SetStringValue("Mount Sinai Hospital");
			theSet[DicomTags.ReferringPhysiciansName].SetStringValue("Last^First");
			theSet[DicomTags.StudyDescription].SetStringValue("HEART");
			theSet[DicomTags.SeriesDescription].SetStringValue("Heart 2D EPI BH TRA");

			theSet[DicomTags.StudyInstanceUid].SetStringValue(images[0].DataSet[DicomTags.StudyInstanceUid].ToString());
			theSet[DicomTags.SeriesInstanceUid].SetStringValue(images[0].DataSet[DicomTags.SeriesInstanceUid].ToString());
			theSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().ToString());

			StudyXml xml = new StudyXml();

			foreach (DicomFile file in images)
				xml.AddFile(file);

			StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
			XmlDocument doc = xml.GetMemento(settings);

			List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
			int i = 0;
			foreach (DicomFile file in images)
				ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);

			xml = new StudyXml();
			xml.SetMemento(doc);

			dataSets = GetInstanceXmlDataSets(xml);
			i = 0;
			foreach (DicomFile file in images)
				ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
		}
开发者ID:khaha2210,项目名称:radio,代码行数:56,代码来源:StudyXmlTests.cs

示例12: TestExclusionsImmediatelyAfterSerialization

		public void TestExclusionsImmediatelyAfterSerialization()
		{
			//NOTE: previously, this test failed because the excluded tags were not added to the
			//xml collection until after it had been deserialized at least once from the xml.
			foreach (string[] testSet in _overlappingTagTestSets)
			{
				List<DicomFile> images = SetupImages(testSet.Length);
				SetTestAttribute(images, testSet);

				StudyXml xml = new StudyXml();

				foreach (DicomFile file in images)
					xml.AddFile(file);

				StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
				settings.MaxTagLength = 1024;
				XmlDocument doc = xml.GetMemento(settings);

				List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
				ValidateSimpleDataSets(testSet, dataSets, settings);

				//do a little extra validation, what the hay.
				xml = new StudyXml();
				xml.SetMemento(doc);

				dataSets = GetInstanceXmlDataSets(xml);
				ValidateSimpleDataSets(testSet, dataSets, settings);
			}
		}
开发者ID:khaha2210,项目名称:radio,代码行数:29,代码来源:StudyXmlTests.cs

示例13: TestEqualAfterSerialization

		public void TestEqualAfterSerialization()
		{
			foreach (string[] testSet in _overlappingTagTestSets)
			{
				List<DicomFile> images = SetupImages(testSet.Length);
				SetTestAttribute(images, testSet);

				StudyXml xml = new StudyXml();

				foreach (DicomFile file in images)
					xml.AddFile(file);

				StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
				settings.MaxTagLength = 1024;
				XmlDocument doc = xml.GetMemento(settings);

				List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
				int i = 0;
				foreach (DicomFile file in images)
					ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);

				xml = new StudyXml();
				xml.SetMemento(doc);

				dataSets = GetInstanceXmlDataSets(xml);
				i = 0;
				foreach (DicomFile file in images)
					ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
			}
		}
开发者ID:khaha2210,项目名称:radio,代码行数:30,代码来源:StudyXmlTests.cs

示例14: CreationTest

		public void CreationTest()
		{
			IList<DicomAttributeCollection> instanceList;

			string studyInstanceUid = DicomUid.GenerateUid().UID;

			instanceList = SetupMRSeries(4, 10, studyInstanceUid);



			StudyXml studyXml = new StudyXml(studyInstanceUid);

			string studyXmlFilename = Path.GetTempFileName();

			foreach (DicomAttributeCollection instanceCollection in instanceList)
			{
				instanceCollection[DicomTags.PixelData] = null;


				DicomFile theFile = new DicomFile("test", new DicomAttributeCollection(), instanceCollection);
				SetupMetaInfo(theFile);

				studyXml.AddFile(theFile);

				WriteStudyStream(studyXmlFilename, studyXml);
			}

			StudyXml newXml = LoadStudyStream(studyXmlFilename);

			if (!Compare(newXml, instanceList))
				Assert.Fail("Comparison of StudyXML failed against base loaded from disk");

			if (!Compare(studyXml, instanceList))
				Assert.Fail("Comparison of StudyXML failed against base in memory");

		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:36,代码来源:GeneralStreamingTest.cs

示例15: UpdateFilesystem

		private void UpdateFilesystem()
		{
			Platform.Log(LogLevel.Info, "Updating filesystem...");
			StudyXml studyXml = _oldStudyLocation.LoadStudyXml();
			StudyXmlOutputSettings outputSettings = ImageServerCommonConfiguration.DefaultStudyXmlOutputSettings;

			StudyXml newStudyXml = new StudyXml();
            foreach (SeriesXml seriesXml in studyXml)
			{
				foreach (InstanceXml instanceXml in seriesXml)
				{
					string path = Path.Combine(_oldStudyPath, seriesXml.SeriesInstanceUid);
					path = Path.Combine(path, instanceXml.SopInstanceUid);
					path += ServerPlatform.DicomFileExtension;

                    if (!File.Exists(path))
                    {
                        Platform.Log(LogLevel.Info, "SOP {0} is referenced in study xml but does not exist. It will be removed");
                        continue; // file was removed but xml was not updated?
                    }

                    try
                    {                        
                        DicomFile file = new DicomFile(path);
                        file.Load();

                        InstanceInfo instance = new InstanceInfo
                        {
                            SeriesInstanceUid = file.DataSet[DicomTags.SeriesInstanceUid].GetString(0, String.Empty),
                            SopInstanceUid = file.DataSet[DicomTags.SopInstanceUid].GetString(0, String.Empty)
                        };
                        
                        UpdateDicomFile(file);

                        // Add into the temporary study xml
                        long fileSize = 0;
                        if (File.Exists(file.Filename))
                        {
                            FileInfo finfo = new FileInfo(file.Filename);
                            fileSize = finfo.Length;
                        }
                        newStudyXml.AddFile(file, fileSize, outputSettings);

                        
                        _updatedSopList.Add(instance);
                        Platform.Log(ServerPlatform.InstanceLogLevel, "SOP {0} has been updated [{1} of {2}].", instance.SopInstanceUid, _updatedSopList.Count, _totalSopCount);

						EventManager.FireEvent(this, new UpdateSopEventArgs { File = file, ServerPartitionEntry = _partition, WorkQueueUidEntry = null, WorkQueueEntry = _workQueue, FileLength = (ulong)fileSize });

                    }
                    catch (Exception)
                    {
                        File.Delete(Path.Combine(_backupDir, instanceXml.SopInstanceUid) + ".bak"); //dont' need to restore this file
                        throw;
                    }
                }                
			}

            // Log any study-level warnings
			if (_updatedSopList.Count != _totalSopCount)
			{
				Platform.Log(LogLevel.Warn, "Inconsistent data: expected {0} instances to be updated / Found {1}.", _totalSopCount, _updatedSopList.Count);
			}

            // update the header
			Platform.Log(LogLevel.Info, "Generating new study header...");
			string newStudyXmlPath = Path.Combine(NewStudyPath, _newStudyInstanceUid + ".xml");
			string gzipStudyXmlPath = Path.Combine(NewStudyPath, _newStudyInstanceUid + ".xml.gz");
			using (FileStream xmlStream = FileStreamOpener.OpenForSoleUpdate(newStudyXmlPath, FileMode.Create),
			                  gzipStream = FileStreamOpener.OpenForSoleUpdate(gzipStudyXmlPath, FileMode.Create))
			{
				StudyXmlIo.WriteXmlAndGzip(newStudyXml.GetMemento(outputSettings), xmlStream, gzipStream);
				xmlStream.Close();
				gzipStream.Close();
			}
		}
开发者ID:jfphilbin,项目名称:ClearCanvas,代码行数:76,代码来源:UpdateStudyCommand.cs


注:本文中的StudyXml.AddFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。