终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.8 KiB

  1. using BPASmartClient.Model;
  2. using System.Xml.Linq;
  3. using System.Xml.XPath;
  4. namespace BPASmartClient.Business
  5. {
  6. public class ConfigMgr : IPlugin
  7. {
  8. private List<DeviceConfig> deviceConfigs;
  9. public void Dispose()
  10. {
  11. }
  12. public void Initialize()
  13. {
  14. InitDeviceModel();
  15. }
  16. public List<DeviceConfig> GetDeviceConfigs()
  17. {
  18. if (null == deviceConfigs)
  19. InitDeviceModel();
  20. return deviceConfigs;
  21. }
  22. private void InitDeviceModel()
  23. {
  24. deviceConfigs = new List<DeviceConfig>();
  25. var devicePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DeviceInfo.xml");
  26. var xdoc = XDocument.Load(devicePath);
  27. var devices = xdoc.XPathSelectElements("//Device");
  28. foreach (var device in devices)
  29. {
  30. DeviceConfig deviceConfig = new DeviceConfig();
  31. deviceConfig.Name = device.Attribute("Name").Value;
  32. deviceConfig.Module = device.Attribute("Module").Value;
  33. deviceConfig.DeviceId = device.Attribute("DeviceId").Value;
  34. foreach (var peripheralEl in device.XPathSelectElements("//Peripheral"))
  35. {
  36. BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral();
  37. peripheral.Module = peripheralEl.Attribute("Module").Value;
  38. foreach (XElement parameter in peripheralEl.Element("Parameters").Elements())
  39. {
  40. peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value);
  41. }
  42. deviceConfig.Peripherals.Add(peripheral);
  43. }
  44. deviceConfigs.Add(deviceConfig);
  45. }
  46. }
  47. }
  48. }