private void LoadFromBinary(StreamReader streamReader)
        {
            BinaryReader binaryReader = new BinaryReader(streamReader.BaseStream);

            while (streamReader.BaseStream.Position < streamReader.BaseStream.Length)
            {
                try
                {
                    int    length = binaryReader.ReadInt32();
                    byte[] buffer = new byte[length];
                    binaryReader.Read(buffer, 0, length);
                    string stringUid = ByteConvert.ToString(buffer,
                                                            CharacterRepertoire.Ascii);
                    Uid uid = new Uid(stringUid);
                    length = binaryReader.ReadInt32();
                    buffer = new byte[length];
                    binaryReader.Read(buffer, 0, length);
                    string name = ByteConvert.ToString(buffer,
                                                       CharacterRepertoire.Ascii);
                    int     intType = binaryReader.ReadInt32();
                    UidType type    = (UidType)UidType.ToObject(typeof(UidType),
                                                                intType);
                    bool retired             = binaryReader.ReadBoolean();
                    UidDictionaryEntry entry =
                        new UidDictionaryEntry(uid, name, type, retired);
                    Add(entry);
                }
                catch (Exception e)
                {
                    throw new DicomException("Wrong entry before index " +
                                             streamReader.BaseStream.Position + ": " + e.Message);
                }
            }
        }
 /// <summary>
 ///     Returns the entire UID dictionary as array of
 ///     <see cref="UidDictionaryEntry" />.
 /// </summary>
 public UidDictionaryEntry[] ToArray()
 {
     UidDictionaryEntry[] entryArray =
         new UidDictionaryEntry[Count];
     hashTable.Values.CopyTo(entryArray, 0);
     Array.Sort(entryArray);
     return(entryArray);
 }
        protected virtual void LoadFromXml(TextReader textReader)
        {
            XmlTextReader xmlTextReader = new XmlTextReader(textReader);
            string        uid           = null;
            string        name          = null;
            string        type          = null;
            string        retired       = null;

            while (xmlTextReader.Read())
            {
                switch (xmlTextReader.Name)
                {
                case "DictionaryEntry":
                    retired = xmlTextReader["retired"];
                    break;

                case "Uid":
                    xmlTextReader.MoveToContent();
                    uid = xmlTextReader.ReadString();
                    break;

                case "Name":
                    xmlTextReader.MoveToContent();
                    name = xmlTextReader.ReadString();
                    break;

                case "Type":
                    xmlTextReader.MoveToContent();
                    type = xmlTextReader.ReadString();
                    break;
                }
                if (uid != null && name != null && type != null)
                {
                    try
                    {
                        UidDictionaryEntry entry =
                            new UidDictionaryEntry(uid, name.Trim(),
                                                   type.Trim(), retired);
                        Add(entry);
                    }
                    catch (Exception e)
                    {
                        throw new DicomException("Wrong entry at UID " +
                                                 uid + ": " + e.Message);
                    }
                    uid = name = type = retired = null;
                }
            }
            xmlTextReader.Close();
        }
        private void LoadFromProperty(TextReader textReader)
        {
            string line       = textReader.ReadLine();
            int    lineNumber = 1;

            string[] result = null;
            while (line != null)
            {
                string lineWithoutSpaces = line.Replace(" ", null);
                if (!lineWithoutSpaces.StartsWith("#") &&
                    !lineWithoutSpaces.Equals(""))
                {
                    if (Regex.IsMatch(lineWithoutSpaces,
                                      "^[0-9\\.]+=[^,]+,[^,]+(,RET)?$"))
                    {
                        result = line.Split('=');
                        string uid = result[0];
                        result = result[1].Split(',');
                        string retired = (result.Length == 3) ? "RET" : null;
                        try
                        {
                            UidDictionaryEntry entry =
                                new UidDictionaryEntry(uid,
                                                       result[0].Trim(), result[1].Trim(),
                                                       retired);
                            Add(entry);
                        }
                        catch (Exception e)
                        {
                            throw new DicomException("Wrong entry in line " +
                                                     lineNumber.ToString() + ": " + e.Message);
                        }
                    }
                    else
                    {
                        throw new DicomException("Wrong entry in line " +
                                                 lineNumber.ToString() + ".");
                    }
                }
                line = textReader.ReadLine();
                lineNumber++;
            }
        }
 /// <summary>
 ///     Adds a new UID dictionary entry to a UID
 ///     dictionary instance.
 /// </summary>
 public void Add(UidDictionaryEntry entry)
 {
     if (entry != null)
     {
         if (!Contains(entry.Uid))
         {
             hashTable.Add(entry.Uid.ToString(), entry);
         }
         else
         {
             throw new DicomException(
                       "UID already exists in UID dictionary.",
                       "entry.Uid", entry.Uid.ToString());
         }
     }
     else
     {
         throw new DicomException("entry is null.", "entry");
     }
 }
 /// <summary>
 ///     Determines whether another UID dictionary entry instance equals
 ///     this instance by its properties.
 /// </summary>
 public bool Equals(UidDictionaryEntry dictionaryEntry)
 {
     return(CompareTo(dictionaryEntry) == 0);
 }