/// <summary> /// Загрузить настройки приложения из файла /// </summary> public bool Load(string fileName, out string errMsg) { // очистка существующих настроек Params.SetToDefault(); CommLines.Clear(); // распознавание XML-документа XmlDocument xmlDoc = null; try { if (!File.Exists(fileName)) { throw new FileNotFoundException(string.Format(CommonPhrases.NamedFileNotFound, fileName)); } xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); // загрузка общих параметров LoadCommonParams(xmlDoc); // загрузка линий связи LoadCommLines(xmlDoc); errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommonPhrases.LoadAppSettingsError + ":" + Environment.NewLine + ex.Message; return(false); } }
/// <summary> /// Загрузить линии связи /// </summary> private void LoadCommLines(XmlDocument xmlDoc) { XmlNode commLinesNode = xmlDoc.DocumentElement.SelectSingleNode("CommLines"); if (commLinesNode != null) { XmlNodeList commLineNodes = commLinesNode.SelectNodes("CommLine"); foreach (XmlElement commLineElem in commLineNodes) { string lineNumStr = commLineElem.GetAttribute("number"); try { CommLine commLine = LoadCommLine(commLineElem); CommLines.Add(commLine); } catch (Exception ex) { throw new Exception(string.Format(CommPhrases.IncorrectLineSettings, lineNumStr) + ":" + Environment.NewLine + ex.Message); } } } }