private static void LoadInternalDictionaries() { lock (_lock) { if (_default == null) { _default = new DicomDictionary(); _default.Add(new DicomDictionaryEntry(DicomMaskedTag.Parse("xxxx", "0000"), "Group Length", "GroupLength", DicomVM.VM_1, false, DicomVR.UL)); try { var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream("Dicom.Dictionaries.DICOM Dictionary.xml.gz"); var gzip = new GZipStream(stream, CompressionMode.Decompress); var reader = new DicomDictionaryReader(_default, DicomDictionaryFormat.XML, gzip); reader.Process(); } catch (Exception e) { throw new DicomDataException("Unable to load DICOM dictionary from resources.\n\n" + e.Message, e); } try { var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream("Dicom.Dictionaries.Private Dictionary.xml.gz"); var gzip = new GZipStream(stream, CompressionMode.Decompress); var reader = new DicomDictionaryReader(_default, DicomDictionaryFormat.XML, gzip); reader.Process(); } catch (Exception e) { throw new DicomDataException("Unable to load private dictionary from resources.\n\n" + e.Message, e); } } } }
public void Load(string file, DicomDictionaryFormat format) { using (var fs = File.OpenRead(file)) { Stream s = fs; if (file.EndsWith(".gz")) { s = new GZipStream(s, CompressionMode.Decompress); } DicomDictionaryReader reader = new DicomDictionaryReader(this, format, s); reader.Process(); } }
/// <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 = IOManager.CreateFileReference(file).OpenRead()) { var s = fs; if (file.EndsWith(".gz")) { s = new GZipStream(s, CompressionMode.Decompress); } var reader = new DicomDictionaryReader(this, format, s); reader.Process(); } }
/// <summary> /// Ensures the default DICOM dictionaries are loaded /// Safe to call multiple times but will throw an exception if inconsistent values for loadPrivateDictionary are provided over multiple calls /// </summary> /// <param name="loadPrivateDictionary">Leave null (default value) if unconcerned. Set true to search for resource streams named "Dicom.Dictionaries.Private Dictionary.xml.gz" in referenced assemblies</param> /// <returns></returns> public static DicomDictionary EnsureDefaultDictionariesLoaded(bool?loadPrivateDictionary = null) { // short-circuit if already initialised (#151). if (_default != null) { if (loadPrivateDictionary.HasValue && _defaultIncludesPrivate != loadPrivateDictionary.Value) { throw new DicomDataException("Default DICOM dictionary already loaded " + (_defaultIncludesPrivate ? "with" : "without") + "private dictionary and the current request to ensure the default dictionary is loaded requests that private dictionary " + (loadPrivateDictionary.Value ? "is" : "is not") + " loaded"); } return(_default); } lock (_lock) { if (_default == null) { var dict = new DicomDictionary(); dict.Add( new DicomDictionaryEntry( DicomMaskedTag.Parse("xxxx", "0000"), "Group Length", "GroupLength", DicomVM.VM_1, false, DicomVR.UL)); try { #if NET35 || HOLOLENS using ( var stream = new MemoryStream( UnityEngine.Resources.Load <UnityEngine.TextAsset>("DICOM Dictionary").bytes)) { var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, stream); reader.Process(); } #else var assembly = typeof(DicomDictionary).GetTypeInfo().Assembly; using ( var stream = assembly.GetManifestResourceStream( "Dicom.Dictionaries.DICOMDictionary.xml.gz")) { var gzip = new GZipStream(stream, CompressionMode.Decompress); var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, gzip); reader.Process(); } #endif } catch (Exception e) { throw new DicomDataException( "Unable to load DICOM dictionary from resources.\n\n" + e.Message, e); } if (loadPrivateDictionary.GetValueOrDefault(true)) { try { #if NET35 || HOLOLENS using ( var stream = new MemoryStream( UnityEngine.Resources.Load <UnityEngine.TextAsset>("Private Dictionary").bytes)) { var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, stream); reader.Process(); } #else var assembly = typeof(DicomDictionary).GetTypeInfo().Assembly; using ( var stream = assembly.GetManifestResourceStream("Dicom.Dictionaries.PrivateDictionary.xml.gz")) { var gzip = new GZipStream(stream, CompressionMode.Decompress); var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, gzip); reader.Process(); } #endif } catch (Exception e) { throw new DicomDataException( "Unable to load private dictionary from resources.\n\n" + e.Message, e); } } _defaultIncludesPrivate = loadPrivateDictionary.GetValueOrDefault(true); _default = dict; } else { //ensure the race wasn't for two different "load private dictionary" states if (loadPrivateDictionary.HasValue && _defaultIncludesPrivate != loadPrivateDictionary) { throw new DicomDataException("Default DICOM dictionary already loaded " + (_defaultIncludesPrivate ? "with" : "without") + "private dictionary and the current request to ensure the default dictionary is loaded requests that private dictionary " + (loadPrivateDictionary.Value ? "is" : "is not") + " loaded"); } return(_default); } //race is complete return(_default); } }