From f441a3c49f8b5cedee3e4def6fbb448ef40eb9cb Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 10 六月 2020 14:46:58 +0800
Subject: [PATCH] Crabtree-ON 2020-06-10 基于最新HDL ON 优化问题,Crabtree-ONAPP部分功能同步修改优化调整 1. 增加大图片大文件上传处理. 2.远程连接交互提示,由原来的Loading修改成顶部Tip提示。 3.灯光全开、全关和场景控制多线程发送,和HDLON同样加锁处理。 4.Android ,判断移动网络失败,网络监测修复方法修改,后台前台切换优化。

---
 Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs |   91 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 71 insertions(+), 20 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
index 0774a26..06bf05b 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/MqttCommon.cs
@@ -17,6 +17,11 @@
 {
     public static class MqttCommon
     {
+        /// <summary>
+        /// 鏄惁鎻愮ず 杩滅▼杩炴帴鐨勯敊璇俊鎭� 
+        /// </summary>
+        public static bool IfDEBUG = false;
+
         static string mqttEncryptKey = "";
         static string checkGatewayTopicBase64 = "";
         static RemoteMACInfo CurRemoteMACInfo = null;
@@ -57,8 +62,10 @@
             new System.Threading.Thread (async () => {
                 while (true) {
                     try {
-                        System.Threading.Thread.Sleep (100);
+                        System.Threading.Thread.Sleep (200);
                         if (!CommonPage.IsRemote) continue;
+
+                        if (Control.IsEnterBackground) continue;
 
                         await StartCloudMqtt ();
                         await CheckingSubscribeTopics ();
@@ -67,6 +74,15 @@
                 }
             }) { IsBackground = true }.Start ();
         }
+
+        public static void InitState ()
+        {
+            IfNeedReadAllDeviceStatus = true;
+            bNeedStartTip = true;
+            IsGatewayOnline = false;
+            StartCloudMqtt ();
+        }
+
 
         /// <summary>
         /// 鏄惁璁㈤槄鎴愬姛
@@ -135,7 +151,7 @@
                     if (CommonPage.IsRemote) {
                         Utlis.ShowAppLinkStatus (AppLinkStatus.CloudUnlink);
                     }
-                    Utlis.WriteLine ($"============>MqttRemoteDisConnectRemoteMqttClient");
+                    //Utlis.WriteLine ($"============>MqttRemoteDisConnectRemoteMqttClient");
 
                 }
             } catch (Exception e) {
@@ -153,7 +169,7 @@
         /// <summary>
         /// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴
         /// </summary>
-        static bool remoteMqttIsConnecting;
+        public static bool remoteMqttIsConnecting;
         static bool remoteIsConnected;
         /// <summary>
         /// 鍚姩杩滅▼Mqtt
@@ -224,7 +240,7 @@
                     }
                     if (RemoteMqttClient.ConnectedHandler == null) {
                         RemoteMqttClient.UseConnectedHandler (async (e) => {
-                            IfNeedReadAllDeviceStatus = true;
+                            //IfNeedReadAllDeviceStatus = true;
                             mCheckGatewayTime = DateTime.Now;
                             CheckGatewayCount = 0;
                             bNeedStartTip = true;
@@ -273,10 +289,21 @@
                     }
 
                 } catch (Exception ex) {
-                    Utlis.WriteLine ($"============>Mqtt 杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
+                    //Utlis.WriteLine ($"============>Mqtt 杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
+
+                    MainPage.LoadingTipShow ("Connect error, trying to reconnect.");
+
+                    if (IfDEBUG) {
+                        MainPage.ShowAlertOnMainThread ("error: " + ex.Message);
+                    }
+
                 } finally {
                     //鏈�缁堣閲婃斁杩炴帴鐘舵��
                     remoteMqttIsConnecting = false;
+
+                    MainPage.LoadingTipHide ();
+
+                    //MainPage.LoadingHide ();
                 }
             });
         }
@@ -315,16 +342,25 @@
                                 //----绗笁姝� 寮�濮嬭繛鎺�
                                 await MQTTConnectAsync ();
                             } else {
-                                Utlis.WriteLine ("============>Mqtt CurRemoteMACInfo null");
+                                //Utlis.WriteLine ("============>Mqtt CurRemoteMACInfo null");
+
+                                MainPage.LoadingTipShow ("Please wait, failed to get gateway parameters.");
                             }
                         }
 
                     } else {
-                        Utlis.WriteLine ("============>Mqtt mqttInfoRequestResult_Obj null");
+                        //Utlis.WriteLine ("============>Mqtt mqttInfoRequestResult_Obj null");
+
+                        MainPage.LoadingTipShow ("Please wait, failed to get user parameters.");
+                        //MainPage.LoadingTipShow ("Please wait, failed to get parameters.");
                     }
