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.
 
 

82 lines
2.8 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. namespace HBLConsole.MainConsole
  14. {
  15. public class Main
  16. {
  17. private volatile static Main _Instance;
  18. public static Main GetInstance => _Instance ?? (_Instance = new Main());
  19. private Main() { }
  20. List<string> Topics = new List<string>();
  21. public void DataInit()
  22. {
  23. Json<MorkOrderPushPar>.GetInstance.Read();
  24. Json<BatchingInfoPar>.GetInstance.Read();
  25. }
  26. public void DataSave()
  27. {
  28. Json<MorkOrderPushPar>.GetInstance.Save();
  29. Json<BatchingInfoPar>.GetInstance.Save();
  30. TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo");
  31. }
  32. public void BusinessInit()
  33. {
  34. Topics.Clear();
  35. Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId));
  36. Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId));
  37. ThreadManagerment.GetInstance.Start(new Action(() =>
  38. {
  39. InternetInfo.GetInstance.ConfigInit();//从 consul 获取配置数据
  40. SimpleFactory.GetInstance.DeviceInit();//设备初始化
  41. //MQTT 连接成功
  42. MqttHelper.GetInstance.ConnectOk = new Action(() =>
  43. {
  44. MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅
  45. HeartbeatReport.GetInstance.Init();//心跳上报
  46. ServerData.GetInstance.Init();//数据处理初始化
  47. //接收MQTT消息
  48. MqttHelper.GetInstance.MqttReceive = new Action<MQTTnet.MqttApplicationMessageReceivedEventArgs>((receivce) =>
  49. {
  50. ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload));
  51. });
  52. });
  53. //MQTT 重连成功
  54. MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); });
  55. //MQTT 连接
  56. MqttHelper.GetInstance.MqttInitAsync(InternetInfo.GetInstance.MqttUserName,
  57. InternetInfo.GetInstance.MqttPassword,
  58. InternetInfo.GetInstance.MqttAddress,
  59. InternetInfo.GetInstance.MqttPort,
  60. DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
  61. }), "业务逻辑初始化");
  62. }
  63. }
  64. }