public override IDeviceConfiguration[] ReadConfigurations() { var result = new List<IDeviceConfiguration>(); using (var reader = XmlReader.Create(this.ConfigurationFile)) { while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) continue; if (!reader.Name.Equals("device")) continue; var element = XNode.ReadFrom(reader) as XElement; if (element == null) continue; var name = this.GetInnerElementValue(element, "name"); var handshake = this.GetInnerElementValue(element, "handshake"); var connectionConfiguration = new SerialConnectionConfiguration(); var protocol = element.Descendants("protocol").FirstOrDefault(); if (protocol != null) { var port = this.GetInnerElementValue(protocol, "port"); var baudrate = this.GetInnerElementValue(protocol, "baudrate"); var parity = this.GetInnerElementValue(protocol, "parity"); var databits = this.GetInnerElementValue(protocol, "databits"); var stopbits = this.GetInnerElementValue(protocol, "stopbits"); var readperiod = this.GetInnerElementValue(protocol, "readperiod"); var checksumEnabled = this.GetInnerElementValue(protocol, "checksum"); connectionConfiguration.PortName = port; connectionConfiguration.Baudrate = Convert.ToInt32(baudrate); connectionConfiguration.Parity = (Parity)Convert.ToInt32(parity); connectionConfiguration.DataBits = Convert.ToInt32(databits); connectionConfiguration.StopBits = (StopBits)Convert.ToInt32(stopbits); connectionConfiguration.ReadPeriod = Convert.ToInt32(readperiod); connectionConfiguration.ChecksumEnabled = Convert.ToBoolean(checksumEnabled); } var panelConfigurationList = new List<PanelConfiguration>(); var settlementElement = element.Descendants("settlement").FirstOrDefault(); if (settlementElement != null) { panelConfigurationList.AddRange(from panelConfigElement in settlementElement.Descendants("panel") let id = panelConfigElement.Attribute("id").Value let panelName = panelConfigElement.Attribute("name").Value let regions = this.ParseRegions(panelConfigElement.Descendants("region")) select new PanelConfiguration { Id = Convert.ToInt32(id), Name = panelName, RegionConfigurations = regions }); } var handshakeValue = handshake == null ? HandshakeType.None : handshake.ToEnum<HandshakeType>(); var deviceConfiguration = new HcsDeviceConfiguration(name, handshakeValue, connectionConfiguration) { Settlement = panelConfigurationList }; result.Add(deviceConfiguration); } } return result.ToArray(); }
public HcsDeviceConfiguration(string name, HandshakeType handshake, SerialConnectionConfiguration connectionConfiguration) : base(name, handshake, connectionConfiguration) { }