Davin
2023-07-26 489d3bd60ad7dc2fecb398b09cf4c52df16f0fc2
HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -12,6 +12,7 @@
using HDL_ON.Entity;
using HDL_ON.UI;
using HDL_ON.DAL.Server;
using HDL_ON;
namespace HDL_ON.DAL.Mqtt
{
@@ -110,6 +111,7 @@
            {
                MqttInfoConfig.Current.IfGetMqttInfoSuccess = false;
            }
            Control.Ins.GatewayOnline_Cloud = Control.Ins.GatewayOnline_Local = false;
            await DisConnectRemoteMqttClient(s);
        }
@@ -159,7 +161,7 @@
            StartCloudMqtt();
        }
        static bool isSubscribeSuccess;
        public static bool isSubscribeSuccess;
        /// <summary>
        /// 订阅主题
        /// </summary>
@@ -261,8 +263,8 @@
                    #endregion
                    Utlis.WriteLine("开始订阅!");
                    var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
                    Utlis.WriteLine("开始订阅!");
                     var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
                        pirStatus,pirStudy,
                        appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange,
                        topicFilterPush2, topicAlinkStatus ,mqttkeyChange,
@@ -374,7 +376,7 @@
                            try
                            {
                                var topic = e.ApplicationMessage.Topic;
                                //MainPage.Log($"收到mqtt主题:{topic}");
                                MainPage.Log($"收到mqtt主题:{topic}");
                                //一端口主题处理
                                if (DB_ResidenceData.Instance.GatewayType == 0 && !DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
                                {
@@ -460,6 +462,7 @@
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up")
                                {
                                    MainPage.Log("住宅数据刷新通知");
                                    System.Threading.Thread.Sleep(2000);
                                    new HttpServerRequest().GetHomePager();
                                }
                                //appRoomRefresh:房间数据刷新通知
@@ -488,48 +491,6 @@
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up")
                                {
                                    MainPage.Log("设备数据刷新通知");
                                    var deviceResult = new HttpServerRequest().GetDeviceList();
                                    if (deviceResult.Code == StateCode.SUCCESS)
                                    {
                                        MainPage.Log($"读取设备信息成功");
                                        var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                        if (deviceList == null)
                                        {
                                            deviceList = new DevcieApiPack();
                                        }
                                        string delFile = "";
                                        if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                                        {
                                            for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;)
                                            {
                                                var localFunction = FunctionList.List.GetDeviceFunctionList()[i];
                                                if (SPK.MusicSpkList().Contains(localFunction.spk))
                                                {
                                                    i++;
                                                    continue;
                                                }
                                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                                                if (delFile == localFunction.savePath)
                                                {
                                                    i++;
                                                    continue;
                                                }
                                                delFile = localFunction.savePath;
                                                FunctionList.List.DeleteFunction(localFunction);
                                            }
                                        }
                                        //处理剩下的新增功能
                                        foreach (var newFunction in deviceList.list)
                                        {
                                            newFunction.SaveFunctionFile();
                                            FunctionList.List.IniFunctionList(newFunction.savePath);
                                        }
                                    }
                                    else
                                    {
                                        MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
                                    }
                                }
                                //网关密钥变化
                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change")
@@ -682,7 +643,7 @@
                }
                catch (Exception ex)
                {
                    Utlis.WriteLine($"error:" + ex.Message);
                    Utlis.WriteLine($"mqtt连接异常 error:" + ex.Message);
                    //mqtt连接异常,清空本地mqtt信息,可能需要重新获取:wxr
                    MqttInfoConfig.Current.Refresh();
                }
@@ -876,6 +837,7 @@
            //测试账号,不挤下线
            switch (UserInfo.Current.userMobileInfo)
            {
                case "18316672920":
                case "15626203746":
                case "464027401@qq.com":
                    return;
@@ -1185,7 +1147,7 @@
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MainPage.Log(ex.Message);
            }
            return reData;
        }