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 |  448 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 292 insertions(+), 156 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 92abd67..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(() =>
@@ -345,7 +379,6 @@
             var formTemp = UserCenterResourse.DicActionForm[formName];
             formTemp.CloseForm();
             UserCenterResourse.DicActionForm.Remove(formName);
-            formTemp = null;
 
             return true;
         }
@@ -402,11 +435,13 @@
                             {
                                 try
                                 {
-                                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
-                                    if (Myform is EditorCommonForm)
+                                    EditorCommonForm Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID] as EditorCommonForm;
+                                    if (Myform != null)
                                     {
+                                        //閲嶇疆宸︽粦浣胯兘
+                                        Myform.ScrollEnabled = Myform.ScrollEnabled;
                                         //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
-                                        int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
+                                        int value = Myform.FormActionAgainEvent();
                                         if (value == 1)
                                         {
                                             //Log鍑哄姏
@@ -417,7 +452,7 @@
                                 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鍑哄姏
@@ -437,11 +472,13 @@
                                 {
                                     try
                                     {
-                                        var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
-                                        if (Myform is EditorCommonForm)
+                                        EditorCommonForm Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID] as EditorCommonForm;
+                                        if (Myform != null)
                                         {
+                                            //閲嶇疆宸︽粦浣胯兘
+                                            Myform.ScrollEnabled = Myform.ScrollEnabled;
                                             //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
-                                            int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
+                                            int value = Myform.FormActionAgainEvent();
                                             if (value == 1)
                                             {
                                                 //Log鍑哄姏
@@ -452,7 +489,7 @@
                                     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鍑哄姏
@@ -466,9 +503,7 @@
                 //绉婚櫎ID
                 UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
                 //绉婚櫎鐢婚潰
-                var formTemp = UserCenterResourse.DicActionForm[formName];
                 UserCenterResourse.DicActionForm.Remove(formName);
-                formTemp = null;
             }
         }
 
@@ -510,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();
             //鍒锋柊鏈湴璁惧
@@ -530,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
@@ -603,8 +651,7 @@
             //鍏抽棴鎵�鏈夋帴鏀�
             HdlGatewayReceiveLogic.Current.RemoveAllEvent();
             //娓呴櫎鍗囩骇鍒楄〃
-            FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
-            FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
+            FirmwareUpdateResourse.dicUpdateList.Clear();
 
             HdlThreadLogic.Current.RunThread(async () =>
             {
@@ -622,15 +669,11 @@
                 HdlGatewayLogic.Current.ClearAllRealGateway();
                 try
                 {
-                    ZigBee.Device.ZbGateway.DisRemoteMqttClientConnect();
+                    //鏂紑杩滅▼Mqtt杩炴帴
+                    ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                 }
                 catch { }
 
-                if (noticeDb == true)
-                {
-                    //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
-                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
-                }
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
@@ -641,24 +684,36 @@
                     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 = "")
         {
             while (UserView.HomePage.Instance.ChildrenCount > 0)
             {
                 var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
                 if (view is CommonFormBase)
                 {
+                    if (((CommonFormBase)view).FormID == tagetFrom)
+                    {
+                        //鍙叧闂埌鎸囧畾鐩爣鐣岄潰
+                        return;
+                    }
                     ((CommonFormBase)view).CloseForm();
                 }
                 else if (view is UserView.UserPage)
                 {
-                    break;
+                    return;
                 }
                 else
                 {
@@ -781,17 +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;
+            //杩樺師杩滅▼杩炴帴鍙橀噺
+            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;
@@ -799,15 +875,18 @@
                 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();
@@ -824,18 +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();
-
-                //鍒濆鍖栦綇瀹呭璞�
-                Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
+                if (hadNet == true)
+                {
+                    //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
+                    HdlGatewayLogic.Current.SynchronizeDbGateway();
+                }
 
                 //鍒濆鍖栨埧闂�(閮洩鍩庨偅杈逛笉鍋氬鐞�,闇�瑕佽繖閲岀壒娈婃墽琛屼竴姝�)
                 Room.RefreshAllRoomByLocation();
@@ -844,11 +927,13 @@
                 HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
 
                 //0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�,杩欎釜鏃跺�欓渶瑕佹彁绀哄浠�
-                //if (result == 0)
-                //{
-                //    //寮�鍚嚜鍔ㄥ浠芥彁绀�
-                //    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
-                //}
+                if (result == 0 && ShowPrompted == true)
+                {
+                    //寮�鍚嚜鍔ㄥ浠芥彁绀�
+                    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
+                }
+                //鏄剧ず寮曞鐣岄潰
+                ShowGuideForm(result);
             }
             //APP缂撳瓨鍔犺浇瀹屾垚
             UserCenterResourse.Option.AppCanSignout = true;
@@ -866,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)
             {
@@ -914,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)
@@ -954,9 +1050,11 @@
             UserCenterResourse.UserInfo.StringPwd = null;
 
             //鍒濆鍖栫鐞嗗憳鎺у埗涓讳汉鐨勮繛鎺ュ湴鍧�(鍥犱负杩欎釜杩炴帴Token鏄笉浼氭敼鍙樼殑,鎵�浠ュ彧闇�瑕佸垵濮嬪寲涓�娆�)
-            await InitAdminConnectMainInfo();
+            bool flage = await InitAdminConnectMainInfo();
+            //鍒濆鍖栦釜浜轰俊鎭殑鏍囪瘑
+            UserCenterResourse.UserInfo.InitUserInfoSuccess = flage;
 
-            return true;
+            return flage;
         }
 
         /// <summary>
@@ -973,6 +1071,26 @@
             }
             var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
             return info;
+        }
+
+        /// <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>
@@ -1006,13 +1124,8 @@
         /// 鍒濆鍖栫鐞嗗憳鏉冮檺杩滅▼杩炴帴涓讳汉鐨勪俊鎭�
         /// </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 && UserCenterResourse.UserInfo.AuthorityNo != 3)
             {
                 //鏃朵唬鍙樹簡,杩欓噷绠$悊鍛樺拰鎴愬憳閮借兘璋冪敤
@@ -1026,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;
         }
@@ -1181,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>
@@ -1230,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>
@@ -1257,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