diff --git a/BPASmartClient.Business/MainConsole.cs b/BPASmartClient.Business/MainConsole.cs index 32fecfd9..2b72eb67 100644 --- a/BPASmartClient.Business/MainConsole.cs +++ b/BPASmartClient.Business/MainConsole.cs @@ -22,8 +22,7 @@ namespace BPASmartClient.Business InternetInfo.InitConfig(); //业务插件初始化 Plugin.GetInstance().Init(); - //主题初始化 - TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin().GetDevices()); + //设备开启 Plugin.GetInstance().GetPlugin().StartService(); diff --git a/BPASmartClient.Business/Plugin/ConfigMgr.cs b/BPASmartClient.Business/Plugin/ConfigMgr.cs index 95f693a8..05cc195a 100644 --- a/BPASmartClient.Business/Plugin/ConfigMgr.cs +++ b/BPASmartClient.Business/Plugin/ConfigMgr.cs @@ -95,6 +95,10 @@ namespace BPASmartClient.Business MQTT_Config = mqttBroker.Value.FromJSON(); } + public void Start() + { + } + public class MQTT_Entity { public string Host { get; set; } diff --git a/BPASmartClient.Business/Plugin/DeviceMgr.cs b/BPASmartClient.Business/Plugin/DeviceMgr.cs index 7c05e85d..176d5a04 100644 --- a/BPASmartClient.Business/Plugin/DeviceMgr.cs +++ b/BPASmartClient.Business/Plugin/DeviceMgr.cs @@ -29,6 +29,10 @@ namespace BPASmartClient.Business } public void Initialize() + { + } + + public void Start() { LoadDevice(); } @@ -126,5 +130,7 @@ namespace BPASmartClient.Business { this.devices.ForEach(device => device.Stop()); } + + } } diff --git a/BPASmartClient.Business/Plugin/IPlugin.cs b/BPASmartClient.Business/Plugin/IPlugin.cs index f3204909..88931d5c 100644 --- a/BPASmartClient.Business/Plugin/IPlugin.cs +++ b/BPASmartClient.Business/Plugin/IPlugin.cs @@ -12,5 +12,6 @@ namespace BPASmartClient.Business public interface IPlugin:IDisposable { void Initialize(); + void Start(); } } diff --git a/BPASmartClient.Business/Plugin/MQTTMgr.cs b/BPASmartClient.Business/Plugin/MQTTMgr.cs index 1f507263..29b5b84b 100644 --- a/BPASmartClient.Business/Plugin/MQTTMgr.cs +++ b/BPASmartClient.Business/Plugin/MQTTMgr.cs @@ -32,8 +32,15 @@ namespace BPASmartClient.Business //消息处理者 private List messageRecives = new List(); public void Initialize() + { + + } + + public void Start() { running = true; + //主题初始化 + TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin().GetDevices()); //MQTT 连接成功 mqttProxy.Connected = new Action(() => { @@ -66,7 +73,8 @@ namespace BPASmartClient.Business { if (package.Message != null) { - for (int i = messageRecives.Count - 1; i >= 0; i--) { + for (int i = messageRecives.Count - 1; i >= 0; i--) + { messageRecives[i]?.Invoke(package.Message); } } @@ -104,6 +112,6 @@ namespace BPASmartClient.Business messageRecives.Clear(); } - + } } diff --git a/BPASmartClient.Business/Plugin/OrderProxy.cs b/BPASmartClient.Business/Plugin/OrderProxy.cs index 91925ed0..215b8c55 100644 --- a/BPASmartClient.Business/Plugin/OrderProxy.cs +++ b/BPASmartClient.Business/Plugin/OrderProxy.cs @@ -31,9 +31,12 @@ namespace BPASmartClient.Business /// public void Initialize() { - running = true; deviceMgr = Plugin.GetInstance().GetPlugin(); + } + public void Start() + { + running = true; Plugin.GetInstance().GetPlugin().SetMessageReciveHandler(delegate (IMessage orderInfo) { if (orderInfo == null) return; @@ -49,8 +52,6 @@ namespace BPASmartClient.Business }); EventBus.EventBus.GetInstance().Subscribe(0, OrderStatusChangedHandle); - - } private void StartTargetDeviceOrderJob(int deviceId) @@ -111,5 +112,7 @@ namespace BPASmartClient.Business { running = false; } + + } } diff --git a/BPASmartClient.Business/Plugin/Plugin.cs b/BPASmartClient.Business/Plugin/Plugin.cs index c8865f65..4045b95d 100644 --- a/BPASmartClient.Business/Plugin/Plugin.cs +++ b/BPASmartClient.Business/Plugin/Plugin.cs @@ -26,7 +26,10 @@ namespace BPASmartClient.Business } }); - plugins.ForEach(p => p.Initialize()); + plugins.ForEach(p => { + p.Initialize(); + p.Start(); + }); } public T GetPlugin() where T : IPlugin diff --git a/BPASmartClient.Business/Plugin/StatusMgr.cs b/BPASmartClient.Business/Plugin/StatusMgr.cs index 1d1b32f4..e4fb4bb6 100644 --- a/BPASmartClient.Business/Plugin/StatusMgr.cs +++ b/BPASmartClient.Business/Plugin/StatusMgr.cs @@ -28,6 +28,10 @@ namespace BPASmartClient.Business { deviceMgr = Plugin.GetInstance().GetPlugin(); mqttMgr = Plugin.GetInstance().GetPlugin(); + } + + public void Start() + { running = true; ThreadManage.GetInstance().Start(() => { @@ -53,7 +57,7 @@ namespace BPASmartClient.Business { wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus(); deviceStatus.Healthy = device.IsHealth ? BPA.Message.Enum.DeviceHealthy.Health : BPA.Message.Enum.DeviceHealthy.UnHealth; - var msg=BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType); + var msg = BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType); mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize()); } Thread.Sleep(1000); @@ -65,5 +69,7 @@ namespace BPASmartClient.Business { running = false; } + + } }