/// <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")); ConnectionOptions.SaveToXml(rootElem.AppendElem("ConnectionOptions")); XmlElement linesElem = rootElem.AppendElem("Lines"); foreach (LineConfig lineConfig in Lines) { lineConfig.SaveToXml(linesElem.AppendElem("Line")); } xmlDoc.Save(fileName); errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommonPhrases.SaveAppConfigError + ": " + ex.Message; return(false); } }
/// <summary> /// Saves the configuration to the specified writer. /// </summary> protected override void Save(TextWriter writer) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(xmlDecl); XmlElement rootElem = xmlDoc.CreateElement("ScadaCommConfig"); xmlDoc.AppendChild(rootElem); GeneralOptions.SaveToXml(rootElem.AppendElem("GeneralOptions")); ConnectionOptions.SaveToXml(rootElem.AppendElem("ConnectionOptions")); XmlElement dataSourcesElem = rootElem.AppendElem("DataSources"); foreach (DataSourceConfig dataSourceConfig in DataSources) { dataSourceConfig.SaveToXml(dataSourcesElem.AppendElem("DataSource")); } XmlElement linesElem = rootElem.AppendElem("Lines"); foreach (LineConfig lineConfig in Lines) { lineConfig.SaveToXml(linesElem.AppendElem("Line")); } xmlDoc.Save(writer); }