Просмотр исходного кода

配置文件修改

样式分支
pry 2 лет назад
Родитель
Сommit
e3db5d31c3
4 измененных файлов: 74 добавлений и 162 удалений
  1. +15
    -88
      BPASmartClient.Business/Plugin/ConfigMgr.cs
  2. +26
    -58
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  3. +6
    -5
      BPASmartClient.IoT/DataVClient.cs
  4. +27
    -11
      BPASmartClient.ViewModel/DeviceMonitorViewModel.cs

+ 15
- 88
BPASmartClient.Business/Plugin/ConfigMgr.cs Просмотреть файл

@@ -30,6 +30,8 @@ namespace BPASmartClient.Business

public UriConfig uriConfig { get; set; }

public ObservableCollection<DeviceConfigModelJson> deviceConfigModelJsons { get; set; }

//Apollo地址
private string apolloUri;
private string apoid;
@@ -42,12 +44,21 @@ namespace BPASmartClient.Business

public void Initialize()
{
ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
if (File.Exists(path))
{
string JsonString = File.ReadAllText(path);
deviceConfigModelJsons = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
}
if (deviceConfigModelJsons?.Count > 0)
{
ClientId = int.Parse(deviceConfigModelJsons.ElementAt(0).ShopId);
}
//ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString();
apoid = System.Configuration.ConfigurationManager.AppSettings["AppId"].ToString();
namespa = System.Configuration.ConfigurationManager.AppSettings["Namespaces"].ToString();
//InternetInfo.OrderServer = System.Configuration.ConfigurationManager.AppSettings["OrderServiceUri"].ToString();
//InternetInfo.StockServer = System.Configuration.ConfigurationManager.AppSettings["StockServiceUri"].ToString();
InternetInfo.IsEnableTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsEnableTest"].ToString());
InitDeviceModel();
InitConfig();
@@ -65,92 +76,8 @@ namespace BPASmartClient.Business
/// </summary>
private void InitDeviceModel()
{
//var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
//string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
//deviceConfigs = new List<DeviceConfig>();
//if (File.Exists(path))
//{
// string JsonString = File.ReadAllText(path);
// var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
// if (result != null)
// {
// foreach (var shop in result)
// {
// foreach (var device in shop.deviceModels)
// {

// DeviceConfig deviceConfig = new DeviceConfig();
// deviceConfig.Name = device.DeviceName;
// deviceConfig.Module = device.DeviceNamespace;
// deviceConfig.DeviceId = int.Parse(device.DeviceId);

// foreach (var comms in device.communicationDevcies)
// {
// BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral();
// peripheral.Module = comms.CommunicationNamespace;
// }
// deviceConfigs.Add(deviceConfig);
// }
// }
// }
//}





//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 = int.Parse(device.Attribute("DeviceId").Value);

// var Peripherals = device.XPathSelectElements("Peripherals/Peripheral");
// if (Peripherals != null)
// {
// foreach (var Per in Peripherals)
// {
// BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral();
// peripheral.Module = Per.Attribute("Module").Value;

// var Parameters = Per.Element("Parameters").Elements();
// if (Parameters != null)
// {
// foreach (var item in Parameters)
// {
// peripheral.Parameters.Add(item.Name.LocalName, item.Value);
// }
// }
// deviceConfig.Peripherals.Add(peripheral);
// }
// }
// deviceConfigs.Add(deviceConfig);
//}
}

/// <summary>
/// 加载MQTT配置
/// </summary>
//private void InitMQTT()
//{
// IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
// configurationBuilder.AddApolloConfiguration(p =>
// {
// p.AppId = apoid;
// p.MetaServer = apolloUri;
// p.Namespaces = new List<string>() { namespa };
// });

// IConfiguration config = configurationBuilder.Build();
// var mqttBroker = config.GetSection("BrokerHostSettings");
// MQTT_Config = mqttBroker.Value.FromJSON<MQTT_Entity>();
// if (MQTT_Config == null) MessageLog.GetInstance.Show("获取配置数据为空!");
//}
}

