From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 28 二月 2020 15:25:13 +0800
Subject: [PATCH] 2020.2.28

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs |  544 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 341 insertions(+), 203 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
old mode 100755
new mode 100644
index 7d859aa..f513304
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -29,6 +29,13 @@
         /// </param>
         public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
         {
+            //妫�娴嬫槸鍚﹀凡缁忓畬鎴愯处鍙蜂俊鎭垵濮嬪寲
+            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
+            {
+                //涓嶇缁撴灉鎬庝箞鏍�,濡傛灉璋冪敤浜嗚繖涓嚱鏁�,闇�瑕侀噸澶磋幏鍙朤oken,鎵�浠ュ繀椤昏繑鍥炲け璐�
+                await ReInitUserAccoutInfo();
+                return false;
+            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -63,6 +70,14 @@
         /// </param>
         public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
         {
+            //妫�娴嬫槸鍚﹀凡缁忓畬鎴愯处鍙蜂俊鎭垵濮嬪寲
+            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
+            {
+                //涓嶇缁撴灉鎬庝箞鏍�,濡傛灉璋冪敤浜嗚繖涓嚱鏁�,闇�瑕侀噸澶磋幏鍙朤oken,鎵�浠ュ繀椤昏繑鍥炲け璐�
+                await ReInitUserAccoutInfo();
+                return "Error";
+            }
+
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -96,6 +111,13 @@
         /// </param>
         public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
         {
+            //妫�娴嬫槸鍚﹀凡缁忓畬鎴愯处鍙蜂俊鎭垵濮嬪寲
+            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
+            {
+                //涓嶇缁撴灉鎬庝箞鏍�,濡傛灉璋冪敤浜嗚繖涓嚱鏁�,闇�瑕侀噸澶磋幏鍙朤oken,鎵�浠ュ繀椤昏繑鍥炲け璐�
+                await ReInitUserAccoutInfo();
+                return null;
+            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -139,6 +161,13 @@
         /// </param>
         public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
         {
+            //妫�娴嬫槸鍚﹀凡缁忓畬鎴愯处鍙蜂俊鎭垵濮嬪寲
+            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
+            {
+                //涓嶇缁撴灉鎬庝箞鏍�,濡傛灉璋冪敤浜嗚繖涓嚱鏁�,闇�瑕侀噸澶磋幏鍙朤oken,鎵�浠ュ繀椤昏繑鍥炲け璐�
+                await ReInitUserAccoutInfo();
+                return null;
+            }
             //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
             var connectMode = GetHttpConnectMode(checkAuthority);
             //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
@@ -259,6 +288,11 @@
         /// <param name="pra">璇锋眰鐨勫弬鏁�</param>
         public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null, object pra = null)
         {
+            if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
+            {
+                //涓嶆娴�
+                return true;
+            }
             if (revertObj == null)
             {
                 Application.RunOnMainThread(() =>
@@ -285,7 +319,7 @@
                         //濡傛灉鐢ㄦ埛宸茬粡閫�鍑轰簡鐧婚檰,鍒欎笉澶勭悊
                         return;
                     }
-                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
+                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj, pra);
                     if (msg != null)
                     {
                         var control = new ShowMsgControl(ShowMsgType.Tip, msg);
@@ -309,7 +343,7 @@
         /// </summary>
         /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄�</param>
         /// <returns></returns>
-        private static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
+        public static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
         {
             if (checkAuthority == false)
             {
@@ -345,7 +379,6 @@
             var formTemp = UserCenterResourse.DicActionForm[formName];
             formTemp.CloseForm();
             UserCenterResourse.DicActionForm.Remove(formName);
-            formTemp = null;
 
             return true;
         }
@@ -397,23 +430,29 @@
                         {
                             //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
                             UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
-                            if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
+                            //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
+                            if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                             {
                                 try
                                 {
-                                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
-                                    //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
-                                    int value = Myform.FormActionAgainEvent();
-                                    if (value == 1)
+                                    EditorCommonForm Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID] as EditorCommonForm;
+                                    if (Myform != null)
                                     {
-                                        //Log鍑哄姏
-                                        HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+                                        //閲嶇疆宸︽粦浣胯兘
+                                        Myform.ScrollEnabled = Myform.ScrollEnabled;
+                                        //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
+                                        int value = Myform.FormActionAgainEvent();
+                                        if (value == 1)
+                                        {
+                                            //Log鍑哄姏
+                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+                                        }
                                     }
                                 }
                                 catch (Exception ex)
                                 {
                                     //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
-                                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
+                                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                                     alert.Show();
 
                                     //Log鍑哄姏
@@ -428,23 +467,29 @@
                             {
                                 //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
                                 UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
-                                if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
+                                //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
+                                if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                                 {
                                     try
                                     {
-                                        var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
-                                        //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
-                                        int value = Myform.FormActionAgainEvent();
-                                        if (value == 1)
+                                        EditorCommonForm Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID] as EditorCommonForm;
+                                        if (Myform != null)
                                         {
-                                            //Log鍑哄姏
-                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+                                            //閲嶇疆宸︽粦浣胯兘
+                                            Myform.ScrollEnabled = Myform.ScrollEnabled;
+                                            //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
+                                            int value = Myform.FormActionAgainEvent();
+                                            if (value == 1)
+                                            {
+                                                //Log鍑哄姏
+                                                HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+                                            }
                                         }
                                     }
                                     catch (Exception ex)
                                     {
                                         //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
-                                        var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
+                                        var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                                         alert.Show();
 
                                         //Log鍑哄姏
@@ -458,9 +503,7 @@
                 //绉婚櫎ID
                 UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
                 //绉婚櫎鐢婚潰
-                var formTemp = UserCenterResourse.DicActionForm[formName];
                 UserCenterResourse.DicActionForm.Remove(formName);
-                formTemp = null;
             }
         }
 
@@ -502,18 +545,8 @@
         /// </summary>
         public static void RefreshAllMemory()
         {
-            //澶囦唤鐨勬暟鎹紝鏈夊彲鑳芥槸涓讳汉鑷繁涓婁紶鐨勶紝濡傛灉绠$悊鍛樼櫥闄嗘椂锛屼粬鑾峰彇鐨勫浠芥暟鎹湁鐐圭壒娈�
-            //姣斿涓嬮潰杩欎笁涓笢瑗垮湪涓昏处鍙烽偅閲屾槸涓嶉渶瑕佺殑
-            bool isOthreShare = Config.Instance.Home.IsOthreShare;
-            int accountType = Config.Instance.Home.AccountType;
-            string mainMark = Config.Instance.Home.MainUserDistributedMark;
-            //杩樺師浣忓畢瀵硅薄
-            Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
-            Config.Instance.Home.IsOthreShare = isOthreShare;
-            Config.Instance.Home.AccountType = accountType;
-            Config.Instance.Home.MainUserDistributedMark = mainMark;
-            Config.Instance.Home.Save();
-
+            //鍒锋柊浣忓畢瀵硅薄
+            RefreshHomeObject();
             //鍒锋柊鏈湴缃戝叧鏂囦欢
             HdlGatewayLogic.Current.ReFreshByLocal();
             //鍒锋柊鏈湴璁惧
@@ -522,6 +555,29 @@
             HdlGatewayLogic.Current.SynchronizeDbGateway();
             //浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿
             Common.Room.RefreshAllRoomByLocation();
+
+        }
+
+        /// <summary>
+        /// 鍒锋柊浣忓畢瀵硅薄
+        /// </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 = House.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;
+            Config.Instance.Home.Save(false);
         }
 
         #endregion
@@ -572,11 +628,6 @@
                 //涓嶈兘鍒犻櫎Config鏂囦欢
                 return true;
             }
-            else if (fileName.StartsWith("DeviceUI_") == true)
-            {
-                //涓嶈兘鍒犻櫎璁惧UI鏂囦欢
-                return true;
-            }
             else if (fileName.StartsWith("House_") == true)
             {
                 //涓嶈兘鍒犻櫎浣忓畢鏂囦欢
@@ -598,10 +649,9 @@
         {
             UserCenterResourse.Option.OldAccountId = string.Empty;
             //鍏抽棴鎵�鏈夋帴鏀�
-            HdlDeviceAttributeLogic.Current.RemoveAllEvent();
+            HdlGatewayReceiveLogic.Current.RemoveAllEvent();
             //娓呴櫎鍗囩骇鍒楄〃
-            FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
-            FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
+            FirmwareUpdateResourse.dicUpdateList.Clear();
 
             HdlThreadLogic.Current.RunThread(async () =>
             {
@@ -619,16 +669,11 @@
                 HdlGatewayLogic.Current.ClearAllRealGateway();
                 try
                 {
-                    ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
-                    ZigBee.Device.ZbGateway.RemoteMqttClient = null;
+                    //鏂紑杩滅▼Mqtt杩炴帴
+                    ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                 }
                 catch { }
 
-                if (noticeDb == true)
-                {
-                    //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
-                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
-                }
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
@@ -639,35 +684,42 @@
                     Shared.Common.CommonPage.Instance.AddChidren(formLogin);
                     formLogin.Show(account);
                 });
+
+                if (noticeDb == true)
+                {
+                    //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
+                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
+                }
             });
         }
 
         /// <summary>
         /// 鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
         /// </summary>
-        public static void CloseAllOpenForm()
+        /// <param name="tagetFrom">鐩爣鐣岄潰,濡傛灉鎸囧畾浜嗙殑璇�,鍒欏叧闂洰鏍囩晫闈笂灞傜殑鍏ㄩ儴鐣岄潰(瀹冭嚜韬笉鍏抽棴)</param>
+        public static void CloseAllOpenForm(string tagetFrom = "")
         {
-            var listForm = new List<CommonFormBase>();
-            var listId = new List<string>();
-            foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
+            while (UserView.HomePage.Instance.ChildrenCount > 0)
             {
-                if (form.FormID != "UserMainForm")
+                var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
+                if (view is CommonFormBase)
                 {
-                    listForm.Insert(0, form);
-                    listId.Add(form.FormID);
+                    if (((CommonFormBase)view).FormID == tagetFrom)
+                    {
+                        //鍙叧闂埌鎸囧畾鐩爣鐣岄潰
+                        return;
+                    }
+                    ((CommonFormBase)view).CloseForm();
+                }
+                else if (view is UserView.UserPage)
+                {
+                    return;
+                }
+                else
+                {
+                    view.RemoveFromParent();
                 }
             }
-            foreach (var id in listId)
-            {
-                UserCenterResourse.DicActionForm.Remove(id);
-            }
-
-            //鍏抽棴鎵�鏈夌敾闈�
-            foreach (CommonFormBase form in listForm)
-            {
-                form.CloseForm();
-            }
-            listForm.Clear();
         }
 
         #endregion
@@ -784,18 +836,38 @@
         /// <summary>
         /// 寮傛鏂规硶鎵ц(浠呴檺鍒囨崲浣忓畢鏃惰皟鐢�)锛屽埛鏂颁釜浜轰腑蹇冪殑鍐呭瓨鍙婄嚎绋�
         /// </summary>
-        public async static Task<bool> InitUserCenterMenmoryAndThread()
+        /// <param name="ShowPrompted">鏂拌拷鍔犲彉閲忥細鏄惁鏄剧ず鎻愮ず鑷姩澶囦唤鐨勭晫闈�</param>
+        /// <returns></returns>
+        public async static Task<bool> InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
         {
             //APP缂撳瓨鍔犺浇寮�濮�
             UserCenterResourse.Option.AppCanSignout = false;
-
-            //寮哄埗鎸囧畾涓嶅叧闂繘搴︽潯
-            ProgressBar.SetCloseBarFlag(true);
+            //杩樺師杩滅▼杩炴帴鍙橀噺
+            ZigBee.Device.ZbGateway.AllowRemoteCtrl = true;
 
             //鍙湁鍦ㄤ綇瀹匢D涓嶄竴鏍风殑鏃跺�欐墠鍋氳繖涓搷浣�
             if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
                 || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
             {
+                try
+                {
+                    //鏂紑杩滅▼Mqtt杩炴帴
+                    await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
+                }
+                catch { }
+
+                //娑堟伅璁板綍閲嶆柊璇诲彇鍙婃娴�
+                ControlCommonResourse.ReadMessageAgain = true;
+                ControlCommonResourse.HadNewMessage = false;
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    for (int i = 0; i < ControlCommonResourse.listMessageManaContr.Count; i++)
+                    {
+                        //鏄剧ず瑙掓爣鐗规晥
+                        ControlCommonResourse.listMessageManaContr[i].IsSelected = false;
+                    }
+                });
+
                 //鍔犺浇璐﹀彿閰嶇疆淇℃伅
                 var optionInfo = UserCenterResourse.Option.Load();
                 UserCenterResourse.Option = optionInfo;
@@ -803,25 +875,26 @@
                 UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
 
                 //鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅
-                await InitUserAccoutInfo();
-                //鍒濆鍖栫鐞嗗憳鏉冮檺淇℃伅
-                await InitAdminConnectMqttInfo(true);
+                var hadNet = await InitUserAccoutInfo();
+                //濡傛灉鏈夌綉缁滅殑璇�
+                if (hadNet == true)
+                {
+                    //閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
+                    HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
+                    //璇诲彇闅愬尶閰嶇疆
+                    await HdlBackupLogic.Current.LoadHideOption();
+                }
 
                 //鍒濆鍖栫紦瀛樻垚鍛樼殑淇℃伅
                 InitLocalMemberListInfo();
-
-                //閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
-                HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
 
                 //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
                 CreatAllUserCenterDirectory();
 
                 //鍏抽棴鎵�鏈夋帴鏀�
-                HdlDeviceAttributeLogic.Current.RemoveAllEvent();
+                HdlGatewayReceiveLogic.Current.RemoveAllEvent();
                 //鍒锋柊瀹夐槻涓婃姤淇℃伅
                 HdlAlarmsLogic.Current.RefreshAlarmInfo();
-                //娣诲姞淇濆瓨瀹夐槻璁惧鎶ヨ鐨勪簨浠�(涓嶉渶瑕佸啀鎵ц浠讳綍鎿嶄綔,骞朵笖姘镐箙瀛樺湪)
-                HdlAlarmsLogic.Current.AddAlarmInfoEvent();
 
                 //淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
                 SaveUserInformationToLocation();
@@ -830,15 +903,22 @@
                 UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
 
                 //鍚屾鏁版嵁(浜屾璋冪敤娌″叧绯�)
-                var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
+                int result = -1;
+                if (hadNet == true)
+                {
+                    result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
+                }
 
                 //鍒濆鍖栨湰鍦扮殑缃戝叧淇℃伅
                 HdlGatewayLogic.Current.ReFreshByLocal();
                 //鍒濆鍖栨湰鍦扮殑璁惧淇℃伅
                 Common.LocalDevice.Current.ReFreshByLocal();
 
-                //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
-                HdlGatewayLogic.Current.SynchronizeDbGateway();
+                if (hadNet == true)
+                {
+                    //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
+                    HdlGatewayLogic.Current.SynchronizeDbGateway();
+                }
 
                 //鍒濆鍖栨埧闂�(閮洩鍩庨偅杈逛笉鍋氬鐞�,闇�瑕佽繖閲岀壒娈婃墽琛屼竴姝�)
                 Room.RefreshAllRoomByLocation();
@@ -846,19 +926,15 @@
                 //鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D(鍙互鍙嶅璋冪敤,闇�瑕佸湪缃戝叧鍒濆鍖栧畬浜嗕箣鍚庢墠鑳借皟鐢�)
                 HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
 
-                //娓呯┖寮哄埗鎸囧畾鏂囨湰鐨勯檮鍔犱俊鎭�
-                ProgressBar.SetAppendText(string.Empty);
-
                 //0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�,杩欎釜鏃跺�欓渶瑕佹彁绀哄浠�
-                //if (result == 0)
-                //{
-                //    //寮�鍚嚜鍔ㄥ浠芥彁绀�
-                //    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
-                //}
+                if (result == 0 && ShowPrompted == true)
+                {
+                    //寮�鍚嚜鍔ㄥ浠芥彁绀�
+                    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
+                }
+                //鏄剧ず寮曞鐣岄潰
+                ShowGuideForm(result);
             }
-
-            //鎭㈠鍙叧闂繘搴︽潯
-            ProgressBar.SetCloseBarFlag(false);
             //APP缂撳瓨鍔犺浇瀹屾垚
             UserCenterResourse.Option.AppCanSignout = true;
 
@@ -875,22 +951,32 @@
         /// <returns></returns>
         private async static Task<bool> InitUserAccoutInfo()
         {
+            //鍒濆鍖栦釜浜轰俊鎭殑鏍囪瘑
+            UserCenterResourse.UserInfo.InitUserInfoSuccess = false;
             //鑾峰彇鏈湴璁板綍鐨勭敤鎴蜂俊鎭�
             UserCenterResourse.UserInfo = GetUserInformationFromLocation();
             UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
+            //鍏堟牴鎹湰鍦扮紦瀛樿缃垵濮嬪��
+            Config.Instance.isAdministrator = UserCenterResourse.UserInfo.AuthorityNo != 1;
 
             //鑾峰彇鐧诲綍璐﹀彿鐨勪俊鎭�
             var pra = new AccountInfoPra();
-            var listNotShow = new List<string>() { "NotSetAgain" };
-            string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetAccountInfo", false, pra, listNotShow);
-            if (string.IsNullOrEmpty(result) == true)
+            //搴忓垪鍖栧璞�
+            var requestJson = JsonConvert.SerializeObject(pra);
+            //璁块棶鎺ュ彛
+            byte[] byteData = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson));
+            if (byteData == null)
             {
-                //鏂綉鐨勮瘽锛岃骞插槢灏卞共鍢涘惂,鎬讳箣涓嶈兘鎺т富浜虹殑涓滆タ
-                Config.Instance.isAdministrator = false;
+                return false;
+            }
+            //妫�娴嬮敊璇�
+            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
+            if (revertObj.StateCode.ToUpper() != "SUCCESS")
+            {
                 return false;
             }
 
-            var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(result);
+            var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(revertObj.ResponseData.ToString());
             userInfo.Account = Common.Config.Instance.Account;
             if (string.IsNullOrEmpty(userInfo.UserName) == true)
             {
@@ -923,22 +1009,23 @@
                 string dirPath = CombinePath();
                 if (System.IO.Directory.Exists(dirPath) == true)
                 {
-                    //鍏堣褰曡捣浣忓畢鐨勪竴浜涗俊鎭�
-                    var house = House.GetHouseByHouseId(Config.Instance.HomeId);
-                    //鍒犻櫎鏁翠釜鏂囦欢澶�
-                    System.IO.Directory.Delete(dirPath, true);
+                    try
+                    {
+                        //鍚屾鏁版嵁鐨勫垽鏂枃浠�(浠ラ槻涓囦竴鍒犻櫎鏁翠釜鏂囦欢澶瑰け璐ョ殑鏃跺��,杩欎釜鏂囦欢琚垹鐨勮瘽,搴旇娌′粈涔堝ぇ闂)
+                        string SynchronizeFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
+                        //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
+                        if (System.IO.File.Exists(SynchronizeFile) == true)
+                        {
+                            System.IO.File.Delete(SynchronizeFile);
+                        }
+                        //鍒犻櫎鏁翠釜鏂囦欢澶�
+                        System.IO.Directory.Delete(dirPath, true);
+                    }
+                    catch { }
                     //鍒涘缓浣忓畢鏂囦欢澶�
                     Global.CreateHomeDirectory(Config.Instance.HomeId);
                     //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
                     CreatAllUserCenterDirectory();
-
-                    var newHouse = new House();
-                    newHouse.Id = house.Id;
-                    newHouse.Name = house.Name;
-                    newHouse.IsOthreShare = house.IsOthreShare;
-                    newHouse.AccountType = house.AccountType;
-                    newHouse.MainUserDistributedMark = house.MainUserDistributedMark;
-                    newHouse.Save();
                 }
             }
             if (string.IsNullOrEmpty(userInfo.UserName) == true)
@@ -949,11 +1036,25 @@
 
             UserCenterResourse.UserInfo = userInfo;
             UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
+            if (UserCenterResourse.UserInfo.HeadImage != null)
+            {
+                //鍐欏叆澶村儚鍐呭
+                Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
+            }
+            UserCenterResourse.UserInfo.HeadImage = null;
+            //鎵嬪娍瀵嗙爜
+            UserCenterResourse.Option.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd;
+            UserCenterResourse.UserInfo.GesturePwd = null;
+            //瀵嗙爜楠岃瘉
+            UserCenterResourse.Option.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
+            UserCenterResourse.UserInfo.StringPwd = null;
 
             //鍒濆鍖栫鐞嗗憳鎺у埗涓讳汉鐨勮繛鎺ュ湴鍧�(鍥犱负杩欎釜杩炴帴Token鏄笉浼氭敼鍙樼殑,鎵�浠ュ彧闇�瑕佸垵濮嬪寲涓�娆�)
-            await InitAdminConnectMainInfo();
+            bool flage = await InitAdminConnectMainInfo();
+            //鍒濆鍖栦釜浜轰俊鎭殑鏍囪瘑
+            UserCenterResourse.UserInfo.InitUserInfoSuccess = flage;
 
-            return true;
+            return flage;
         }
 
         /// <summary>
@@ -973,6 +1074,26 @@
         }
 
         /// <summary>
+        /// 閲嶆柊鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅(鏃ㄥ湪瀵瑰簲閭d竴鐬棿,缃戠粶涓嶅ソ,瀵艰嚧璇垽鐨勬儏鍐�)
+        /// </summary>
+        /// <returns></returns>
+        private async static Task<bool> ReInitUserAccoutInfo()
+        {
+            //閲嶆柊鍒濆鍖栬处鍙蜂俊鎭�
+            var result = await InitUserAccoutInfo();
+            if (result == false)
+            {
+                return result;
+            }
+            //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
+            HdlGatewayLogic.Current.SynchronizeDbGateway();
+            //鍒濆鍖栦釜浜轰俊鎭殑鏍囪瘑
+            UserCenterResourse.UserInfo.InitUserInfoSuccess = true;
+
+            return true;
+        }
+
+        /// <summary>
         /// 淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
         /// </summary>
         private static void SaveUserInformationToLocation()
@@ -987,13 +1108,12 @@
             {
                 return;
             }
-            string nowFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
-            if (System.IO.File.Exists(nowFile) == true)
+            if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
             {
                 return;
             }
             //澶嶅埗杩囧幓
-            System.IO.File.Copy(defultFile, nowFile);
+            System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile);
         }
 
         #endregion
@@ -1004,16 +1124,11 @@
         /// 鍒濆鍖栫鐞嗗憳鏉冮檺杩滅▼杩炴帴涓讳汉鐨勪俊鎭�
         /// </summary>
         /// <returns></returns>
-        public static async Task<bool> InitAdminConnectMainInfo()
+        private static async Task<bool> InitAdminConnectMainInfo()
         {
-            //鍏堟竻绌�
-            Config.Instance.isAdministrator = false;
-            Config.Instance.AdminRequestBaseUrl = string.Empty;
-            Config.Instance.AdminRequestToken = string.Empty;
-
-            if (UserCenterResourse.UserInfo.AuthorityNo != 2)
+            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
             {
-                //鎷ユ湁绠$悊鍛樻潈闄愮殑鎴愬憳鎵嶈兘杩欐牱鎼�,  杩欓噷蹇呴』鏄�2
+                //鏃朵唬鍙樹簡,杩欓噷绠$悊鍛樺拰鎴愬憳閮借兘璋冪敤
                 return true;
             }
             var pra = new
@@ -1024,56 +1139,26 @@
                 SharedHid = Config.Instance.Home.Id
             };
 
-            var listNotShow = new List<string>() { "NotSetAgain" };
-            var result = await GetResponseDataByRequestHttps("App/GetSharedHomeApiControl", false, pra, listNotShow);
-            if (string.IsNullOrEmpty(result) == true)
+            //搴忓垪鍖栧璞�
+            var requestJson = JsonConvert.SerializeObject(pra);
+            //璁块棶鎺ュ彛
+            byte[] byteData = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson));
+            if (byteData == null)
+            {
+                return false;
+            }
+            //妫�娴嬮敊璇�
+            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
+            if (revertObj.StateCode.ToUpper() != "SUCCESS")
             {
                 return false;
             }
 
             Config.Instance.isAdministrator = true;
             //鍒嗕韩閾炬帴