-                } catch { }
+                } catch {
+
+                }
             } else {
-                Utlis.WriteLine ("============>Mqtt GetInfo 澶辫触");
+                //Utlis.WriteLine ("============>Mqtt GetInfo 澶辫触");
+                MainPage.AddTip ("Please wait, failed to get parameters.");
+                //MainPage.LoadingTipShow ("Please wait, failed to get parameters.");
             }
 
         }
@@ -350,6 +386,8 @@
                     mMqttInfo = mqttInfoRequestResult_info;
                     //--绗簩姝ワ細鑾峰彇褰撳墠浣忓垎浜畢缃戝叧淇℃伅骞惰繛鎺QTT
                     await GetSingleHomeGatewayPaggerAndMQTTConnectAsync ();
+                } else {
+                    MainPage.LoadingTipShow ("Please wait, failed to get user parameters.");
                 }
             }
         }
@@ -363,7 +401,10 @@
 
              
                 //鑾峰彇鍙傛暟鎴愬姛锛屽紑濮嬭繛鎺�...
-                MainPage.AddTip ("Successfully obtained parameters, starting to connect...");
+                //MainPage.AddTip ("Successfully obtained parameters, starting to connect...");
+
+                MainPage.LoadingTipShow ("Please wait, connecting remotely...");
+
                 //try {
                 //    var url = mMqttInfo.connEmqDomainPort;
                 //    var clientId = mMqttInfo.connEmqClientId;
@@ -389,7 +430,7 @@
                 //    Console.WriteLine ("Connect error: " + ex.Message);
                 //}
 
-                string mes = "";
+                //string mes = "";
                 try {
 
                     var url = mMqttInfo.connEmqDomainPort;
@@ -397,7 +438,7 @@
                     var username = mMqttInfo.connEmqUserName;
                     var passwordRemote = mMqttInfo.connEmqPwd;
 
-                    mes = "step1.Set Data";
+                    //mes = "step1.Set Data";
                     CurRemoteMACInfo.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
                     mqttEncryptKey = CurRemoteMACInfo.aesKey;
                     var options1 = new MQTTnet.Client.Options.MqttClientOptionsBuilder ()
@@ -408,14 +449,16 @@
                                         // .WithCommunicationTimeout (new TimeSpan (0, 0, 20))
                                         .Build ();
 
-                    mes = "step2.DisConnect";
+                    //mes = "step2.DisConnect";
                     await DisConnectRemoteMqttClient ("StartRemoteMqtt");
                     //MainPage.AddTip ("Start to connect...");
-                    mes = "step3.Start to connect";
+                    //mes = "step3.Start to connect";
                     await RemoteMqttClient.ConnectAsync (options1);
-                    mes = "step4.Connected Success";
+                    //mes = "step4.Connected Success";
                     remoteIsConnected = true;
                     IsDisConnectingWithSendCatch = false;
+
+                    MainPage.LoadingTipShow ("Remote connection succeeded.");
 
                     //MainPage.AddTip ("Connection succeeded!");
                     //await MqttRemoteSend (new byte [] { 0 }, 1);
@@ -423,12 +466,17 @@
                     //await MqttRemoteSend (new byte [] { 0 }, 4);
 
                 } catch (Exception ex) {
-                    mes = ex.Message;
+                    //mes = ex.Message;
                     //options1 寮傚父鎻愮ず
-                    //Console.WriteLine("Connect error: " + ex.Message);
-                    //MainPage.ShowAlertOnMainThread ("Connect error: " + ex.Message);
+                    //Console.WriteLine ("Connect error: " + ex.Message);
+
+                    MainPage.LoadingTipShow ("Connect error.");
+
+                    if (IfDEBUG) {
+                        MainPage.ShowAlertOnMainThread ("Connect error: " + ex.Message);
+                    }
                 } finally {
-                    MainPage.ShowAlertOnMainThread ("finally: " + mes);
+                    //MainPage.ShowAlertOnMainThread ("finally: " + mes);
                     //MainPage.AddTip ("finally: " + mes);
                 }
 
@@ -447,7 +495,8 @@
             if (bNeedStartTip) {
                 bNeedStartTip = false;
                 if (CommonPage.IsRemote) {
-                    MainPage.AddTip ("Getting remote connection parameters...");
+                    //MainPage.AddTip ("Getting remote connection parameters...");
+                    MainPage.LoadingTipShow ("Please wait, getting connection parameters...");
                 }
             }
         }
@@ -545,6 +594,8 @@
                     if (mGatewayRes != null) {
                         CurRemoteMACInfo.aesKey = mGatewayRes.AesKey;
                         mqttEncryptKey = CurRemoteMACInfo.aesKey;
+                    } else {
+                        MainPage.LoadingTipShow ("Please wait, failed to get gateway parameters.");
                     }
 
                 }

--
Gitblit v1.8.0