From e3db5d31c380d2344c3e7b7c2d201b8f95a7a2aa 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: Fri, 27 May 2022 13:03:40 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=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 | 103 +++--------------- BPASmartClient.Business/Plugin/DeviceMgr.cs | 84 +++++--------- BPASmartClient.IoT/DataVClient.cs | 11 +- .../DeviceMonitorViewModel.cs | 38 +++++-- 4 files changed, 74 insertions(+), 162 deletions(-) diff --git a/BPASmartClient.Business/Plugin/ConfigMgr.cs b/BPASmartClient.Business/Plugin/ConfigMgr.cs index dd49de63..9d56d1e2 100644 --- a/BPASmartClient.Business/Plugin/ConfigMgr.cs +++ b/BPASmartClient.Business/Plugin/ConfigMgr.cs @@ -30,6 +30,8 @@ namespace BPASmartClient.Business public UriConfig uriConfig { get; set; } + public ObservableCollection 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>(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 /// private void InitDeviceModel() { - //var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig"); - //string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json"; - //deviceConfigs = new List(); - //if (File.Exists(path)) - //{ - // string JsonString = File.ReadAllText(path); - // var result = JsonConvert.DeserializeObject>(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(); - //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); - //} - } - /// - /// 加载MQTT配置 - /// - //private void InitMQTT() - //{ - // IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()); - // configurationBuilder.AddApolloConfiguration(p => - // { - // p.AppId = apoid; - // p.MetaServer = apolloUri; - // p.Namespaces = new List() { namespa }; - // }); - - // IConfiguration config = configurationBuilder.Build(); - // var mqttBroker = config.GetSection("BrokerHostSettings"); - // MQTT_Config = mqttBroker.Value.FromJSON(); - // if (MQTT_Config == null) MessageLog.GetInstance.Show("获取配置数据为空!"); - //} + } public void InitConfig() { diff --git a/BPASmartClient.Business/Plugin/DeviceMgr.cs b/BPASmartClient.Business/Plugin/DeviceMgr.cs index 3373ed91..cc2245e9 100644 --- a/BPASmartClient.Business/Plugin/DeviceMgr.cs +++ b/BPASmartClient.Business/Plugin/DeviceMgr.cs @@ -48,73 +48,41 @@ namespace BPASmartClient.Business /// 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()?.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>(JsonString); + if (result != null) { - string JsonString = File.ReadAllText(path); - var result = JsonConvert.DeserializeObject>(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 peripherals = new List(); - 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 peripherals = new List(); + 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().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 peripherals = new List(); - // 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); //} } diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index a560ca08..b3f1063a 100644 --- a/BPASmartClient.IoT/DataVClient.cs +++ b/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().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 /// /// 维保通知 /// - public List maintainTables = new List(); + public List maintainTables = new List(); #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"; diff --git a/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs b/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs index fab22475..da038d99 100644 --- a/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs +++ b/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>(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()?.deviceConfigModelJsons; + if (result != null) { - string JsonString = File.ReadAllText(path); - var result = JsonConvert.DeserializeObject>(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; From 73f2a17f0d8b484a9c1dc172ce3bbf4dbff23155 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: Fri, 27 May 2022 13:57:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.ViewModel/LogViewModel.cs | 28 +++++++++++++----------- BPASmartClient/App.config | 3 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 31f47aaa..aeef16f1 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -1,4 +1,5 @@ -using BPASmartClient.Helper; +using BPASmartClient.Business; +using BPASmartClient.Helper; using BPASmartClient.IoT; using BPASmartClient.Message; using BPASmartClient.Model; @@ -30,9 +31,9 @@ namespace BPASmartClient.ViewModel public DispatcherTimer UpDataFileTimer; //定时清除界面日志 public DispatcherTimer dispatcherTimer; - public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); + //public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); public ObservableCollection LogDataGridData { get; set; } - private ObservableCollection _LogModels;public ObservableCollection LogDataGrid + private ObservableCollection _LogModels; public ObservableCollection LogDataGrid { get { @@ -46,7 +47,7 @@ namespace BPASmartClient.ViewModel OnPropertyChanged("LogDataGrid"); } } - private bool _RealTimeModel = true;public bool RealTimeModel + private bool _RealTimeModel = true; public bool RealTimeModel { get { @@ -60,7 +61,7 @@ namespace BPASmartClient.ViewModel OnPropertyChanged("RealTimeModel"); } } - private bool _TimedClear = true;public bool TimedClear + private bool _TimedClear = true; public bool TimedClear { get { @@ -192,7 +193,7 @@ namespace BPASmartClient.ViewModel logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s); DataVClient.GetInstance().HttpAddLog(new LogTable { - ClientId = ClientId, + ClientId = Plugin.GetInstance().GetPlugin().ClientId.ToString(), LogTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), LogType = "严重", LogMessage = s, @@ -225,7 +226,7 @@ namespace BPASmartClient.ViewModel { if (LogDataGridData.Count > 200) { - LogModel logModel= LogDataGridData.Last(); + LogModel logModel = LogDataGridData.Last(); DeleteLog(logModel); LogDataGridData.Remove(logModel); } @@ -247,7 +248,7 @@ namespace BPASmartClient.ViewModel /// public void AddLog(LogModel logModel) { - BookEx book= SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == logModel.type); + BookEx book = SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == logModel.type); if (book != null) { LogDataGrid.Insert(0, logModel); @@ -260,7 +261,8 @@ namespace BPASmartClient.ViewModel public void RefreshLog() { LogDataGrid.Clear(); - LogDataGridData?.ToList().ForEach(b => { + LogDataGridData?.ToList().ForEach(b => + { BookEx book = SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == b.type); if (book != null) @@ -268,15 +270,15 @@ namespace BPASmartClient.ViewModel LogDataGrid.Add(b); } }); - + } /// /// 删除日志 /// public void DeleteLog(LogModel logModel) { - LogModel log= LogDataGrid?.ToList().Find(par => par == logModel); - if(log!=null) LogDataGrid.Remove(log); + LogModel log = LogDataGrid?.ToList().Find(par => par == logModel); + if (log != null) LogDataGrid.Remove(log); } /// @@ -344,7 +346,7 @@ namespace BPASmartClient.ViewModel SelectBookExs.Clear(); foreach (BookEx item in bookExs) { - builder.Append(item.BookN.Name.Replace("日志","") + ","); + builder.Append(item.BookN.Name.Replace("日志", "") + ","); SelectBookExs.Add((BookEx)item); } SelectedText = builder == null ? string.Empty : builder.ToString(); diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index dd930bf7..4e21d83c 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -3,9 +3,8 @@ - + -