pry 2 years ago
parent
commit
790fb14146
8 changed files with 39 additions and 9 deletions
  1. +1
    -2
      BPASmartClient.Business/MainConsole.cs
  2. +4
    -0
      BPASmartClient.Business/Plugin/ConfigMgr.cs
  3. +6
    -0
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  4. +1
    -0
      BPASmartClient.Business/Plugin/IPlugin.cs
  5. +10
    -2
      BPASmartClient.Business/Plugin/MQTTMgr.cs
  6. +6
    -3
      BPASmartClient.Business/Plugin/OrderProxy.cs
  7. +4
    -1
      BPASmartClient.Business/Plugin/Plugin.cs
  8. +7
    -1
      BPASmartClient.Business/Plugin/StatusMgr.cs

+ 1
- 2
BPASmartClient.Business/MainConsole.cs View File

@@ -22,8 +22,7 @@ namespace BPASmartClient.Business
InternetInfo.InitConfig();
//业务插件初始化
Plugin.GetInstance().Init();
//主题初始化
TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin<DeviceMgr>().GetDevices());
//设备开启
Plugin.GetInstance().GetPlugin<DeviceMgr>().StartService();



+ 4
- 0
BPASmartClient.Business/Plugin/ConfigMgr.cs View File

@@ -95,6 +95,10 @@ namespace BPASmartClient.Business
MQTT_Config = mqttBroker.Value.FromJSON<MQTT_Entity>();
}

public void Start()
{
}

public class MQTT_Entity
{
public string Host { get; set; }


+ 6
- 0
BPASmartClient.Business/Plugin/DeviceMgr.cs View File

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

}
}

+ 1
- 0
BPASmartClient.Business/Plugin/IPlugin.cs View File

@@ -12,5 +12,6 @@ namespace BPASmartClient.Business
public interface IPlugin:IDisposable
{
void Initialize();
void Start();
}
}

+ 10
- 2
BPASmartClient.Business/Plugin/MQTTMgr.cs View File

@@ -32,8 +32,15 @@ namespace BPASmartClient.Business
//消息处理者
private List<RecivedHandle> messageRecives = new List<RecivedHandle>();
public void Initialize()
{
}

public void Start()
{
running = true;
//主题初始化
TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin<DeviceMgr>().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();
}

}
}

+ 6
- 3
BPASmartClient.Business/Plugin/OrderProxy.cs View File

@@ -31,9 +31,12 @@ namespace BPASmartClient.Business
/// </summary>
public void Initialize()
{
running = true;
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>();
}

public void Start()
{
running = true;
Plugin.GetInstance().GetPlugin<MQTTMgr>().SetMessageReciveHandler(delegate (IMessage orderInfo)
{
if (orderInfo == null) return;
@@ -49,8 +52,6 @@ namespace BPASmartClient.Business
});

EventBus.EventBus.GetInstance().Subscribe<OrderStatusChangedEvent>(0, OrderStatusChangedHandle);


}

private void StartTargetDeviceOrderJob(int deviceId)
@@ -111,5 +112,7 @@ namespace BPASmartClient.Business
{
running = false;
}

}
}

+ 4
- 1
BPASmartClient.Business/Plugin/Plugin.cs View File

@@ -26,7 +26,10 @@ namespace BPASmartClient.Business
}
});

plugins.ForEach(p => p.Initialize());
plugins.ForEach(p => {
p.Initialize();
p.Start();
});
}

public T GetPlugin<T>() where T : IPlugin


+ 7
- 1
BPASmartClient.Business/Plugin/StatusMgr.cs View File

@@ -28,6 +28,10 @@ namespace BPASmartClient.Business
{
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>();
mqttMgr = Plugin.GetInstance().GetPlugin<MQTTMgr>();
}

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;
}

}
}

Loading…
Cancel
Save