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.
 
 

93 lines
3.4 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. string deviceType = TextHelper.GetInstance.ReadTextInfo();
  25. GeneralConfig.DeviceType = DeviceClientType.MORKS;
  26. if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct;
  27. LocaPath.GetInstance.FilePath = $"AccessFile\\{GeneralConfig.DeviceType.ToString()}\\";
  28. ThreadManage.GetInstance.Start(new Action(() => { Sqlite<Alarm>.GetInstance.GetData(); }), "GetAlarm");
  29. Json<MorkOrderPushPar>.Read();
  30. Json<BatchingInfoPar>.Read();
  31. Json<SimOrderConfig>.Read();
  32. Json<KeepDataBase>.Read();
  33. MessageLog.GetInstance.Show($"启动【{GeneralConfig.DeviceType}】设备");
  34. }
  35. public void DataSave()
  36. {
  37. Json<MorkOrderPushPar>.Save();
  38. Json<BatchingInfoPar>.Save();
  39. Json<SimOrderConfig>.Save();
  40. Json<KeepDataBase>.Save();
  41. Sqlite<Alarm>.GetInstance.Save();
  42. TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo");
  43. }
  44. public void BusinessInit()
  45. {
  46. ThreadManage.GetInstance.Start(new Action(() =>
  47. {
  48. InternetInfo.ConfigInit();//从 consul 获取配置数据
  49. Topics.Clear();
  50. Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
  51. Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
  52. //MQTT 连接成功
  53. MqttHelper.GetInstance.ConnectOk = new Action(() =>
  54. {
  55. SimpleFactory.GetInstance.DeviceInit();//设备初始化
  56. MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅
  57. //IotReport.GetInstance.Init();//IOT 上报
  58. HeartbeatReport.GetInstance.Init();//心跳上报
  59. ServerData.GetInstance.Init();//数据处理初始化
  60. //接收MQTT消息
  61. MqttHelper.GetInstance.MqttReceive = new Action<MQTTnet.MqttApplicationMessageReceivedEventArgs>((receivce) =>
  62. {
  63. ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload));
  64. });
  65. });
  66. //MQTT 重连成功
  67. MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); });
  68. //MQTT 连接
  69. MqttHelper.GetInstance.MqttInitAsync(InternetInfo.MqttUserName, InternetInfo.MqttPassword,
  70. InternetInfo.MqttAddress, InternetInfo.MqttPort, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
  71. }), "业务逻辑初始化");
  72. }
  73. }
  74. }