Example #1
0
        /// <summary>
        /// Saves the configuration to the specified file.
        /// </summary>
        public bool Save(string fileName, out string errMsg)
        {
            try
            {
                XmlDocument    xmlDoc  = new XmlDocument();
                XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmlDoc.AppendChild(xmlDecl);

                XmlElement rootElem = xmlDoc.CreateElement("ScadaServerConfig");
                xmlDoc.AppendChild(rootElem);

                GeneralOptions.SaveToXml(rootElem.AppendElem("GeneralOptions"));
                ListenerOptions.SaveToXml(rootElem.AppendElem("ListenerOptions"));
                PathOptions.SaveToXml(rootElem.AppendElem("PathOptions"));

                XmlElement modulesElem = rootElem.AppendElem("Modules");
                foreach (string moduleCode in ModuleCodes)
                {
                    modulesElem.AppendElem("Module").SetAttribute("code", moduleCode);
                }

                XmlElement archivesElem = rootElem.AppendElem("Archives");
                foreach (ArchiveConfig archiveConfig in Archives)
                {
                    archiveConfig.SaveToXml(archivesElem.AppendElem("Archive"));
                }

                xmlDoc.Save(fileName);
                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.SaveAppConfigError + ": " + ex.Message;
                return(false);
            }
        }