/// <summary> /// Loads the configuration from the specified file. /// </summary> public bool Load(string fileName, out string errMsg) { try { SetToDefault(); if (!File.Exists(fileName)) { throw new FileNotFoundException(string.Format(CommonPhrases.NamedFileNotFound, fileName)); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); XmlElement rootElem = xmlDoc.DocumentElement; if (rootElem.SelectSingleNode("GeneralOptions") is XmlNode generalOptionsNode) { GeneralOptions.LoadFromXml(generalOptionsNode); } if (rootElem.SelectSingleNode("ListenerOptions") is XmlNode listenerOptionsNode) { ListenerOptions.LoadFromXml(listenerOptionsNode); } if (rootElem.SelectSingleNode("PathOptions") is XmlNode pathOptionsNode) { PathOptions.LoadFromXml(pathOptionsNode); } HashSet <string> moduleCodes = new HashSet <string>(); if (rootElem.SelectSingleNode("Modules") is XmlNode modulesNode) { foreach (XmlElement moduleElem in modulesNode.SelectNodes("Module")) { string moduleCode = ScadaUtils.RemoveFileNameSuffixes(moduleElem.GetAttribute("code")); if (moduleCodes.Add(moduleCode.ToLowerInvariant())) // check uniqueness { ModuleCodes.Add(moduleCode); } } } if (rootElem.SelectSingleNode("Archives") is XmlNode archivesNode) { foreach (XmlElement archiveElem in archivesNode.SelectNodes("Archive")) { ArchiveConfig archiveConfig = new ArchiveConfig(); archiveConfig.LoadFromXml(archiveElem); Archives.Add(archiveConfig); if (archiveConfig.Active && moduleCodes.Add(archiveConfig.Module.ToLowerInvariant())) { ModuleCodes.Add(archiveConfig.Module); } } } errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommonPhrases.LoadAppConfigError + ": " + ex.Message; return(false); } }