public Driver(string xmlText) { m_Devices = new List <Device>(); if (string.IsNullOrEmpty(xmlText)) { xmlText = DefaultXmlText(); } m_Doc = XDocument.Parse(xmlText); XElement configElement = m_Doc.Element(Element.Configuration); if (configElement == null) { throw new ArgumentException("Cannot find the root element \"" + Element.Configuration + "\""); } XElement driverElement = configElement.Element(Element.Driver); if (driverElement == null) { driverElement = new XElement(Element.Driver); driverElement.Add(new XAttribute(Attribute.Id, Id)); configElement.Add(driverElement); } m_Root = driverElement.Element(Element.Common); if (m_Root == null) { m_Root = new XElement(Element.Common); driverElement.Add(m_Root); } m_Description = Xml.GetElementValueText(m_Root, Element.Description, "This is an example driver", true); m_Demo = new Demo(driverElement, DeviceId.Demo); m_Devices.Add(m_Demo); m_Heater = new Heater(driverElement, DeviceId.Heater); m_Devices.Add(m_Heater); m_Pump = new Pump(driverElement, DeviceId.Pump); m_Devices.Add(m_Pump); m_AutoSampler = new AutoSampler(driverElement, DeviceId.AutoSampler); m_Devices.Add(m_AutoSampler); m_Detector = new Detector(driverElement, DeviceId.Detector); m_Devices.Add(m_Detector); m_Devices.Sort((Device device1, Device device2) => device1.Id.CompareTo(device2.Id)); }
protected Device(XElement docRoot, string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } if (docRoot == null) { throw new ArgumentNullException("docRoot"); } m_Id = id; m_Root = docRoot.Elements(Element.Device).FirstOrDefault(item => { XAttribute attribute = item.Attribute(Attribute.Id); string value = attribute != null ? attribute.Value : null; return(value == Id); }); if (m_Root == null) { m_Root = new XElement(Element.Device); Root.Add(new XAttribute(Attribute.Id, Id)); docRoot.Add(Root); } string name = m_Id.Replace('-', '_'); const string idSuffix = "_Id"; if (name.EndsWith(idSuffix)) { name = name.Substring(0, name.Length - idSuffix.Length); } name += "_Name"; m_Name = Xml.GetElementValueText(Root, Element.Name, name); }
public Demo(XElement docRoot, string id) : base(docRoot, id) { m_IsSimulated = Xml.GetElementValueBool(Root, Element.IsSimulated, true); m_FirmwareUsbAddress = Xml.GetElementValueText(Root, Element.FirmwareUsbAddress, "USB-1234567890AB"); }
public Heater(XElement docRoot, string id) : base(docRoot, id) { m_ProductDescription = Xml.GetElementValueText(Root, Element.ProductDescription, "Heat"); }