public void InitConfig()
{


+ 26
- 58
BPASmartClient.Business/Plugin/DeviceMgr.cs Просмотреть файл

@@ -48,73 +48,41 @@ namespace BPASmartClient.Business
/// </summary>
private void LoadDevice()
{

#region 启动设备对象

var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
if (File.Exists(path))
var result = Plugin.GetInstance().GetPlugin<ConfigMgr>()?.deviceConfigModelJsons;
//var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
//string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
//if (File.Exists(path))
//{
//string JsonString = File.ReadAllText(path);
//var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
if (result != null)
{
string JsonString = File.ReadAllText(path);
var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
if (result != null)
foreach (var shop in result)//店铺集合
{
foreach (var shop in result)//店铺集合
foreach (var device in shop.deviceModels)//设备集合
{
foreach (var device in shop.deviceModels)//设备集合
{

string Namespace = device.DeviceNamespace.Substring(0, device.DeviceNamespace.LastIndexOf('.'));
var deviceTemp = Assembly.Load(Namespace).CreateInstance(device.DeviceNamespace) as IDevice;
deviceTemp.Name = device?.DeviceName;
deviceTemp.DeviceId = int.Parse(device.DeviceId);
string Namespace = device.DeviceNamespace.Substring(0, device.DeviceNamespace.LastIndexOf('.'));
var deviceTemp = Assembly.Load(Namespace).CreateInstance(device.DeviceNamespace) as IDevice;
deviceTemp.Name = device?.DeviceName;
deviceTemp.DeviceId = int.Parse(device.DeviceId);

//通讯模块
List<IPeripheral> peripherals = new List<IPeripheral>();
foreach (var comms in device.communicationDevcies)//通讯集合
{
string IPeripheralNamespace = comms.CommunicationNamespace.Substring(0, comms.CommunicationNamespace.LastIndexOf('.'));
var peripheralTemp = Assembly.Load(IPeripheralNamespace).CreateInstance(comms.CommunicationNamespace) as IPeripheral;
peripheralTemp.variables = comms.variables;
peripheralTemp.communicationPar = comms.communicationPar;
peripherals.Add(peripheralTemp);
}

deviceTemp.Initliaze(peripherals);
this.devices.Add(deviceTemp);
//通讯模块
List<IPeripheral> peripherals = new List<IPeripheral>();
foreach (var comms in device.communicationDevcies)//通讯集合
{
string IPeripheralNamespace = comms.CommunicationNamespace.Substring(0, comms.CommunicationNamespace.LastIndexOf('.'));
var peripheralTemp = Assembly.Load(IPeripheralNamespace).CreateInstance(comms.CommunicationNamespace) as IPeripheral;
peripheralTemp.variables = comms.variables;
peripheralTemp.communicationPar = comms.communicationPar;
peripherals.Add(peripheralTemp);
}

deviceTemp.Initliaze(peripherals);
this.devices.Add(deviceTemp);
}
}
}

#endregion



//var devices = Plugin.GetInstance().GetPlugin<ConfigMgr>().GetDeviceConfigs();
//foreach (var device in devices)
//{
// var deviceTemp = Assembly.Load(device.Module.Substring(0, device.Module.LastIndexOf('.'))).CreateInstance(device.Module) as IDevice;
// deviceTemp.Name = device.Name;
// deviceTemp.DeviceId = device.DeviceId;
// foreach (var pars in device.Parameters)
// {
// deviceTemp.GetType().GetProperty(pars.Key).SetValue(deviceTemp, Convert.ChangeType(pars.Value, deviceTemp.GetType().GetProperty(pars.Key).PropertyType));
// }

// List<IPeripheral> peripherals = new List<IPeripheral>();
// 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));
// }
// peripherals.Add(peripheralTemp);
// }
// deviceTemp.Initliaze(peripherals);
// this.devices.Add(deviceTemp);
//}
}



+ 6
- 5
BPASmartClient.IoT/DataVClient.cs Просмотреть файл

@@ -35,14 +35,15 @@ namespace BPASmartClient.IoT
public DataVClient()
{
DataVApiAddress = InternetInfo.DataVApiAddress;
ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
//ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
ClientId = Plugin.GetInstance().GetPlugin<ConfigMgr>().ClientId.ToString();
DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"].ToString();
ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString();
DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString();
StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString();
BroadcastPubTopic = InternetInfo.BroadcastPubTopic;
//MaintainTable maintainTable = new MaintainTable();
//maintainTable.Id = Guid.NewGuid().ToString();
//maintainTable.MaintainTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
@@ -85,7 +86,7 @@ namespace BPASmartClient.IoT
/// <summary>
/// 维保通知
/// </summary>
public List<MaintainTable> maintainTables = new List<MaintainTable>();
public List<MaintainTable> maintainTables = new List<MaintainTable>();
#endregion

#region API调用
@@ -122,7 +123,7 @@ namespace BPASmartClient.IoT
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
maintainTable.Id=Guid.NewGuid().ToString();
maintainTable.Id = Guid.NewGuid().ToString();
//maintainTable.MaintainTime = DateTime.Now.ToString();
//maintainTable.MaintainType = "一般";
//maintainTable.MaintainVla = "MorkS";


+ 27
- 11
BPASmartClient.ViewModel/DeviceMonitorViewModel.cs Просмотреть файл

@@ -12,6 +12,7 @@ using BPASmartClient.Model;
using System.Reflection;
using Microsoft.Toolkit.Mvvm.Input;
using System.Windows;
using BPASmartClient.Business;

namespace BPASmartClient.ViewModel
{
@@ -49,23 +50,38 @@ namespace BPASmartClient.ViewModel

private void GetData()
{
var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
if (File.Exists(path))
//var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
//string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
//if (File.Exists(path))
//{
// string JsonString = File.ReadAllText(path);
// var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
// if (result != null)
// {
// foreach (var shop in result)//店铺集合
// {
// foreach (var device in shop.deviceModels)//设备集合
// {
// Devices.Add(new Device() { Name = device.DeviceName, Namespace = device.DeviceNamespace });
// }
// }
// }
//}

var result = Plugin.GetInstance().GetPlugin<ConfigMgr>()?.deviceConfigModelJsons;
if (result != null)
{
string JsonString = File.ReadAllText(path);
var result = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
if (result != null)
foreach (var shop in result)//店铺集合
{
foreach (var shop in result)//店铺集合
foreach (var device in shop.deviceModels)//设备集合
{
foreach (var device in shop.deviceModels)//设备集合
{
Devices.Add(new Device() { Name = device.DeviceName, Namespace = device.DeviceNamespace });
}
Devices.Add(new Device() { Name = device.DeviceName, Namespace = device.DeviceNamespace });
}
}
}



if (Devices.Count > 0)
{
Devices.ElementAt(0).IsChecked = true;


Загрузка…
Отмена
Сохранить