Exemplo n.º 1
0
        /// <summary>
        /// Loads the configuration from the specified reader.
        /// </summary>
        protected override void Load(TextReader reader)
        {
            XmlDocument xmlDoc = new();

            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("LoginOptions") is XmlNode loginOptionsNode)
            {
                LoginOptions.LoadFromXml(loginOptionsNode);
            }

            if (rootElem.SelectSingleNode("DisplayOptions") is XmlNode displayOptionsNode)
            {
                DisplayOptions.LoadFromXml(displayOptionsNode);
            }

            HashSet <string> pluginCodes = new();

            if (rootElem.SelectSingleNode("Plugins") is XmlNode pluginsNode)
            {
                foreach (XmlElement pluginElem in pluginsNode.SelectNodes("Plugin"))
                {
                    string pluginCode = ScadaUtils.RemoveFileNameSuffixes(pluginElem.GetAttribute("code"));

                    if (pluginCodes.Add(pluginCode.ToLowerInvariant())) // check uniqueness
                    {
                        PluginCodes.Add(pluginCode);
                    }
                }
            }


            if (rootElem.SelectSingleNode("PluginAssignment") is XmlNode pluginAssignmentNode)
            {
                PluginAssignment.LoadFromXml(pluginAssignmentNode);
            }

            if (rootElem.SelectSingleNode("CustomOptions") is XmlNode customOptionsNode)
            {
                foreach (XmlElement optionGroupElem in customOptionsNode.SelectNodes("OptionGroup"))
                {
                    OptionList optionList = new();
                    optionList.LoadFromXml(optionGroupElem);
                    CustomOptions[optionGroupElem.GetAttrAsString("name")] = optionList;
                }
            }
        }