예제 #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;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Sets the default values.
 /// </summary>
 protected override void SetToDefault()
 {
     GeneralOptions    = new GeneralOptions();
     ConnectionOptions = new ConnectionOptions();
     LoginOptions      = new LoginOptions();
     DisplayOptions    = new DisplayOptions();
     PluginCodes       = new List <string>();
     PluginAssignment  = new PluginAssignment();
     CustomOptions     = new SortedList <string, OptionList>();
 }
예제 #3
0
        /// <summary>
        /// Saves the configuration to the specified writer.
        /// </summary>
        protected override void Save(TextWriter writer)
        {
            XmlDocument    xmlDoc  = new();
            XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDoc.AppendChild(xmlDecl);

            XmlElement rootElem = xmlDoc.CreateElement("ScadaWebConfig");

            xmlDoc.AppendChild(rootElem);

            GeneralOptions.SaveToXml(rootElem.AppendElem("GeneralOptions"));
            ConnectionOptions.SaveToXml(rootElem.AppendElem("ConnectionOptions"));
            LoginOptions.SaveToXml(rootElem.AppendElem("LoginOptions"));
            DisplayOptions.SaveToXml(rootElem.AppendElem("DisplayOptions"));

            XmlElement pluginsElem = rootElem.AppendElem("Plugins");

            foreach (string pluginCode in PluginCodes)
            {
                pluginsElem.AppendElem("Plugin").SetAttribute("code", pluginCode);
            }

            PluginAssignment.SaveToXml(rootElem.AppendElem("PluginAssignment"));

            XmlElement customOptionsElem = rootElem.AppendElem("CustomOptions");

            foreach (KeyValuePair <string, OptionList> pair in CustomOptions)
            {
                XmlElement optionGroupElem = customOptionsElem.AppendElem("OptionGroup");
                optionGroupElem.SetAttribute("name", pair.Key);
                pair.Value.SaveToXml(optionGroupElem);
            }

            xmlDoc.Save(writer);
        }