Ejemplo n.º 1
0
        /// <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 (xmlDoc.DocumentElement.SelectSingleNode("Connections") is XmlNode connectionsNode)
                {
                    foreach (XmlNode connectionNode in connectionsNode.SelectNodes("Connection"))
                    {
                        ConnectionOptions connectionOptions = new ConnectionOptions();
                        connectionOptions.LoadFromXml(connectionNode);
                        Connections[connectionOptions.Name] = connectionOptions;
                    }
                }

                if (rootElem.SelectSingleNode("DataSources") is XmlNode dataSourcesNode)
                {
                    foreach (XmlElement dataSourceElem in dataSourcesNode.SelectNodes("DataSource"))
                    {
                        DataSourceConfig dataSourceConfig = new DataSourceConfig();
                        dataSourceConfig.LoadFromXml(dataSourceElem);
                        DataSources.Add(dataSourceConfig);
                    }
                }

                if (rootElem.SelectSingleNode("Lines") is XmlNode linesNode)
                {
                    foreach (XmlElement lineElem in linesNode.SelectNodes("Line"))
                    {
                        LineConfig lineConfig = new LineConfig();
                        lineConfig.LoadFromXml(lineElem);
                        Lines.Add(lineConfig);
                    }
                }

                FillDriverCodes();
                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.LoadAppConfigError + ": " + ex.Message;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the configuration from the specified reader.
        /// </summary>
        protected override void Load(TextReader reader)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(reader);
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (rootElem.SelectSingleNode("GeneralOptions") is XmlNode generalOptionsNode)
            {
                GeneralOptions.LoadFromXml(generalOptionsNode);
            }

            if (rootElem.SelectSingleNode("ConnectionOptions") is XmlNode connectionOptionsNode)
            {
                ConnectionOptions.LoadFromXml(connectionOptionsNode);
            }

            if (rootElem.SelectSingleNode("DataSources") is XmlNode dataSourcesNode)
            {
                foreach (XmlElement dataSourceElem in dataSourcesNode.SelectNodes("DataSource"))
                {
                    DataSourceConfig dataSourceConfig = new DataSourceConfig();
                    dataSourceConfig.LoadFromXml(dataSourceElem);
                    DataSources.Add(dataSourceConfig);
                }
            }

            if (rootElem.SelectSingleNode("Lines") is XmlNode linesNode)
            {
                foreach (XmlElement lineElem in linesNode.SelectNodes("Line"))
                {
                    LineConfig lineConfig = new LineConfig {
                        Parent = this
                    };
                    lineConfig.LoadFromXml(lineElem);
                    Lines.Add(lineConfig);
                }
            }

            FillDriverCodes();
        }