-            var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
+            var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(revertObj.ResponseData.ToString());
             Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
             Config.Instance.AdminRequestToken = info.RequestToken;
-
-            return true;
-        }
-
-        /// <summary>
-        /// 鍒濆鍖栫鐞嗗憳鏉冮檺鐨勮繙绋嬭繛鎺ヤ俊鎭�
-        /// </summary>
-        /// <param name="stopRemote">鏄惁涓柇杩滅▼</param>
-        /// <returns></returns>
-        public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
-        {
-            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
-            {
-                //鍙湁鎴愬憳鍒嗚韩鎵嶈兘璋冪敤杩欎釜鍑芥暟
-                return true;
-            }
-            var praMqtt = new
-            {
-                CommonPage.RequestVersion,
-                LoginAccessToken = Config.Instance.Token,
-                Config.Instance.Home.MainUserDistributedMark,
-                HomeId = Config.Instance.Home.Id
-            };
-
-            var listNotShow = new List<string>() { "NotSetAgain" };
-            var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
-            if (string.IsNullOrEmpty(result2) == true)
-            {
-                return false;
-            }
-
-            //杩滅▼Mqtt
-            var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
-            Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
-            Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
-            Config.Instance.AdminMqttKey = info2.MqttKey;
-            Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
-            Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
 
             return true;
         }
