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;