using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HBLConsole.Model; using HBLConsole.Service; using HBLConsole.GVL; using HBLConsole.Communication; using BPA.Message; using HBLConsole.Business; using HBLConsole.Factory; using BPA.Message.Enum; using System.Collections.ObjectModel; using System.Threading; namespace HBLConsole.MainConsole { public class Main { private volatile static Main _Instance; public static Main GetInstance => _Instance ?? (_Instance = new Main()); private Main() { } List Topics = new List(); public void DataInit() { string deviceType = TextHelper.GetInstance.ReadTextInfo("DeviceType"); GeneralConfig.DeviceType = DeviceClientType.MORKS; if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct; LocaPath.GetInstance.FilePath = $"AccessFile\\{GeneralConfig.DeviceType.ToString()}\\"; ThreadManage.GetInstance.Start(new Action(() => { Sqlite.GetInstance.GetData(); }), "GetAlarm"); //Json.Read(); Json.Read(); Json.Read(); Json.Read(); if (Json.Data.parSets == null) Json.Data.parSets = new ObservableCollection(); if (Json.Data.parSets.Count < 6) { Json.Data.parSets.Clear(); for (int i = 0; i < 6; i++) { Json.Data.parSets.Add(new ParSet() { CheckBoxContext = $"煮面口{i + 1}屏蔽", Minute = 1, Second = 0, IsShield = false, TextBlockContext = $"煮面口{i + 1}时间设定" }); } } MessageLog.GetInstance.Show($"启动【{GeneralConfig.DeviceType}】设备"); } public void DataSave() { //Json.Save(); Json.Save(); Json.Save(); Json.Save(); Sqlite.GetInstance.Save(); TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo", "OrderInfoLog"); } public void BusinessInit() { ThreadManage.GetInstance.Start(new Action(() => { SimpleFactory.GetInstance.DeviceInit();//设备初始化 //InternetInfo.ConfigInit();//从 consul 获取配置数据 //IotReport.GetInstance.Initialize(); //Topics.Clear(); //Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.deviceId)); //Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.deviceId)); //Topics.Add(TOPIC.GetInstance.GetChargebackTopic(GeneralConfig.DeviceType, InternetInfo.deviceId)); ////MQTT 连接成功 //MqttHelper.GetInstance.ConnectOk = new Action(() => //{ // SimpleFactory.GetInstance.DeviceInit();//设备初始化 // MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 // HeartbeatReport.GetInstance.Init();//心跳上报 // ServerData.GetInstance.Init();//数据处理初始化 // //接收MQTT消息 // MqttHelper.GetInstance.MqttReceive = new Action((receivce) => // { // ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload)); // }); //}); ////MQTT 重连成功 //MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); }); ////MQTT 连接 //MqttHelper.GetInstance.MqttInitAsync(InternetInfo.MqttUserName, InternetInfo.MqttPassword, // InternetInfo.MqttAddress, InternetInfo.MqttPort, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); }), "业务逻辑初始化"); } } }