Bladeren bron

配置文件读取修改

样式分支
pry 2 jaren geleden
bovenliggende
commit
5fe5f50bac
3 gewijzigde bestanden met toevoegingen van 70 en 53 verwijderingen
  1. +68
    -14
      BPASmartClient.Business/Plugin/ConfigMgr.cs
  2. +2
    -1
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  3. +0
    -38
      BPASmartClient/DeviceInfo.xml

+ 68
- 14
BPASmartClient.Business/Plugin/ConfigMgr.cs Bestand weergeven

@@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration;
using System.Xml.Linq;
using System.Xml.XPath;


namespace BPASmartClient.Business
{
/// <summary>
@@ -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);
}
}


+ 2
- 1
BPASmartClient.Business/Plugin/DeviceMgr.cs Bestand weergeven

@@ -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());
}

}
}

+ 0
- 38
BPASmartClient/DeviceInfo.xml Bestand weergeven

@@ -20,10 +20,6 @@
</Device>

<Device Name="MorkF" Module="BPASmartClient.MorkF.Control_MorkF" DeviceId="2">
<!--<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>-->
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters>
@@ -33,29 +29,10 @@
<PLCReadAddress>M,M0.1,1;M,M1.0,8;M,M2.0,9;M,M8.0,4;M,M13.5,1;M,M16.0,7;</PLCReadAddress>
</Parameters>
</Peripheral>

<!--<Peripheral Module="BPASmartClient.MORKSM.BK.PLC.MorksMachine">
<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>
</Peripheral>-->

<!--<Peripheral Module="BPASmartClient.KLMCoffee.CoffeeMachine">
<Parameters>
<PortName>COM8</PortName>
<BaudRate>38400</BaudRate>
</Parameters>
</Peripheral>-->

</Peripherals>
</Device>

<Device Name="Morks" Module="BPASmartClient.MorkS.Control" DeviceId="3">
<!--<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>-->
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters>
@@ -65,21 +42,6 @@
<PLCReadAddress>M,M0.1,1;M,M1.0,8;M,M2.0,9;M,M8.0,4;M,M13.5,1;M,M16.0,7;</PLCReadAddress>
</Parameters>
</Peripheral>

<!--<Peripheral Module="BPASmartClient.MORKSM.BK.PLC.MorksMachine">
<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>
</Peripheral>-->

<!--<Peripheral Module="BPASmartClient.KLMCoffee.CoffeeMachine">
<Parameters>
<PortName>COM8</PortName>
<BaudRate>38400</BaudRate>
</Parameters>
</Peripheral>-->

</Peripherals>
</Device>



Laden…
Annuleren
Opslaan