You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

94 lines
3.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using HBLConsole.Model;
  7. using HBLConsole.Service;
  8. using HBLConsole.GVL;
  9. using HBLConsole.Communication;
  10. using BPA.Message;
  11. using HBLConsole.Business;
  12. using HBLConsole.Factory;
  13. using BPA.Message.Enum;
  14. namespace HBLConsole.MainConsole
  15. {
  16. public class Main
  17. {
  18. private volatile static Main _Instance;
  19. public static Main GetInstance => _Instance ?? (_Instance = new Main());
  20. private Main() { }
  21. List<string> Topics = new List<string>();
  22. public void DataInit()
  23. {
  24. Json<SetPar>.Read();
  25. if (Enum.TryParse(Json<SetPar>.Data.ClientDeviceType, out DeviceClientType dct))
  26. {
  27. GeneralConfig.DeviceType = dct;
  28. }
  29. else { GeneralConfig.DeviceType = DeviceClientType.MORKS; }
  30. Json<MorkOrderPushPar>.Read();
  31. Json<BatchingInfoPar>.Read();
  32. Json<SimOrderConfig>.Read();
  33. Json<KeepDataBase>.Read();
  34. MessageLog.GetInstance.Show($"启动【{GeneralConfig.DeviceType}】设备");
  35. }
  36. public void DataSave()
  37. {
  38. Json<MorkOrderPushPar>.Save();
  39. Json<BatchingInfoPar>.Save();
  40. Json<SetPar>.Save();
  41. Json<SimOrderConfig>.Save();
  42. Json<KeepDataBase>.Save();
  43. TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo");
  44. }
  45. public void BusinessInit()
  46. {
  47. ThreadOperate.GetInstance.Start(new Action(() =>
  48. {
  49. InternetInfo.ConfigInit();//从 consul 获取配置数据
  50. //SimpleFactory.GetInstance.DeviceInit();//设备初始化
  51. Topics.Clear();
  52. Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
  53. Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
  54. //MQTT 连接成功
  55. MqttHelper.GetInstance.ConnectOk = new Action(() =>
  56. {
  57. SimpleFactory.GetInstance.DeviceInit();//设备初始化
  58. MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅
  59. //w IotReport.GetInstance.Init();//IOT 上报
  60. HeartbeatReport.GetInstance.Init();//心跳上报
  61. ServerData.GetInstance.Init();//数据处理初始化
  62. //接收MQTT消息
  63. MqttHelper.GetInstance.MqttReceive = new Action<MQTTnet.MqttApplicationMessageReceivedEventArgs>((receivce) =>
  64. {
  65. ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload));
  66. });
  67. });
  68. //MQTT 重连成功
  69. MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); });
  70. //MQTT 连接
  71. MqttHelper.GetInstance.MqttInitAsync(InternetInfo.MqttUserName, InternetInfo.MqttPassword,
  72. InternetInfo.MqttAddress, InternetInfo.MqttPort, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
  73. }), "业务逻辑初始化");
  74. }
  75. }
  76. }