Skip to content

Commit

Permalink
Removed System.IO.File dependency from DicomDictionary. Issue fo-dico…
Browse files Browse the repository at this point in the history
  • Loading branch information
anders9ustafsson committed Sep 2, 2015
1 parent 9841271 commit 17d7da0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
8 changes: 8 additions & 0 deletions DICOM [Unit Tests]/DICOM [Unit Tests].csproj
Expand Up @@ -115,6 +115,14 @@
<None Include="Test Data\DICOMDIR">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Test Data\minimumdict.xml.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Test Data\minimumdict.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
33 changes: 33 additions & 0 deletions DICOM [Unit Tests]/DicomDictionaryTest.cs
Expand Up @@ -4,6 +4,7 @@
namespace Dicom
{
using System.Collections.Generic;
using System.Linq;

using Xunit;

Expand All @@ -19,6 +20,37 @@ public void Default_Item_ExistingTag_EntryFound(DicomTag tag)
Assert.NotEqual(DicomDictionary.UnknownTag, entry);
}

[Theory]
[MemberData("Tags")]
public void Constructor_NoExplicitLoading_TagsNotFound(DicomTag tag)
{
var dict = new DicomDictionary();
var actual = dict[tag];
Assert.Equal(DicomDictionary.UnknownTag, actual);
}

[Fact]
public void Load_UncompressedFile_LoadedTagFound()
{
var dict = new DicomDictionary();
dict.Load(@".\Test Data\minimumdict.xml", DicomDictionaryFormat.XML);

var expected = DicomVR.CS;
var actual = dict[DicomTag.FileSetID].ValueRepresentations.Single();
Assert.Equal(expected, actual);
}

[Fact]
public void Load_CompressedFile_LoadedTagFound()
{
var dict = new DicomDictionary();
dict.Load(@".\Test Data\minimumdict.xml.gz", DicomDictionaryFormat.XML);

var expected = DicomVR.CS;
var actual = dict[DicomTag.FileSetID].ValueRepresentations.Single();
Assert.Equal(expected, actual);
}

#endregion

#region Support data
Expand All @@ -27,6 +59,7 @@ public static IEnumerable<object[]> Tags
{
get
{
yield return new object[] { DicomTag.FileSetID };
yield return new object[] { DicomTag.ContourData };
yield return new object[] { DicomTag.ReferencePixelX0 };
yield return new object[] { DicomTag.dBdt };
Expand Down
4 changes: 4 additions & 0 deletions DICOM [Unit Tests]/Test Data/minimumdict.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<dictionary version="minimum">
<tag group="0004" element="1130" keyword="FileSetID" vr="CS" vm="1">File-set ID</tag>
</dictionary>
Binary file added DICOM [Unit Tests]/Test Data/minimumdict.xml.gz
Binary file not shown.
25 changes: 18 additions & 7 deletions DICOM/DicomDictionary.cs
Expand Up @@ -3,14 +3,18 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;

namespace Dicom
{
public partial class DicomDictionary : IEnumerable<DicomDictionaryEntry>
using Dicom.IO;

/// <summary>
/// Class for managing DICOM dictionaries.
/// </summary>
public class DicomDictionary : IEnumerable<DicomDictionaryEntry>
{
#region Private Members

Expand Down Expand Up @@ -244,15 +248,22 @@ public DicomPrivateCreator GetPrivateCreator(string creator)
return pvt;
}

/// <summary>
/// Load DICOM dictionary data from file.
/// </summary>
/// <param name="file">File name.</param>
/// <param name="format">File format.</param>
public void Load(string file, DicomDictionaryFormat format)
{
using (var fs = File.OpenRead(file))
using (var fs = IOManager.CreateFileReference(file).OpenRead())
{
Stream s = fs;

if (file.EndsWith(".gz")) s = new GZipStream(s, CompressionMode.Decompress);
var s = fs;
if (file.EndsWith(".gz"))
{
s = new GZipStream(s, CompressionMode.Decompress);
}

DicomDictionaryReader reader = new DicomDictionaryReader(this, format, s);
var reader = new DicomDictionaryReader(this, format, s);
reader.Process();
}
}
Expand Down

0 comments on commit 17d7da0

Please sign in to comment.