From 5eeafe3af80bfd88306bd8ad9e76c8f4b51ca35f Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 14:16:20 +0800
Subject: [PATCH] 增加本地发送的重发机制

---
 HDL_ON/DAL/Mqtt/MqttClient.cs |   54 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 321d8b1..4ddfc8e 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -210,7 +210,7 @@
         /// </summary>
         public static async Task StartCloudMqtt()
         {
-            if (OnAppConfig.Instance.internetStatus == 0)
+            if (MainPage.InternetStatus == 0)
             {
                 return;
             }
@@ -268,9 +268,10 @@
                                 else
                                 {
                                     SetGatewayOnlineResetCheck();
-                                    Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.residenceData.HomeGateway.aesKey);
+                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
+                                    
                                     //bus鏁版嵁瑙f瀽
-                                    if (DB_ResidenceData.residenceData.GatewayType == 0)
+                                    if (DB_ResidenceData.Instance.GatewayType == 0)
                                     {
                                         var packet = new Packet();
 
@@ -287,8 +288,8 @@
                                     else
                                     {
                                         //A鍗忚鏁版嵁澶勭悊
-                                        var revString = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
-                                        Control.Ins.UpdataFunctionStatus(revString);
+                                        var revString = Encoding.UTF8.GetString(bytes);
+                                        Control.Ins.UpdataFunctionStatus(revString,null);
                                     }
                                 }
                             }
@@ -309,10 +310,27 @@
                     if (RemoteMqttClient.ConnectedHandler == null)
                     {
                         RemoteMqttClient.UseConnectedHandler(async (e) => {
+                            if (DB_ResidenceData.Instance.HomeGateway.gatewayStatus)
+                            {
+                                Control.Ins.GatewayOnline = true;
+                            }
+                            else
+                            {
+                                //new System.Threading.Thread(() => {
+                                //    while(true)
+                                //    {
+                                //        System.Threading.Thread.Sleep(1000);
+                                //        if (DB_ResidenceData.Instance.HomeGateway.GatewayOnline)
+                                //        {
+                                //            Control.Ins.GatewayOnline = true;
+                                //            break;
+                                //        }
+                                //    }
+                                //}) { IsBackground = true }.Start();
+                            }
                             IfNeedReadAllDeviceStatus = true;
                             Utlis.WriteLine($"============>Mqtt杩滅▼杩炴帴鎴愬姛");
                             SendPushSignOut();
-                            FunctionList.List.ReadAllFunctionStatus();
                         });
                     }
                     #endregion
@@ -369,7 +387,7 @@
         {
             try
             {
-                if (MqttInfoConfig.Current.HomeGatewayInfo != null && MqttInfoConfig.Current.HomeGatewayInfo.mac == Entity.DB_ResidenceData.residenceData.residenceGatewayMAC)
+                if (MqttInfoConfig.Current.HomeGatewayInfo != null && MqttInfoConfig.Current.HomeGatewayInfo.mac == Entity.DB_ResidenceData.Instance.residenceGatewayMAC)
                 {
                     await MQTTConnectAsync();
                 }
@@ -522,7 +540,9 @@
         /// </summary>
         static void ReceiveNotifySqueezeAsync(string mMes)
         {
-
+#if DEBUG
+            return;
+#endif
             if (mMes == PushSignStr) return;//鏄嚜宸辩殑鐧诲綍鎺ㄩ�佷笉澶勭悊
 
             //鏂紑杩滅▼杩炴帴
@@ -534,13 +554,15 @@
 
             DisConnectRemoteMqttClient("鎸や笅绾�");
 
-            UserInfo.Current.LastTime = DateTime.MinValue;
-            UserInfo.Current.SaveUserInfo();
+            HDLCommon.Current.CheckLogout();
 
-            Application.RunOnMainThread(() => {
-                MainPage.GoLoginPage(UserInfo.Current);
-                //寮圭獥鎻愮ず琚尋涓嬬嚎
-            });
+            //UserInfo.Current.LastTime = DateTime.MinValue;
+            //UserInfo.Current.SaveUserInfo();
+
+            //Application.RunOnMainThread(() => {
+            //    MainPage.GoLoginPage(UserInfo.Current);
+            //    //寮圭獥鎻愮ず琚尋涓嬬嚎
+            //});
 
             //2020-08-11 鍒犻櫎鎺ㄩ�佹暟鎹�
             //HDLRequest.Current.PushserivceSignOut ();
@@ -652,10 +674,10 @@
                 MqttInfoConfig.Current.mMqttInfo = mqttInfoRequestResult_Obj;
                 await MQTTConnectAsync();
                 //1.鍒ゆ柇鏄惁缁戝畾浜嗙綉鍏筹紝鑾峰彇缃戝叧杩滅▼杩炴帴鐨勫姞瀵咾EY
-                if (DB_ResidenceData.residenceData.CheckWhetherGatewayIsBound())
+                if (DB_ResidenceData.Instance.CheckWhetherGatewayIsBound())
                 {
                     //2.鎵惧嚭鏄惁瀛樺湪鍖归厤褰撳墠浣忓畢鐨刴ac锛屽瓨鍦ㄥ啀杩涜杩滅▼銆�
-                    MqttInfoConfig.Current.HomeGatewayInfo = DB_ResidenceData.residenceData.HomeGateway;
+                    MqttInfoConfig.Current.HomeGatewayInfo = DB_ResidenceData.Instance.HomeGateway;
                     //3.寮�濮嬭繛鎺�
                     await MQTTConnectAsync();
                 }

--
Gitblit v1.8.0