Пример #1
0
        //open
        private static void open()
        {
            //is parameter fileName null or empty
            if (fileName == null | fileName == string.Empty)
            {
                throwParameterNullException("fileName");
            }

            data = new XmlDocument();

            // if file exsist load, if not create
            if (File.Exists(fileName))
            {
                try
                {
                    data.Load(fileName);
                }
                catch(XmlException ex)
                {
                    throwXmlFormatException(ex);
                }
            }
            else
            {
                data.AppendChild(data.CreateElement(RES_RootName));
                root = new SettingsKey(data.DocumentElement,true);
            }

            //set rootkey  to readonly
            root = new SettingsKey(data.DocumentElement,true);

            //set handlers
            XmlNodeChangedEventHandler handler = new XmlNodeChangedEventHandler(handleChanges);
            data.NodeChanged +=  handler;
            data.NodeInserted += handler;
            data.NodeRemoved +=  handler;

            //set dirty flag
            hasChanges = false;

            //set Open
            isOpen = true;
        }
Пример #2
0
        /// <summary>
        /// Retrieves a specified subkey, with the specified
        /// read-write access.
        /// </summary>
        /// 
        /// <param name="subkeyName">
        /// The name or path of the subkey to open.
        /// </param>
        /// 
        /// <param name="writable">
        /// Set this argument to true if you need write access to the key.
        /// </param>
        /// 
        /// <returns>
        /// The subkey requested, or null if the operation failed.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The specified string parameter 'subkeyName' is null or an empty string.
        /// </exception>
        /// 
        /// <remarks>
        /// The parameter 'subkeyName' is  case-sensitive.
        /// You must open a key before it can be manipulated 
        /// with other methods and properties. If the specified 
        /// subkey cannot be found, then a null setting is returned.
        /// If writable is set to true, the subkey will be 
        /// opened for read-write access. 
        /// If writable is set to false the key will be opened as read-only.
        /// </remarks>
        public SettingsKey OpenSubKey(string subkeyName, bool writable)
        {
            SettingsKey key;

            #region conditions

            // is the parameter subkeyName null or an empty string
            if (subkeyName == null || subkeyName == String.Empty)
            {
                this.throwParameterNullException("subkeyName");
            }

            #endregion

            // if subkey exsist assign it to key
            if (this.data[subkeyName] != null)
            {
                key = new SettingsKey(this.data[subkeyName], !writable);
            }
            else
                key = null;

            return key;
        }