本文整理汇总了C#中StudyXml.GetMemento方法的典型用法代码示例。如果您正苦于以下问题:C# StudyXml.GetMemento方法的具体用法?C# StudyXml.GetMemento怎么用?C# StudyXml.GetMemento使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StudyXml
的用法示例。
在下文中一共展示了StudyXml.GetMemento方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: WriteStudyStream
private void WriteStudyStream(string streamFile, StudyXml theStream)
{
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
settings.IncludeSourceFileName = false;
XmlDocument doc = theStream.GetMemento(settings);
if (File.Exists(streamFile))
File.Delete(streamFile);
using (Stream fileStream = new FileStream(streamFile, FileMode.CreateNew))
{
StudyXmlIo.Write(doc, fileStream);
fileStream.Close();
}
return;
}
示例3: WriteStudyStream
private static void WriteStudyStream(string streamFile, string gzStreamFile, StudyXml theStream)
{
XmlDocument doc = theStream.GetMemento(_outputSettings);
// allocate the random number generator here, in case we need it below
Random rand = new Random();
string tmpStreamFile = streamFile + "_tmp";
string tmpGzStreamFile = gzStreamFile + "_tmp";
for (int i = 0; ; i++)
try
{
if (File.Exists(tmpStreamFile))
FileUtils.Delete(tmpStreamFile);
if (File.Exists(tmpGzStreamFile))
FileUtils.Delete(tmpGzStreamFile);
using (FileStream xmlStream = FileStreamOpener.OpenForSoleUpdate(tmpStreamFile, FileMode.CreateNew),
gzipStream = FileStreamOpener.OpenForSoleUpdate(tmpGzStreamFile, FileMode.CreateNew))
{
StudyXmlIo.WriteXmlAndGzip(doc, xmlStream, gzipStream);
xmlStream.Close();
gzipStream.Close();
}
if (File.Exists(streamFile))
FileUtils.Delete(streamFile);
File.Move(tmpStreamFile, streamFile);
if (File.Exists(gzStreamFile))
FileUtils.Delete(gzStreamFile);
File.Move(tmpGzStreamFile,gzStreamFile);
return;
}
catch (IOException)
{
if (i < 5)
{
Thread.Sleep(rand.Next(5, 50)); // Sleep 5-50 milliseconds
continue;
}
throw;
}
}
示例4: 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));
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);
}
}
示例5: 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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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));
}
示例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));
}
示例11: WriteStudyStream
private void WriteStudyStream(string streamFile, string gzStreamFile, StudyXml theStream)
{
var theMemento = theStream.GetMemento(_outputSettings);
// allocate the random number generator here, in case we need it below
var rand = new Random();
string tmpStreamFile = streamFile + "_tmp";
string tmpGzStreamFile = gzStreamFile + "_tmp";
for (int i = 0; ; i++)
try
{
//FileUtils.Delete checks for existence
FileUtils.Delete(tmpStreamFile);
FileUtils.Delete(tmpGzStreamFile);
_fileSaved = true;
using (FileStream xmlStream = FileStreamOpener.OpenForSoleUpdate(tmpStreamFile, FileMode.CreateNew),
gzipStream = FileStreamOpener.OpenForSoleUpdate(tmpGzStreamFile, FileMode.CreateNew))
{
StudyXmlIo.WriteXmlAndGzip(theMemento, xmlStream, gzipStream);
xmlStream.Close();
gzipStream.Close();
}
//FileUtils.Delete checks for existence
FileUtils.Delete(streamFile);
File.Move(tmpStreamFile, streamFile);
//FileUtils.Delete checks for existence
FileUtils.Delete(_gzPath);
File.Move(tmpGzStreamFile, _gzPath);
return;
}
catch (IOException)
{
if (i < 5)
{
Thread.Sleep(rand.Next(5, 50)); // Sleep 5-50 milliseconds
continue;
}
throw;
}
}
示例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);
}
}
示例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);
}
}
示例14: 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();
}
}
示例15: SaveStudyXml
/// <summary>
/// Save the <see cref="StudyXml"/> file for a study.
/// </summary>
/// <param name="studyXml">The <see cref="StudyXml"/> file to save.</param>
/// <param name="fileCreated">flag set to true if the file was created</param>
public void SaveStudyXml(StudyXml studyXml, out bool fileCreated)
{
var settings = new StudyXmlOutputSettings
{
IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag,
IncludeUnknownTags = StudyXmlTagInclusion.IgnoreTag,
IncludeLargeTags = StudyXmlTagInclusion.IncludeTagExclusion,
MaxTagLength = 2048,
IncludeSourceFileName = true
};
var doc = studyXml.GetMemento(settings);
string streamFile = GetStudyXmlPath();
// allocate the random number generator here, in case we need it below
var rand = new Random();
string tmpStreamFile = streamFile + "_tmp";
for (int i = 0; ; i++)
try
{
if (File.Exists(tmpStreamFile))
FileUtils.Delete(tmpStreamFile);
using (FileStream xmlStream = FileStreamOpener.OpenForSoleUpdate(tmpStreamFile, FileMode.CreateNew))
{
StudyXmlIo.Write(doc, xmlStream);
xmlStream.Close();
}
File.Copy(tmpStreamFile, streamFile, true);
fileCreated = true;
FileUtils.Delete(tmpStreamFile);
return;
}
catch (IOException)
{
if (i < 5)
{
Thread.Sleep(rand.Next(5, 50)); // Sleep 5-50 milliseconds
continue;
}
throw;
}
}