Переглянути джерело

订单流转

样式分支
applelon 2 роки тому
джерело
коміт
5cdb2afdb3
7 змінених файлів з 41 додано та 14 видалено
  1. +7
    -1
      BPASmartClient.Business/MainConsole.cs
  2. +3
    -2
      BPASmartClient.Business/Plugin/StatusMgr.cs
  3. +1
    -1
      BPASmartClient.Device/BaseDevice.cs
  4. +18
    -3
      BPASmartClient.Helper/ThreadManage.cs
  5. +3
    -2
      BPASmartClient.MQTT/MQTTProxy.cs
  6. +1
    -1
      BPASmartClient/BPASmartClient.csproj
  7. +8
    -4
      BPASmartClient/MainWindow.xaml.cs

+ 7
- 1
BPASmartClient.Business/MainConsole.cs Переглянути файл

@@ -1,4 +1,5 @@
using HBLConsole.Communication;
using BPASmartClient.Message;
using HBLConsole.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -25,6 +26,11 @@ namespace BPASmartClient.Business
TopicDefine.GetInstance().Initialize(Plugin.GetInstance().GetPlugin<DeviceMgr>().GetDevices());
//设备开启
Plugin.GetInstance().GetPlugin<DeviceMgr>().StartService();

MessageLog.GetInstance.InfoNotify = new Action<string>((msg =>
{
Console.WriteLine(msg);
}));
}

/// <summary>


+ 3
- 2
BPASmartClient.Business/Plugin/StatusMgr.cs Переглянути файл

@@ -28,7 +28,7 @@ namespace BPASmartClient.Business
{
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>();
mqttMgr = Plugin.GetInstance().GetPlugin<MQTTMgr>();
running = true;
ThreadManage.GetInstance().Start(() =>
{
while (running)
@@ -54,7 +54,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);
mqttMgr.Publish(TOPIC.GetInstance.GetHeatbeatTopic(device.DeviceType), msg.Serialize());
mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize());
}
Thread.Sleep(1000);
}
@@ -63,6 +63,7 @@ namespace BPASmartClient.Business

public void Dispose()
{
running = false;
}
}
}

+ 1
- 1
BPASmartClient.Device/BaseDevice.cs Переглянути файл

@@ -20,7 +20,7 @@ namespace BPASmartClient.Device
/// <summary>
/// 设备所有状态
/// </summary>
public DeviceStatus Status { get; set; }
public DeviceStatus Status { get; set; } = new DeviceStatus();
/// <summary>
/// 设备名称
/// </summary>


+ 18
- 3
BPASmartClient.Helper/ThreadManage.cs Переглянути файл

@@ -13,7 +13,7 @@ namespace BPASmartClient.Helper
/// <summary>
/// 线程管理
/// </summary>
public class ThreadManage:Singleton<ThreadManage>
public class ThreadManage : Singleton<ThreadManage>
{
string guid = "871d7e28-c413-4675-8d28-64e4dca4c2d3-";
private static readonly object _lock = new object();
@@ -84,12 +84,27 @@ namespace BPASmartClient.Helper
/// </summary>
/// <param name="action"></param>
/// <param name="key"></param>
public void Start(Action action, string key)
public void Start(Action action, string key, bool isRestart = true)
{
MessageLog.GetInstance.Show($"线程 【{key}】启动");
CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource());
bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() =>
{
if (action != null) action();
try
{
if (action != null) action();
}
catch (Exception ex)
{
MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常");
if (isRestart)
{
MessageLog.GetInstance.Show($"线程 【{key}】正在重启");
CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource item1);
Threads.TryRemove(guid + key, out Task item2);
Start(action, key, isRestart);
}
}
}), CancellationTokenSources[guid + key].Token).ContinueWith(new Action<Task, object>((t, o) =>
{
ThreadStatus(t, o.ToString());


+ 3
- 2
BPASmartClient.MQTT/MQTTProxy.cs Переглянути файл

@@ -59,14 +59,15 @@ namespace BPASmartClient.MQTT

public async void Publish(string topic, string content)
{
await client.PublishAsync(topic, content);
if (client.IsConnected)
await client.PublishAsync(topic, content);
}

public async void Subscrib(params string[] topics)
{
foreach (var topic in topics)
{
await client.SubscribeAsync(new MqttTopicFilter() { Topic = topic, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce});
await client.SubscribeAsync(new MqttTopicFilter() { Topic = topic, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce });
}
}
}


+ 1
- 1
BPASmartClient/BPASmartClient.csproj Переглянути файл

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>


+ 8
- 4
BPASmartClient/MainWindow.xaml.cs Переглянути файл

@@ -1,4 +1,5 @@
using BPASmartClient.Business;
using BPA.Message;
using BPASmartClient.Business;
using BPASmartClient.EventBus;
using BPASmartClient.Model;
using BPASmartClient.Model.冰淇淋.Enum;
@@ -45,10 +46,13 @@ namespace BPASmartClient

private void Button_Click(object sender, RoutedEventArgs e)
{
new Demo_MakeCoffeeEvent() { Id = 1 }.Publish();
new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish();
new DRCoffee_CoffeeCommCmdEvent() { Id = 1,CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish();
//new Demo_MakeCoffeeEvent() { Id = 1 }.Publish();
//new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish();
//new DRCoffee_CoffeeCommCmdEvent() { Id = 1,CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish();

MorkOrderPush morkOrderPush = new MorkOrderPush() { DeviceId=2};
var temp=BPAPackage.Make(morkOrderPush, 12, BPA.Message.Enum.DeviceClientType.MORKS);
Plugin.GetInstance().GetPlugin<MQTTMgr>().Publish("DOWN/MORKS/ORDER/12", temp.Serialize());
}
}
}

Завантаження…
Відмінити
Зберегти