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.
 
 

114 lines
4.5 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. using System.Collections.ObjectModel;
  15. using System.Threading;
  16. namespace HBLConsole.MainConsole
  17. {
  18. public class Main
  19. {
  20. private volatile static Main _Instance;
  21. public static Main GetInstance => _Instance ?? (_Instance = new Main());
  22. private Main() { }
  23. List<string> Topics = new List<string>();
  24. public void DataInit()
  25. {
  26. string deviceType = TextHelper.GetInstance.ReadTextInfo("DeviceType");
  27. GeneralConfig.DeviceType = DeviceClientType.MORKS;
  28. if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct;
  29. LocaPath.GetInstance.FilePath = $"AccessFile\\{GeneralConfig.DeviceType.ToString()}\\";
  30. ThreadManage.GetInstance.Start(new Action(() => { Sqlite<Alarm>.GetInstance.GetData(); }), "GetAlarm");
  31. //Json<MorkOrderPushPar>.Read();
  32. Json<BatchingInfoPar>.Read();
  33. Json<SimOrderConfig>.Read();
  34. Json<KeepDataBase>.Read();
  35. if (Json<KeepDataBase>.Data.parSets == null) Json<KeepDataBase>.Data.parSets = new ObservableCollection<ParSet>();
  36. if (Json<KeepDataBase>.Data.parSets.Count < 6)
  37. {
  38. Json<KeepDataBase>.Data.parSets.Clear();
  39. for (int i = 0; i < 6; i++)
  40. {
  41. Json<KeepDataBase>.Data.parSets.Add(new ParSet()
  42. {
  43. CheckBoxContext = $"煮面口{i + 1}屏蔽",
  44. Minute = 1,
  45. Second = 0,
  46. IsShield = false,
  47. TextBlockContext = $"煮面口{i + 1}时间设定"
  48. });
  49. }
  50. }
  51. MessageLog.GetInstance.Show($"启动【{GeneralConfig.DeviceType}】设备");
  52. }
  53. public void DataSave()
  54. {
  55. //Json<MorkOrderPushPar>.Save();
  56. Json<BatchingInfoPar>.Save();
  57. Json<SimOrderConfig>.Save();
  58. Json<KeepDataBase>.Save();
  59. Sqlite<Alarm>.GetInstance.Save();
  60. TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo", "OrderInfoLog");
  61. }
  62. public void BusinessInit()
  63. {
  64. ThreadManage.GetInstance.Start(new Action(() =>
  65. {
  66. SimpleFactory.GetInstance.DeviceInit();//设备初始化
  67. //InternetInfo.ConfigInit();//从 consul 获取配置数据
  68. //IotReport.GetInstance.Initialize();
  69. //Topics.Clear();
  70. //Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.deviceId));
  71. //Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.deviceId));
  72. //Topics.Add(TOPIC.GetInstance.GetChargebackTopic(GeneralConfig.DeviceType, InternetInfo.deviceId));
  73. ////MQTT 连接成功
  74. //MqttHelper.GetInstance.ConnectOk = new Action(() =>
  75. //{
  76. // SimpleFactory.GetInstance.DeviceInit();//设备初始化
  77. // MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅
  78. // HeartbeatReport.GetInstance.Init();//心跳上报
  79. // ServerData.GetInstance.Init();//数据处理初始化
  80. // //接收MQTT消息
  81. // MqttHelper.GetInstance.MqttReceive = new Action<MQTTnet.MqttApplicationMessageReceivedEventArgs>((receivce) =>
  82. // {
  83. // ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload));
  84. // });
  85. //});
  86. ////MQTT 重连成功
  87. //MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); });
  88. ////MQTT 连接
  89. //MqttHelper.GetInstance.MqttInitAsync(InternetInfo.MqttUserName, InternetInfo.MqttPassword,
  90. // InternetInfo.MqttAddress, InternetInfo.MqttPort, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
  91. }), "业务逻辑初始化");
  92. }
  93. }
  94. }