Esempio n. 1
0
        /// <summary>
        /// Saves the currently loaded T Settings object as a serialized XML file.
        /// </summary>
        /// <param name="filename">The filename to save the serialized representation to (including the absolute path: C:\my\directory\filename.xml)</param>
        /// <param name="errorMessage">The errormessage if not successfull.</param>
        /// <returns>True if successfull, otherwise false.</returns>
        public bool SaveAsXmlFile(string filename, out string errorMessage)
        {
            errorMessage = "T Settings object was null and therefore could not be serialized.";
            if (this.Settings != null)
            {
                if (XmlSerializationHelper <T> .SaveAsXmlFile(this.Settings, filename, out errorMessage))
                {
                    lock (_CacheLock)
                    {
                        _Filename = filename;
                        _SetCachedependencyOnFilename = true;

                        RefreshCache();
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the current Settings property from a specified xml string. The xml be a serialized version of the defined T object.
        /// </summary>
        /// <param name="xml">The serialized xml version of the T object to load</param>
        public void LoadFromXml(string xml)
        {
            if (!string.IsNullOrEmpty(xml))
            {
                lock (_CacheLock)
                {
                    string errorMessage = string.Empty;
                    _Settings = XmlSerializationHelper <T> .ConvertFromXml(xml, out errorMessage);

                    if (!string.IsNullOrEmpty(errorMessage) || _Settings == null)
                    {
                        throw new XmlSettingsManagerException(errorMessage);
                    }

                    _SetCachedependencyOnFilename = false;
                    _Filename = string.Empty;

                    RefreshCache();
                }
            }
        }