Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public LineConfig()
 {
     Active        = true;
     IsBound       = true;
     CommLineNum   = 0;
     Name          = "";
     LineOptions   = new LineOptions();
     Channel       = new ChannelConfig();
     CustomOptions = new OptionList();
     DevicePolling = new List <DeviceConfig>();
 }
Exemple #2
0
        /// <summary>
        /// Saves the configuration into the XML node.
        /// </summary>
        public void SaveToXml(XmlElement xmlElem)
        {
            if (xmlElem == null)
            {
                throw new ArgumentNullException(nameof(xmlElem));
            }

            xmlElem.SetAttribute("active", Active);
            xmlElem.SetAttribute("isBound", IsBound);
            xmlElem.SetAttribute("number", CommLineNum);
            xmlElem.SetAttribute("name", Name);
            LineOptions.SaveToXml(xmlElem.AppendElem("LineOptions"));
            Channel.SaveToXml(xmlElem.AppendElem("Channel"));
            CustomOptions.SaveToXml(xmlElem.AppendElem("CustomOptions"));

            XmlElement devicePollingElem = xmlElem.AppendElem("DevicePolling");

            foreach (DeviceConfig device in DevicePolling)
            {
                device.SaveToXml(devicePollingElem.AppendElem("Device"));
            }
        }
Exemple #3
0
        /// <summary>
        /// Loads the configuration from the XML node.
        /// </summary>
        public void LoadFromXml(XmlElement xmlElem)
        {
            if (xmlElem == null)
            {
                throw new ArgumentNullException(nameof(xmlElem));
            }

            Active      = xmlElem.GetAttrAsBool("active");
            IsBound     = xmlElem.GetAttrAsBool("isBound");
            CommLineNum = xmlElem.GetAttrAsInt("number");
            Name        = xmlElem.GetAttrAsString("name");

            if (xmlElem.SelectSingleNode("LineOptions") is XmlNode lineOptionsNode)
            {
                LineOptions.LoadFromXml(lineOptionsNode);
            }

            if (xmlElem.SelectSingleNode("Channel") is XmlElement channelElem)
            {
                Channel.LoadFromXml(channelElem);
            }

            if (xmlElem.SelectSingleNode("CustomOptions") is XmlNode customOptionsNode)
            {
                CustomOptions.LoadFromXml(customOptionsNode);
            }

            if (xmlElem.SelectSingleNode("DevicePolling") is XmlNode devicePollingNode)
            {
                foreach (XmlElement deviceElem in devicePollingNode.SelectNodes("Device"))
                {
                    DeviceConfig deviceConfig = new DeviceConfig {
                        Parent = this
                    };
                    deviceConfig.LoadFromXml(deviceElem);
                    DevicePolling.Add(deviceConfig);
                }
            }
        }