From c7df85937f73fb347ee0b19e9c052d2d00a6df6c Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 18 九月 2020 13:58:19 +0800
Subject: [PATCH] 新版本

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs |  195 +++++++++++++++++++++++++++---------------------
 1 files changed, 110 insertions(+), 85 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
index b841920..d8943b3 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -22,24 +22,19 @@
         /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
         /// <param name="obj">涓�涓被</param>
         /// <param name="listNotShowError">涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</param>
-        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿涓嶉噸鍙�</param>
-        public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
+        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿閲嶅彂</param>
+        public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
         {
-            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
-            {
-                //褰撳墠鏃犳硶璁块棶缃戠粶(褰撻渶瑕侀噸鏂板彂閫佹椂,璺宠繃杩欎釜鍒ゆ柇)
-                ShowNotNetMsg(listNotShowError);
-                return false;
-            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
             var byteData = GettByteResponsePack(RequestName, connectMode, obj);
-            if (byteData == null && setAgain == true)
+            if (byteData == null)
             {
                 if (setAgain == false)
                 {
-                    //涓嶆寚瀹氶噸鍙�
+                    //褰撳墠鏃犳硶璁块棶缃戠粶
+                    ShowNotNetMsg(RequestName, listNotShowError);
                     return false;
                 }
                 byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -61,17 +56,10 @@
         /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
         /// <param name="obj">涓�涓被</param>
         /// <param name="listNotShowError">涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</param>
-        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿涓嶉噸鍙�</param>
+        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿閲嶅彂</param>
         /// </param>
-        public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
+        public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
         {
-            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
-            {
-                //褰撳墠鏃犳硶璁块棶缃戠粶(褰撻渶瑕侀噸鏂板彂閫佹椂,璺宠繃杩欎釜鍒ゆ柇)
-                ShowNotNetMsg(listNotShowError);
-                return "Error";
-            }
-
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -80,7 +68,8 @@
             {
                 if (setAgain == false)
                 {
-                    //涓嶆寚瀹氶噸鍙�
+                    //褰撳墠鏃犳硶璁块棶缃戠粶
+                    ShowNotNetMsg(RequestName, listNotShowError);
                     return "Error";
                 }
                 byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -105,16 +94,10 @@
         /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
         /// <param name="obj">涓�涓被</param>
         /// <param name="listNotShowError">涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</param>
-        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿涓嶉噸鍙�</param>
+        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿閲嶅彂</param>
         /// </param>
-        public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
+        public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
         {
-            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
-            {
-                //褰撳墠鏃犳硶璁块棶缃戠粶(褰撻渶瑕侀噸鏂板彂閫佹椂,璺宠繃杩欎釜鍒ゆ柇)
-                ShowNotNetMsg(listNotShowError);
-                return null;
-            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -123,7 +106,8 @@
             {
                 if (setAgain == false)
                 {
-                    //涓嶆寚瀹氶噸鍙�
+                    //褰撳墠鏃犳硶璁块棶缃戠粶
+                    ShowNotNetMsg(RequestName, listNotShowError);
                     return null;
                 }
                 byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -154,15 +138,9 @@
         /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
         /// <param name="obj">涓�涓被</param>
         /// <param name="listNotShowError">涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</param>
-        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿涓嶉噸鍙�</param>
-        public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
+        /// <param name="setAgain">褰撳彂閫佸け璐ユ椂,鏄惁閲嶅彂,榛樿閲嶅彂</param>
+        public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
         {
-            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
-            {
-                //褰撳墠鏃犳硶璁块棶缃戠粶(褰撻渶瑕侀噸鏂板彂閫佹椂,璺宠繃杩欎釜鍒ゆ柇)
-                ShowNotNetMsg(listNotShowError);
-                return null;
-            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -172,7 +150,8 @@
             {
                 if (setAgain == false)
                 {
-                    //涓嶆寚瀹氶噸鍙�
+                    //褰撳墠鏃犳硶璁块棶缃戠粶
+                    ShowNotNetMsg(RequestName, listNotShowError);
                     return null;
                 }
                 revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -227,7 +206,7 @@
                 if (count == 3)
                 {
                     //鏄剧ず娌℃湁缃戠粶鐨凪sg
-                    ShowNotNetMsg(null);
+                    ShowNotNetMsg(RequestName, null);
                     break;
                 }
             }
@@ -349,13 +328,15 @@
         /// <summary>
         /// 鏄剧ず娌℃湁缃戠粶鐨凪sg
         /// </summary>
-        private static void ShowNotNetMsg(List<string> listNotShowError)
+        private static void ShowNotNetMsg(string RequestName, List<string> listNotShowError)
         {
             if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
             {
                 //涓嶆娴�
                 return;
             }
+            //HdlLogLogic.Current.WriteLog(-1, "褰撳墠鏃犵綉缁滆繛鎺�:" + RequestName);
+
             HdlThreadLogic.Current.RunMain(() =>
             {
                 // 褰撳墠鏃犵綉缁滆繛鎺�,璇风‘璁ょ綉缁�
@@ -519,13 +500,18 @@
         #endregion
 
         #region 鈻� 鍒锋柊鏈湴缂撳瓨_______________________
+
         /// <summary>
-        /// 鍒锋柊鏈湴鎵�鏈夌紦瀛�
+        /// 鍒锋柊鏈湴鎵�鏈夌紦瀛�(鐩墠姝ゆ柟娉曞彧鎻愪緵缁欐仮澶嶅浠芥暟鎹娇鐢�)
         /// </summary>
         public static void RefreshAllMemory()
         {
             //鍒锋柊浣忓畢瀵硅薄
             RefreshHomeObject();
+            //鏍规嵁妯℃澘鏂囦欢,鎭㈠鏁版嵁
+            TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile();
+            //寮哄埗鐢熸垚璁惧鍜岀綉鍏虫枃浠�
+            TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce();
             //鍒锋柊鏈湴缃戝叧鏂囦欢
             HdlGatewayLogic.Current.ReFreshByLocal();
             //鍒锋柊鏈湴璁惧
@@ -537,7 +523,7 @@
             //鏂紑杩滅▼Mqtt杩炴帴,閲嶆柊杩炴帴
             HdlThreadLogic.Current.RunThread(async () =>
             {
-                HdlGatewayLogic.Current.ClearAllRealGateway();
+                HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
                 await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
             }, ShowErrorMode.NO);
         }
@@ -547,21 +533,25 @@
         /// </summary>
         public static void RefreshHomeObject()
         {
-            //澶囦唤鐨勬暟鎹紝鏈夊彲鑳芥槸涓讳汉鑷繁涓婁紶鐨勶紝濡傛灉绠$悊鍛樼櫥闄嗘椂锛屼粬鑾峰彇鐨勫浠芥暟鎹湁鐐圭壒娈�
-            //姣斿涓嬮潰杩欎笁涓笢瑗垮湪涓昏处鍙烽偅閲屾槸涓嶉渶瑕佺殑
-            bool isOthreShare = Config.Instance.Home.IsOthreShare;
-            int accountType = Config.Instance.Home.AccountType;
-            string mainMark = Config.Instance.Home.MainUserDistributedMark;
-            double Longitude = Config.Instance.Home.Longitude;
-            double Latitude = Config.Instance.Home.Latitude;
-            //杩樺師浣忓畢瀵硅薄
-            Config.Instance.Home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id);
-            Config.Instance.Home.IsOthreShare = isOthreShare;
-            Config.Instance.Home.AccountType = accountType;
-            Config.Instance.Home.MainUserDistributedMark = mainMark;
-            Config.Instance.Home.Longitude = Longitude;
-            Config.Instance.Home.Latitude = Latitude;
+            var home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id);
+
+            //鍒锋柊妤煎眰
+            Config.Instance.Home.FloorDics = home.FloorDics;
+            Config.Instance.Home.CurrentFloorId = string.Empty;
+            if (Config.Instance.Home.TemplateMode == -1)
+            {
+                Config.Instance.Home.TemplateMode = home.TemplateMode;
+                if (Config.Instance.Home.TemplateMode == -1)
+                {
+                    //榛樿鍒濆鍊�
+                    Config.Instance.Home.TemplateMode = 1;
+                }
+            }
+
             Config.Instance.Home.Save(false);
+
+            //涓婚〉闇�瑕侀噸鏂板埛鏂�
+            UserView.UserPage.Instance.RefreshAllForm = true;
         }
 
         #endregion
@@ -590,7 +580,7 @@
                     //鍏抽棴鍏ㄩ儴寮圭獥
                     ShowMsgControl.CloseAllMsgDialog();
                     //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
-                    CloseAllOpenForm();
+                    CloseAllOpenForm(null, false);
 
                     //鏄剧ず鐧婚檰鐢婚潰
                     var formLogin = new Login.AccountLoginForm();
@@ -618,7 +608,7 @@
 
                 //娓呯┖褰撳墠浣忓畢id
                 Config.Instance.HomeId = string.Empty;
-                HdlGatewayLogic.Current.ClearAllRealGateway();
+                HdlGatewayLogic.Current.ClearAllRealGatewayConection(false);
 
                 //鏂紑杩滅▼Mqtt杩炴帴
                 HdlThreadLogic.Current.RunThread(async () =>
@@ -631,7 +621,7 @@
                     //鏀惰捣宸﹁彍鍗�
                     CommonPage.Instance.CloseLeftMenu();
                     //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
-                    CloseAllOpenForm();
+                    CloseAllOpenForm(null, false);
 
                     //鏄剧ず鐧婚檰鐢婚潰
                     var formLogin = new Login.AccountLoginForm();
@@ -651,7 +641,8 @@
         /// 鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
         /// </summary>
         /// <param name="tagetFrom">鐩爣鐣岄潰,濡傛灉鎸囧畾浜嗙殑璇�,鍒欏叧闂洰鏍囩晫闈笂灞傜殑鍏ㄩ儴鐣岄潰(瀹冭嚜韬笉鍏抽棴)</param>
-        public static void CloseAllOpenForm(string tagetFrom = null)
+        /// <param name="refreshMainPage">褰撳叧闂殑鐣岄潰杈惧埌涓婚〉鏃�,鏄惁鍒锋柊涓婚〉</param>
+        public static void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true)
         {
             while (UserView.HomePage.Instance.ChildrenCount > 0)
             {
@@ -674,8 +665,11 @@
                 }
                 else if (view is UserView.UserPage)
                 {
-                    var form = ((UserView.UserPage)view).GetNowActionForm();
-                    form?.FormActionAgainEvent();
+                    //鍒锋柊涓婚〉
+                    if (refreshMainPage == true)
+                    {
+                        UserView.UserPage.Instance.ReFreshControl();
+                    }
                     return;
                 }
                 else
@@ -824,6 +818,17 @@
                     HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
                     //璇诲彇闅愬尶閰嶇疆
                     HdlBackupLogic.Current.LoadHideOption();
+                    //璋冭瘯锛氬己鍒跺紑鍚悗鍙拌皟璇旳pp鍔熻兘
+                    if (UserCenterResourse.HideOption.StartDebugApp == 1)
+                    {
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            var form = new HideOption.HideOptionMainForm();
+                            form.AddForm();
+                        });
+                        ProgressBar.Close(true);
+                        return false;
+                    }
                 }
 
                 //鍏抽棴鎵�鏈夋帴鏀�
@@ -861,12 +866,15 @@
                 //鏂紑杩滅▼Mqtt杩炴帴,閲嶆柊杩炴帴
                 HdlThreadLogic.Current.RunThread(async () =>
                 {
-                    HdlGatewayLogic.Current.ClearAllRealGateway();
+                    HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
                     await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                 }, ShowErrorMode.NO);
 
                 //鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D(鍙互鍙嶅璋冪敤,闇�瑕佸湪缃戝叧鍒濆鍖栧畬浜嗕箣鍚庢墠鑳借皟鐢�)
                 HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
+
+                //鍔犺浇妯℃澘缂撳瓨
+                //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
 
                 //0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�,杩欎釜鏃跺�欓渶瑕佹彁绀哄浠�
                 if (result == 0 && ShowPrompted == true)
@@ -882,33 +890,19 @@
                 System.Threading.Thread.Sleep(30);
                 if (hadNet == 1)
                 {
-                    try
-                    {
-                        bool canReceiveGw = false;
-                        foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values)
-                        {
-                            if (gateway.HomeId == Config.Instance.Home.Id)
-                            {
-                                //鑳藉鎼滅储寰楀埌缃戝叧
-                                canReceiveGw = true;
-                                break;
-                            }
-                        }
-                        UserCenterResourse.DicReceiveGatewayTest = null;
-                        //璁剧疆杩滅▼杩炴帴鐨勫垵濮嬪��
-                        ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false;
-                        if (canReceiveGw == false)
-                        {
-                            //濡傛灉鏄繙绋嬬殑璇�,杩藉姞绛夊緟鏃堕棿
-                            System.Threading.Thread.Sleep(1500);
-                        }
-                    }
-                    catch { }
+                    //浣忓畢鍒囨崲鏃�,妫�娴嬬綉鍏宠繛鎺ユ儏鍐�
+                    CheckGatewayConnection();
+
                 }
                 UserCenterResourse.DicReceiveGatewayTest = null;
             }
             //APP缂撳瓨鍔犺浇瀹屾垚
             UserCenterResourse.AccountOption.AppCanSignout = true;
+            if (Shared.Phone.Device.Logic.Send.If_Exist == "1")
+            {
+                //浠ユ湰鍦扮姸鎬佷负涓绘墦寮�GPS鏈嶅姟
+                Application.StartGPSLocationService();
+            }
 
             return true;
         }
@@ -933,6 +927,8 @@
             HdlRoomLogic.Current.RefreshAllRoomByLocation();
             //鍒锋柊宸﹁竟鍒锋柊鎴块棿瑙嗗浘鍒楄〃
             HdlRoomLogic.Current.RefreshRoomListView();
+            //鍔犺浇妯℃澘缂撳瓨
+            //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
         }
 
         /// <summary>
@@ -958,6 +954,35 @@
             Common.Logic.SoneLogicList.Clear();
         }
 
+        /// <summary>
+        /// 浣忓畢鍒囨崲鏃�,妫�娴嬬綉鍏宠繛鎺ユ儏鍐�
+        /// </summary>
+        private static void CheckGatewayConnection()
+        {
+            try
+            {
+                bool canReceiveGw = false;
+                foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values)
+                {
+                    if (gateway.HomeId == Config.Instance.Home.Id)
+                    {
+                        //鑳藉鎼滅储寰楀埌缃戝叧
+                        canReceiveGw = true;
+                        break;
+                    }
+                }
+                UserCenterResourse.DicReceiveGatewayTest = null;
+                //璁剧疆杩滅▼杩炴帴鐨勫垵濮嬪��
+                ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false;
+                if (canReceiveGw == false)
+                {
+                    //濡傛灉鏄繙绋嬬殑璇�,杩藉姞绛夊緟鏃堕棿
+                    System.Threading.Thread.Sleep(1500);
+                }
+            }
+            catch { }
+        }
+
         #endregion
 
         #region 鈻� 鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅_______________

--
Gitblit v1.8.0