From 5fe5f50bacd37eb84c289097a56a323d550c1cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 11 May 2022 14:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Business/Plugin/ConfigMgr.cs | 82 +++++++++++++++++---- BPASmartClient.Business/Plugin/DeviceMgr.cs | 3 +- BPASmartClient/DeviceInfo.xml | 38 ---------- 3 files changed, 70 insertions(+), 53 deletions(-) diff --git a/BPASmartClient.Business/Plugin/ConfigMgr.cs b/BPASmartClient.Business/Plugin/ConfigMgr.cs index 90ff8bc5..9be28953 100644 --- a/BPASmartClient.Business/Plugin/ConfigMgr.cs +++ b/BPASmartClient.Business/Plugin/ConfigMgr.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration; using System.Xml.Linq; using System.Xml.XPath; + namespace BPASmartClient.Business { /// @@ -62,27 +63,80 @@ namespace BPASmartClient.Business deviceConfig.Name = device.Attribute("Name").Value; deviceConfig.Module = device.Attribute("Module").Value; deviceConfig.DeviceId = int.Parse(device.Attribute("DeviceId").Value); - if (null != device.Element("Parameters")) - { - foreach (var deviceParameter in device.Element("Parameters").Elements()) - { - deviceConfig.Parameters.Add(deviceParameter.Name.LocalName, deviceParameter.Value); - } - } - foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) + var Peripherals = device.XPathSelectElements("Peripherals/Peripheral"); + if (Peripherals != null) { - BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); - peripheral.Module = peripheralEl.Attribute("Module").Value; - if (null != peripheralEl.Element("Parameters")) + foreach (var Per in Peripherals) { - foreach (XElement parameter in peripheralEl.Element("Parameters").Elements()) + BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); + peripheral.Module = Per.Attribute("Module").Value; + + var Parameters = Per.Element("Parameters").Elements(); + if (Parameters != null) { - peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value); + foreach (var item in Parameters) + { + peripheral.Parameters.Add(item.Name.LocalName, item.Value); + } } + deviceConfig.Peripherals.Add(peripheral); } - deviceConfig.Peripherals.Add(peripheral); } + + + //if (null != device.Element("Parameters")) + //{ + // foreach (var deviceParameter in device.Element("Parameters").Elements()) + // { + // deviceConfig.Parameters.Add(deviceParameter.Name.LocalName, deviceParameter.Value); + // } + //} + + //var Peripheral = device.XPathSelectElements("Parameters"); + //if (null != Peripheral) + //{ + // foreach (var deviceParameter in Peripheral) + // { + // deviceConfig.Parameters.Add(deviceParameter.Name.LocalName, deviceParameter.Value); + // } + //} + + + + //if (device.Element("Peripheral") != null) + //{ + // foreach (var peripherals in device.Element("Peripheral").Elements()) + // { + // BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); + // peripheral.Module = peripherals.Attribute("Module").Value; + // if (null != peripherals.Element("Parameters")) + // { + // foreach (XElement parameter in peripherals.Element("Parameters").Elements()) + // { + // peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value); + // } + // } + // deviceConfig.Peripherals.Add(peripheral); + // } + //} + + + + + //foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) + //{ + // BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); + // peripheral.Module = peripheralEl.Attribute("Module").Value; + // if (null != peripheralEl.Element("Parameters")) + // { + // foreach (XElement parameter in peripheralEl.Element("Parameters").Elements()) + // { + // peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value); + // } + // } + // deviceConfig.Peripherals.Add(peripheral); + //} deviceConfigs.Add(deviceConfig); } } diff --git a/BPASmartClient.Business/Plugin/DeviceMgr.cs b/BPASmartClient.Business/Plugin/DeviceMgr.cs index 10b97840..a93a5e02 100644 --- a/BPASmartClient.Business/Plugin/DeviceMgr.cs +++ b/BPASmartClient.Business/Plugin/DeviceMgr.cs @@ -62,6 +62,7 @@ namespace BPASmartClient.Business foreach (var peripheral in device.Peripherals) { var peripheralTemp = Assembly.Load(peripheral.Module.Substring(0, peripheral.Module.LastIndexOf('.'))).CreateInstance(peripheral.Module) as IPeripheral; + foreach (var pars in peripheral.Parameters) { peripheralTemp.GetType().GetProperty(pars.Key).SetValue(peripheralTemp, Convert.ChangeType(pars.Value, peripheralTemp.GetType().GetProperty(pars.Key).PropertyType)); @@ -135,6 +136,6 @@ namespace BPASmartClient.Business this.devices.ForEach(device => device.Stop()); } - + } } diff --git a/BPASmartClient/DeviceInfo.xml b/BPASmartClient/DeviceInfo.xml index ea9e1d52..8995c22d 100644 --- a/BPASmartClient/DeviceInfo.xml +++ b/BPASmartClient/DeviceInfo.xml @@ -20,10 +20,6 @@ - @@ -33,29 +29,10 @@ M,M0.1,1;M,M1.0,8;M,M2.0,9;M,M8.0,4;M,M13.5,1;M,M16.0,7; - - - - - - @@ -65,21 +42,6 @@ M,M0.1,1;M,M1.0,8;M,M2.0,9;M,M8.0,4;M,M13.5,1;M,M16.0,7; - - - - -