@@ -1179,6 +1264,36 @@
 
         #endregion
 
+        #region 鈻� 寮曞鐣岄潰___________________________
+
+        /// <summary>
+        /// 鏄剧ず寮曞鐣岄潰
+        /// </summary>
+        /// <param name="result">鍚屾缁撴灉 -1锛氬紓甯�   0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�  1锛氭甯稿悓姝�  2:娌℃湁鑷姩澶囦唤鏁版嵁</param>
+        private static void ShowGuideForm(int result)
+        {
+            var checkFile = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, DirNameResourse.GuideFile);
+            if (System.IO.File.Exists(checkFile) == true)
+            {
+                //涓嶉渶瑕佹樉绀�
+                return;
+            }
+            if (result == 2 && Config.Instance.Home.IsOthreShare == false)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new Guide.GuideHouseForm();
+                    form.ShowFrom();
+                });
+            }
+
+            //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚寮曞)
+            var file = System.IO.File.Create(checkFile);
+            file.Close();
+        }
+
+        #endregion
+
         #region 鈻� 16杩涘埗杞寲_________________________
 
         /// <summary>
@@ -1228,24 +1343,28 @@
         /// <returns></returns>
         public static string EncryptPassword(string keys, string strPsw)
         {
-            if (strPsw == string.Empty)
+            try
             {
-                return strPsw;
+                if (strPsw == string.Empty)
+                {
+                    return strPsw;
+                }
+                var des = new System.Security.Cryptography.DESCryptoServiceProvider();
+                byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
+                des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
+                des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
+                var ms = new System.IO.MemoryStream();
+                var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
+                cs.Write(inputByteArray, 0, inputByteArray.Length);
+                cs.FlushFinalBlock();
+                StringBuilder ret = new StringBuilder();
+                foreach (byte b in ms.ToArray())
+                {
+                    ret.AppendFormat("{0:X2}", b);
+                }
+                return ret.ToString().ToLower();
             }
-            var des = new System.Security.Cryptography.DESCryptoServiceProvider();
-            byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
-            des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
-            des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
-            var ms = new System.IO.MemoryStream();
-            var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
-            cs.Write(inputByteArray, 0, inputByteArray.Length);
-            cs.FlushFinalBlock();
-            StringBuilder ret = new StringBuilder();
-            foreach (byte b in ms.ToArray())
-            {
-                ret.AppendFormat("{0:X2}", b);
-            }
-            return ret.ToString();
+            catch { return strPsw; }
         }
 
         /// <summary>
