|
- using BPASmartClient.Model;
- using System.Xml.Linq;
- using System.Xml.XPath;
-
- namespace BPASmartClient.Business
- {
- public class ConfigMgr : IPlugin
- {
- private List<DeviceConfig> deviceConfigs;
- public void Dispose()
- {
- }
-
- public void Initialize()
- {
- InitDeviceModel();
- }
-
- public List<DeviceConfig> GetDeviceConfigs()
- {
- if (null == deviceConfigs)
- InitDeviceModel();
- return deviceConfigs;
- }
-
- private void InitDeviceModel()
- {
- deviceConfigs = new List<DeviceConfig>();
- var devicePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DeviceInfo.xml");
- var xdoc = XDocument.Load(devicePath);
- var devices = xdoc.XPathSelectElements("//Device");
- foreach (var device in devices)
- {
- DeviceConfig deviceConfig = new DeviceConfig();
- deviceConfig.Name = device.Attribute("Name").Value;
- deviceConfig.Module = device.Attribute("Module").Value;
- deviceConfig.DeviceId = device.Attribute("DeviceId").Value;
-
- foreach (var peripheralEl in device.XPathSelectElements("//Peripheral"))
- {
- BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral();
- peripheral.Module = peripheralEl.Attribute("Module").Value;
- foreach (XElement parameter in peripheralEl.Element("Parameters").Elements())
- {
- peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value);
- }
- deviceConfig.Peripherals.Add(peripheral);
- }
- deviceConfigs.Add(deviceConfig);
- }
- }
-
- }
- }
|