/// <summary> /// Loads the settings 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("PathOptions") is XmlNode pathOptionsNode) { PathOptions.LoadFromXml(pathOptionsNode); } if (rootElem.SelectSingleNode("ChannelOptions") is XmlNode channelOptionsNode) { ChannelOptions.LoadFromXml(channelOptionsNode); } errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommonPhrases.LoadAppSettingsError + ": " + ex.Message; return(false); } }
/// <summary> /// Loads the settings 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("PathOptions") is XmlNode pathOptionsNode) { PathOptions.LoadFromXml(pathOptionsNode); } if (rootElem.SelectSingleNode("ChannelOptions") is XmlNode channelOptionsNode) { ChannelOptions.LoadFromXml(channelOptionsNode); } if (rootElem.SelectSingleNode("FileAssociations") is XmlNode fileAssociationsNode) { foreach (XmlElement associationElem in fileAssociationsNode.SelectNodes("Association")) { string ext = associationElem.GetAttrAsString("ext").ToLowerInvariant(); string path = associationElem.GetAttrAsString("path"); FileAssociations[ext] = path; } } errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommonPhrases.LoadAppSettingsError + ": " + ex.Message; return(false); } }