@@ -1255,32 +1374,51 @@
         /// <returns></returns>
         public static string DecryptPassword(string keys, string strPsw)
         {
-            if (strPsw == string.Empty)
+            try
             {
-                return strPsw;
+                if (strPsw == string.Empty)
+                {
+                    return strPsw;
+                }
+                var des = new System.Security.Cryptography.DESCryptoServiceProvider();
+
+                byte[] inputByteArray = new byte[strPsw.Length / 2];
+                for (int x = 0; x < strPsw.Length / 2; x++)
+                {
+                    int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
+                    inputByteArray[x] = (byte)i;
+                }
+
+                des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
+                des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
+                var ms = new System.IO.MemoryStream();
+                var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
+                cs.Write(inputByteArray, 0, inputByteArray.Length);
+                cs.FlushFinalBlock();
+
+                StringBuilder ret = new StringBuilder();
+
+                return System.Text.Encoding.Default.GetString(ms.ToArray());
             }
-            var des = new System.Security.Cryptography.DESCryptoServiceProvider();
-
-            byte[] inputByteArray = new byte[strPsw.Length / 2];
-            for (int x = 0; x < strPsw.Length / 2; x++)
-            {
-                int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
-                inputByteArray[x] = (byte)i;
-            }
-
-            des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
-            des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
-            var ms = new System.IO.MemoryStream();
-            var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
-            cs.Write(inputByteArray, 0, inputByteArray.Length);
-            cs.FlushFinalBlock();
-
-            StringBuilder ret = new StringBuilder();
-
-            return System.Text.Encoding.Default.GetString(ms.ToArray());
+            catch { return strPsw; }
         }
         #endregion
 
+        #region 鈻� 鏃堕棿杞崲___________________________
+
+        /// <summary>
+        /// 灏唘tc鏃堕棿绫诲瀷鐨勫瓧绗︿覆,杞崲涓烘湰鍦版椂闂�
+        /// </summary>
+        /// <param name="timeText"></param>
+        /// <returns></returns>
+        public static DateTime ConvertUtcTimeToLocalTime(string timeText)
+        {
+            var utcTime = Convert.ToDateTime(timeText);
+            return TimeZoneInfo.ConvertTimeFromUtc(utcTime, TimeZoneInfo.Local);
+        }
+
+        #endregion
+
         #region 鈻� 鏂囦欢淇濆瓨鍜岃鍙朹____________________
 
         /// <summary>

--
Gitblit v1.8.0