Example #1
0
        public IEntry AddFolder(string key)
        {
            var containsKey = Contains(key);

            if (containsKey)
            {
                throw new RegistryException("Key already exists.");
            }

            var entry = new FolderEntry(key);

            m_Entries.Add(entry);
            return(entry);
        }
Example #2
0
        public IEntry Read()
        {
            var       root     = new FolderEntry("Root");
            var       settings = new XmlReaderSettings();
            XmlReader reader   = null;

            try
            {
                reader = XmlReader.Create(StorageFile, settings);

                if (reader != null)
                {
                    var document = new XmlDocument();
                    document.Load(reader);

                    XmlNode rootFolder = document.SelectSingleNode("Registry/Folder");
                    if (rootFolder != null)
                    {
                        ReadFromDocument(root, rootFolder);
                    }
                    else
                    {
                        throw new RegistryException("Registry root tag not found!");
                    }
                }
                else
                {
                    throw new RegistryException("Could not open file!");
                }
            }
            catch (XmlException xmlEx)
            {
                throw new RegistryException("Could not load xml document.See inner exception.", xmlEx);
            }
            catch (Exception ex)
            {
                throw new RegistryException("Unknown error occured.See inner exception", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(root);
        }