From 0d9f64668fd7350d6a21fd157e32009a96d98134 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期三, 16 十二月 2020 13:09:08 +0800
Subject: [PATCH] 新云端代码Ver1.2

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayBackupLogic.cs |  996 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 511 insertions(+), 485 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayBackupLogic.cs
similarity index 63%
rename from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs
rename to ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayBackupLogic.cs
index dae74bf..ad7d915 100644
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayBackupLogic.cs
@@ -3,7 +3,7 @@
 using System.Text;
 using ZigBee.Device;
 
-namespace Shared.Phone.UserCenter
+namespace Shared.Phone
 {
     /// <summary>
     /// 缃戝叧澶囦唤涓氬姟鐨勯�昏緫
@@ -38,9 +38,9 @@
         /// <summary>
         /// 缃戝叧鎵ц澶囦唤
         /// </summary>
-        /// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param>
+        /// <param name="gatewayId">缃戝叧ID</param>
         /// <param name="backupName">闇�瑕佸垱寤虹殑澶囦唤鐨勫悕瀛�</param>
-        public void DoBackupGateway(ZbGateway realGateway, string backupName)
+        public void DoBackupGateway(string gatewayId, string backupName)
         {
             //灞曞紑杩涘害鏉�
             ProgressFormBar.Current.Start();
@@ -48,8 +48,8 @@
             ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uCreatBackupFile));
             System.Threading.Thread.Sleep(1000);
 
-            //鍒涘缓涓�涓浠藉悕瀛�
-            string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backupName, 2, realGateway.GwId);
+            //鍒涘缓涓�涓浠�
+            string backupClassId = this.CreatGatewayBackup(gatewayId, backupName);
             if (backupClassId == null)
             {
                 //鍏抽棴杩涘害鏉�
@@ -80,17 +80,516 @@
             //}
 
             //寮�濮嬩笂浼犳暟鎹�
-            bool result = this.StartUpLoadData(realGateway, backupClassId);
+            bool result = this.StartUpLoadData(gatewayId, backupClassId);
             if (result == false)
             {
                 //濡傛灉涓婁紶澶辫触鐨勮瘽锛屽氨鎶婂畠鍒犻櫎
-                HdlBackupLogic.Current.DeleteDbBackupData(backupClassId);
+                this.DeleteGatewayBackup(gatewayId, backupClassId);
                 //鍏抽棴杩涘害鏉�
                 ProgressFormBar.Current.Close();
                 return;
             }
             //鍏抽棴杩涘害鏉�
             ProgressFormBar.Current.Close();
+        }
+
+        /// <summary>
+        /// 鍒犻櫎缃戝叧澶囦唤
+        /// </summary>
+        /// <param name="i_gwId">缃戝叧id</param>
+        /// <param name="i_backupId">澶囦唤鐨勪富閿�</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <returns></returns>
+        public bool DeleteGatewayBackup(string i_gwId, string i_backupId, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            var pra = new { gatewayId = i_gwId, folderId = i_backupId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/folder/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒涘缓缃戝叧澶囦唤(杩斿洖澶囦唤涓婚敭,杩斿洖null浠h〃澶辫触)
+        /// </summary>
+        /// <param name="gwId">缃戝叧id</param>
+        /// <param name="i_backName">澶囦唤鍚嶅瓧</param>
+        /// <returns></returns>
+        private string CreatGatewayBackup(string gwId, string i_backName)
+        {
+            //鍒涘缓涓�涓浠藉悕瀛�
+            var pra = new { backupClassify = "USER_DEFINED_BACKUP", backupDataType = "ZIGBEE", folderName = i_backName, gatewayId = gwId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/folder/add", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
+            {
+                return null;
+            }
+            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<IdInfoClass>(result.Data.ToString());
+            return info.Id;
+        }
+
+        #endregion
+
+        #region 鈻� 寮�濮嬬綉鍏虫暟鎹浠絖__________________
+
+        /// <summary>
+        /// 寮�濮嬩笂浼犳暟鎹�
+        /// </summary>
+        /// <param name="gatewayId"></param>
+        /// <param name="backupClassId"></param>
+        private bool StartUpLoadData(string gatewayId, string backupClassId)
+        {
+            //寮�濮嬪浠界綉鍏虫暟鎹�
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uStartBackupgatewayData));
+            ProgressFormBar.Current.SetValue(0);
+            System.Threading.Thread.Sleep(1000);
+
+            bool threadAction = true;
+            bool success = false;
+            //绛夊緟鏃堕棿
+            int waitime = 60;
+            //璁℃椂鏃堕棿
+            int TimeOut = 0;
+
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+            {
+                if (topic == gatewayId + "/BackupGwDataFile_Respon")
+                {
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                    var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
+                    if (statu == 1)
+                    {
+                        threadAction = false;
+                        //缃戝叧鏁版嵁澶囦唤澶辫触
+                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
+                        return;
+                    }
+                    if (statu == 2)
+                    {
+                        threadAction = false;
+                        success = true;
+                        //涓婁紶鏁版嵁鎴愬姛
+                        string msg2 = Language.StringByID(R.MyInternationalizationString.uUploadDataSuccess);
+                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg2);
+                    }
+                    //灏嗘椂闂村埛鏂�,鐒跺悗绛夊緟鏃堕棿鍙樻洿涓�30绉�
+                    TimeOut = 0;
+                    waitime = 300;
+                }
+                else if (topic == gatewayId + "/BackupGwDataFileProgress_Respon")
+                {
+                    //鍒锋柊绛夊緟鏃堕棿
+                    TimeOut = 0;
+                    //涓婁紶杩涘害鐧惧垎姣�
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                    var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
+                    if (statu != 0)
+                    {
+                        threadAction = false;
+                        //缃戝叧鏁版嵁澶囦唤澶辫触
+                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
+                        return;
+                    }
+                    //璁剧疆杩涘害鐧惧垎姣�
+                    var persent = Convert.ToInt32(jobject["Data"]["BackupPercent"].ToString());
+                    ProgressFormBar.Current.SetValue(persent, 100);
+                }
+            });
+            //鍙戦�佹暟鎹�
+            var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/gateway/file/create";
+            string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A璐﹀彿鏉冮檺);
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6200 } };
+            var data = new Newtonsoft.Json.Linq.JObject {
+                { "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
+            jObject.Add("Data", data);
+
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "BackupGwDataFile", jObject.ToString());
+          
+            while (threadAction == true && TimeOut < waitime)
+            {
+                System.Threading.Thread.Sleep(100);
+                TimeOut++;
+            }
+            //娓呴櫎浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+            if (TimeOut >= waitime)
+            {
+                //鍝嶅簲瓒呮椂,缃戝叧鏁版嵁澶囦唤澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndBackupgatewayDataFail);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+            System.Threading.Thread.Sleep(1000);
+
+            return success;
+        }
+
+        #endregion
+
+        #region 鈻� 浠庝簯绔幏鍙栧浠芥枃浠跺垪琛╛____________
+
+        /// <summary>
+        /// 浠庝簯绔幏鍙栫綉鍏崇殑澶囦唤鍒楄〃
+        /// </summary>
+        /// <param name="gatewayId">缃戝叧di</param>
+        /// <param name="backMode">鑾峰彇鐨勫浠界被鍨�</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        public List<BackupListNameInfo> GetGatewayBackupListFromDb(string gatewayId, BackUpMode backMode, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            var pra = new { mac = gatewayId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/folder/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return null;
+            }
+            var listTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BackupListNameInfo>>(result.Data.ToString());
+            var strDiv = HdlBackupLogic.Current.GetBackUpModeText(backMode);
+
+            var listData = new List<BackupListNameInfo>();
+            foreach (var info in listTemp)
+            {
+                if (info.BackupClassify != strDiv || info.BackupDataType != "ZIGBEE")
+                {
+                    //涓嶆槸鎸囧畾鐨勫浠�
+                    continue;
+                }
+                listData.Add(info);
+            }
+            return listData;
+        }
+
+        /// <summary>
+        /// 鍙戦�佷粠浜戠鑾峰彇澶囦唤鏂囦欢鍒楄〃鐨勫懡浠ょ粰缃戝叧
+        /// </summary>
+        /// <param name="gatewayId"></param>
+        /// <param name="backupClassId"></param>
+        /// <returns></returns>
+        private bool SendGetGatewayFileListComandToGateway(string gatewayId, string backupClassId)
+        {
+            //姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
+            ProgressFormBar.Current.SetValue(0);
+            System.Threading.Thread.Sleep(1000);
+
+            int result = -1;
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+            {
+                if (topic == gatewayId + "/GetDataFileList_Respon")
+                {
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                    result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
+                    if (result != 0)
+                    {
+                        //鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触
+                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail));
+                        return;
+                    }
+                }
+            });
+            //鍙戦�佹暟鎹�
+            var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/backup/file/findAll";
+            string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A璐﹀彿鏉冮檺);
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6202 } };
+            var data = new Newtonsoft.Json.Linq.JObject {
+                { "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
+            jObject.Add("Data", data);
+
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDataFileList", jObject.ToString());
+
+            int timeOut = 0;
+            while (result == -1 && timeOut < 30)
+            {
+                System.Threading.Thread.Sleep(1000);
+                timeOut++;
+            }
+            //绉婚櫎浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+            if (result != 0)
+            {
+                string msg = Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail);
+                if (result == -1)
+                {
+                    //鍝嶅簲瓒呮椂,鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触
+                    msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGetBackupFileListFail);
+                }
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 浠庝簯绔笅杞藉浠芥枃浠禵________________
+
+        /// <summary>
+        /// 鍙戦�佷粠浜戠涓嬭浇澶囦唤鏂囦欢鐨勫懡浠ゅ埌缃戝叧
+        /// </summary>
+        /// <param name="gatewayId"></param>
+        /// <param name="backupClassId"></param>
+        /// <returns></returns>
+        private bool SendDownloadGatewayFileComandToGateway(string gatewayId, string backupClassId)
+        {
+            //姝e湪涓嬭浇澶囦唤鏂囦欢
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading));
+            ProgressFormBar.Current.SetValue(0);
+            System.Threading.Thread.Sleep(1000);
+
+            bool threadAction = true;
+            bool success = false;
+            int timeOut = 0;
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+            {
+                if (topic == gatewayId + "/RestoreDataFileProgress_Respon")
+                {
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                    var result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
+                    if (result == 1 || result == 3)
+                    {
+                        //涓嬭浇澶囦唤鏂囦欢澶辫触
+                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uDownloadBackupFileFail));
+                        threadAction = false;
+                        return;
+                    }
+                    else if (result == 2)
+                    {
+                        //涓嬭浇鎴愬姛
+                        success = true;
+                        threadAction = false;
+                        return;
+                    }
+                    else if (result == 0)
+                    {
+                        //鍒锋柊绛夊緟鏃堕棿
+                        timeOut = 0;
+                        //璁剧疆杩涘害鐧惧垎姣�
+                        var persent = Convert.ToInt32(jobject["Data"]["RestoreDataPercent"].ToString());
+                        //缃戝叧涓嬭浇瀹屾垚涔嬪悗锛屽畠鑷繁浼氬崱涓�浼氾紝鎵嶄細鍙戦��2杩囨潵
+                        ProgressFormBar.Current.SetValue(persent - 1, 100);
+                    }
+                }
+            });
+
+            //鍙戦�佹暟鎹�
+            var fullUrl = HdlHttpLogic.Current.RequestHttpsHost + @"home-wisdom/gateway/file/downOne";
+            string authorization = Common.Config.Instance.HeaderPrefix + HdlHttpLogic.Current.GetHttpToken(CheckMode.A璐﹀彿鏉冮檺);
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6203 } };
+            var data = new Newtonsoft.Json.Linq.JObject {
+                { "url", fullUrl },{ "authorization", authorization },{ "folderId", backupClassId }};
+            jObject.Add("Data", data);
+
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDataFileList", jObject.ToString());
+
+            while (threadAction == true && timeOut < 30)
+            {
+                System.Threading.Thread.Sleep(1000);
+                timeOut++;
+            }
+            //绉婚櫎浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+            if (timeOut >= 30)
+            {
+                //鍝嶅簲瓒呮椂,涓嬭浇澶囦唤鏂囦欢澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndDownloadBackupFileFail);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+            return success;
+        }
+
+        #endregion
+
+        #region 鈻� 缂栬緫缃戝叧澶囦唤鍚嶇О___________________
+
+        /// <summary>
+        /// 缂栬緫缃戝叧澶囦唤鍚嶇О
+        /// </summary>
+        /// <param name="i_backId">澶囦唤鐨勪富閿�</param>
+        /// <param name="i_newName">澶囦唤鐨勬柊鍚嶇О</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <returns></returns>
+        public bool EditorGatewayBackupName(string i_backId, string i_newName, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            var pra = new { gatewayFolderId = i_backId, folderName = i_newName, homeId = Common.Config.Instance.Home.Id };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/folder/update", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 缃戝叧杩樺師___________________________
+
+        /// <summary>
+        /// 鎵ц缃戝叧杩樺師鎿嶄綔
+        /// </summary>
+        /// <param name="gatewayId">缃戝叧ID</param>
+        /// <param name="backupId">澶囦唤涓婚敭</param>
+        public bool RecoverGateway(string gatewayId, string backupId)
+        {
+            //灞曞紑杩涘害鏉�
+            ProgressFormBar.Current.Start();
+            //鍙戦�佷粠浜戠鑾峰彇澶囦唤鏂囦欢鍒楄〃鐨勫懡浠ょ粰缃戝叧
+            var result = this.SendGetGatewayFileListComandToGateway(gatewayId, backupId);
+            if (result == false)
+            {
+                //鍏抽棴杩涘害鏉�
+                ProgressFormBar.Current.Close();
+                return false;
+            }
+
+            //鍙戦�佷粠浜戠涓嬭浇澶囦唤鏂囦欢鐨勫懡浠ゅ埌缃戝叧
+            result = this.SendDownloadGatewayFileComandToGateway(gatewayId, backupId);
+            if (result == false)
+            {
+                //鍏抽棴杩涘害鏉�
+                ProgressFormBar.Current.Close();
+                return false;
+            }
+
+            ////鎭㈠鍗忚皟鍣╪v鍒嗗尯鐨勭粍缃戜俊鎭�
+            //result = this.RestoreGatewayNV(realGateway);
+            //if (result == false)
+            //{
+            //    //鍏抽棴杩涘害鏉�
+            //    ProgressFormBar.Current.Close();
+            //    return false;
+            //}
+
+            //鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳�
+            //result = this.OpenZbMsComSend(realGateway);
+            //if (result == false)
+            //{
+            //    //鍏抽棴杩涘害鏉�
+            //    ProgressFormBar.Current.Close();
+            //    return false;
+            //}
+
+            //閲嶅惎缃戝叧绯荤粺
+            result = this.GatewayReboot(gatewayId);
+            //鍏抽棴杩涘害鏉�
+            ProgressFormBar.Current.Close();
+            return result;
+        }
+
+        #endregion
+
+        #region 鈻� 閲嶅惎缃戝叧绯荤粺_______________________
+
+        /// <summary>
+        /// 閲嶅惎缃戝叧绯荤粺
+        /// </summary>
+        /// <param name="gatewayId"></param>
+        /// <returns></returns>
+        private bool GatewayReboot(string gatewayId)
+        {
+            //姝e湪閲嶅惎缃戝叧绯荤粺
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayRerooting));
+            ProgressFormBar.Current.SetValue(0);
+            System.Threading.Thread.Sleep(1000);
+
+            int result = -1;
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+            {
+                if (topic == gatewayId + "/" + "GwReboot_Respon")
+                {
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                    result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
+                }
+            });
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 83 } };
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GwReboot", jObject.ToString());
+
+            int timeOut = 0;
+            while (result == -1 && timeOut < 30)
+            {
+                System.Threading.Thread.Sleep(1000);
+                timeOut++;
+            }
+            //绉婚櫎浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+            if (result != 0)
+            {
+                //閲嶅惎缃戝叧绯荤粺澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayRerootFail);
+                if (result == -1)
+                {
+                    msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                }
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
+
+            //缃戝叧宸茬粡鎺ユ敹鍒伴噸鍚懡浠�,鎺ヤ笅鏉ュ幓鍒ゆ柇缃戝叧鏄惁閲嶅惎瀹屾垚
+            bool gatewatAction = false;
+            bool threadAction = true;
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                timeOut = 0;
+                while (gatewatAction == false)
+                {
+                    //澶ф缃戝叧閲嶅惎瑕�60绉�
+                    if (timeOut >= 65 && timeOut % 5 == 0)
+                    {
+                        //5绉掍竴娆�,鍘昏幏鍙栫増鏈�
+                        var data = HdlGatewayLogic.Current.RefreshGatewayInfo(gatewayId, false, ShowErrorMode.NO);
+                        if (data != null)
+                        {
+                            gatewatAction = true;
+                            threadAction = false;
+                            break;
+                        }
+                    }
+                    System.Threading.Thread.Sleep(1000);
+                    timeOut++;
+                    //璁剧疆杩涘害鍊�
+                    ProgressFormBar.Current.SetValue(timeOut, 180);
+                    if (timeOut >= 180)
+                    {
+                        //180绉掕繕绛変笉鍒扮殑璇濓紝缃戝叧搴旇鍑洪棶棰樹簡
+                        threadAction = false;
+                        break;
+                    }
+                }
+            });
+            while (threadAction == true)
+            {
+                System.Threading.Thread.Sleep(4000);
+            }
+            if (gatewatAction == true)
+            {
+                //璁剧疆杩涘害鍊�:100%
+                ProgressFormBar.Current.SetValue(1, 1);
+                System.Threading.Thread.Sleep(1000);
+                //缃戝叧鏁版嵁鎭㈠鎴愬姛!
+                string msg = Language.StringByID(R.MyInternationalizationString.uRestoreGatewayDataSuccess);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
+                return true;
+            }
+            else
+            {
+                //鍝嶅簲瓒呮椂,閲嶅惎缃戝叧绯荤粺澶辫触
+                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGatewayRerootFail);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
+                return false;
+            }
         }
 
         #endregion
@@ -140,9 +639,9 @@
                 string msg = Language.StringByID(R.MyInternationalizationString.uSaveGatewayNVFileFail);
                 if (result == -1)
                 {
-                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                    msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 }
-                this.ShowErrorMsg(msg);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
                 return false;
             }
 
@@ -193,366 +692,13 @@
                 string msg = Language.StringByID(R.MyInternationalizationString.uOpenZbMsComSendFail);
                 if (result == -1)
                 {
-                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
+                    msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
                 }
-                this.ShowErrorMsg(msg);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
                 return false;
             }
 
             return true;
-        }
-
-        #endregion
-
-        #region 鈻� 寮�濮嬬綉鍏虫暟鎹浠絖__________________
-
-        /// <summary>
-        /// 寮�濮嬩笂浼犳暟鎹�
-        /// </summary>
-        /// <param name="realGateway"></param>
-        /// <param name="backupClassId"></param>
-        private bool StartUpLoadData(ZbGateway realGateway, string backupClassId)
-        {
-            //寮�濮嬪浠界綉鍏虫暟鎹�
-            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uStartBackupgatewayData));
-            ProgressFormBar.Current.SetValue(0);
-            System.Threading.Thread.Sleep(1000);
-
-            bool threadAction = true;
-            bool success = false;
-            //绛夊緟鏃堕棿
-            int waitime = 60;
-            //璁℃椂鏃堕棿
-            int TimeOut = 0;
-
-            Action<string, string> action = (topic, message) =>
-            {
-                var gatewayID = topic.Split('/')[0];
-                if (topic == gatewayID + "/BackupGwDataFile_Respon")
-                {
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                    var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
-                    if (statu == 1)
-                    {
-                        threadAction = false;
-                        //缃戝叧鏁版嵁澶囦唤澶辫触
-                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
-                        return;
-                    }
-                    if (statu == 2)
-                    {
-                        threadAction = false;
-                        success = true;
-                        //涓婁紶鏁版嵁鎴愬姛
-                        string msg2 = Language.StringByID(R.MyInternationalizationString.uUploadDataSuccess);
-                        this.ShowTipMsg(msg2);
-                    }
-                    //灏嗘椂闂村埛鏂�,鐒跺悗绛夊緟鏃堕棿鍙樻洿涓�30绉�
-                    TimeOut = 0;
-                    waitime = 300;
-                }
-                else if (topic == gatewayID + "/BackupGwDataFileProgress_Respon")
-                {
-                    //鍒锋柊绛夊緟鏃堕棿
-                    TimeOut = 0;
-                    //涓婁紶杩涘害鐧惧垎姣�
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                    var statu = Convert.ToInt32(jobject["Data"]["Status"].ToString());
-                    if (statu != 0)
-                    {
-                        threadAction = false;
-                        //缃戝叧鏁版嵁澶囦唤澶辫触
-                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uBackupgatewayDataFail));
-                        return;
-                    }
-                    //璁剧疆杩涘害鐧惧垎姣�
-                    var persent = Convert.ToInt32(jobject["Data"]["BackupPercent"].ToString());
-                    ProgressFormBar.Current.SetValue(persent, 100);
-                }
-            };
-            realGateway.Actions += action;
-
-            //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
-            string fullUrl = string.Empty;
-            var connectMode = UserCenterLogic.GetHttpConnectMode(true);
-            if (connectMode == HttpConnectMode.Normal)
-            {
-                //鏅�氳闂�
-                fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/UploadHomeAppGatewaySubFiles"}";
-            }
-            else if (connectMode == HttpConnectMode.Admin)
-            {
-                //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛�
-                fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/UploadHomeAppGatewaySubFiles"}";
-            }
-
-            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6200 } };
-            var data = new Newtonsoft.Json.Linq.JObject {
-                { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion },
-                { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "BackupClassId", backupClassId },
-                { "ManualBackupType", 2 },{ "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0}
-            };
-            jObject.Add("Data", data);
-            realGateway.Send("BackupGwDataFile", jObject.ToString());
-
-            while (threadAction == true && TimeOut < waitime)
-            {
-                System.Threading.Thread.Sleep(100);
-                TimeOut++;
-            }
-            realGateway.Actions -= action;
-            if (TimeOut >= waitime)
-            {
-                //鍝嶅簲瓒呮椂,缃戝叧鏁版嵁澶囦唤澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndBackupgatewayDataFail);
-                this.ShowErrorMsg(msg);
-                return false;
-            }
-            System.Threading.Thread.Sleep(1000);
-
-            return success;
-        }
-
-        #endregion
-
-        #region 鈻� 缃戝叧杩樺師___________________________
-
-        /// <summary>
-        /// 鎵ц缃戝叧杩樺師鎿嶄綔
-        /// </summary>
-        /// <param name="realGateway">鐪熷疄鐗╃悊缃戝叧瀵硅薄</param>
-        /// <param name="backupId">澶囦唤涓婚敭</param>
-        /// <param name="isAutoBack">0:鑾峰彇缃戝叧鎵嬪姩澶囦唤鏂囦欢鍒楄〃 1:鑾峰彇缃戝叧鑷姩澶囦唤鏂囦欢鍒楄〃</param>
-        /// <param name="closeBar">鏄惁鍏抽棴杩涘害鏉�</param>
-        public bool RecoverGateway(ZbGateway realGateway, string backupId, int isAutoBack, bool closeBar = true)
-        {
-            //灞曞紑杩涘害鏉�
-            ProgressFormBar.Current.Start();
-            //浠庝簯绔幏鍙栧浠芥枃浠跺垪琛�
-            var result = this.GetGatewayFileList(realGateway, backupId, isAutoBack);
-            if (result == false)
-            {
-                //鍏抽棴杩涘害鏉�
-                ProgressFormBar.Current.Close();
-                return false;
-            }
-
-            //浠庝簯绔笅杞藉浠芥枃浠�
-            result = this.DownloadGatewayFile(realGateway, backupId, isAutoBack);
-            if (result == false)
-            {
-                //鍏抽棴杩涘害鏉�
-                ProgressFormBar.Current.Close();
-                return false;
-            }
-
-            ////鎭㈠鍗忚皟鍣╪v鍒嗗尯鐨勭粍缃戜俊鎭�
-            //result = this.RestoreGatewayNV(realGateway);
-            //if (result == false)
-            //{
-            //    //鍏抽棴杩涘害鏉�
-            //    ProgressFormBar.Current.Close();
-            //    return false;
-            //}
-
-            //鎵撳紑鍗忚皟鍣ㄤ覆鍙e彂閫佸姛鑳�
-            //result = this.OpenZbMsComSend(realGateway);
-            //if (result == false)
-            //{
-            //    //鍏抽棴杩涘害鏉�
-            //    ProgressFormBar.Current.Close();
-            //    return false;
-            //}
-
-            //閲嶅惎缃戝叧绯荤粺
-            result = this.GatewayReboot(realGateway);
-
-            if (result == true)
-            {
-                //鍒锋柊鍏ㄩ儴鍦烘櫙
-                HdlSceneLogic.Current.RefreshSceneUIList(false);
-                //鑾峰彇鍏ㄩ儴璁惧
-                Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(realGateway.GwId, false);
-            }
-            if (closeBar == true)
-            {
-                //鍏抽棴杩涘害鏉�
-                ProgressFormBar.Current.Close();
-            }
-            return result;
-        }
-
-        #endregion
-
-        #region 鈻� 浠庝簯绔幏鍙栧浠芥枃浠跺垪琛╛____________
-
-        /// <summary>
-        /// 浠庝簯绔幏鍙栧浠芥枃浠跺垪琛�
-        /// </summary>
-        /// <param name="realGateway"></param>
-        /// <param name="backupClassId"></param>
-        /// <returns></returns>
-        private bool GetGatewayFileList(ZbGateway realGateway, string backupClassId, int isAutoBack)
-        {
-            //姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃
-            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
-            System.Threading.Thread.Sleep(1000);
-
-            int result = -1;
-            Action<string, string> action = (topic, message) =>
-            {
-                var gatewayID = topic.Split('/')[0];
-                if (topic == gatewayID + "/GetDataFileList_Respon")
-                {
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                    result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
-                    if (result != 0)
-                    {
-                        //鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触
-                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail));
-                        return;
-                    }
-                }
-            };
-            realGateway.Actions += action;
-
-            //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
-            string fullUrl = string.Empty;
-            var connectMode = UserCenterLogic.GetHttpConnectMode(true);
-            if (connectMode == HttpConnectMode.Normal)
-            {
-                //鏅�氳闂�
-                fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/GetHomeDataBackupUploadListPagger"}";
-            }
-            else if (connectMode == HttpConnectMode.Admin)
-            {
-                //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛�
-                fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/GetHomeDataBackupUploadListPagger"}";
-            }
-
-            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6202 } };
-            var data = new Newtonsoft.Json.Linq.JObject {
-                { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion },
-                { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack },
-                { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId},
-                { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0}
-            };
-            jObject.Add("Data", data);
-            realGateway.Send("GetDataFileList", jObject.ToString());
-
-            int timeOut = 0;
-            while (result == -1 && timeOut < 30)
-            {
-                System.Threading.Thread.Sleep(1000);
-                timeOut++;
-            }
-            realGateway.Actions -= action;
-            if (result != 0)
-            {
-                string msg = Language.StringByID(R.MyInternationalizationString.uGetBackupFileListFail);
-                if (result == -1)
-                {
-                    //鍝嶅簲瓒呮椂,鑾峰彇澶囦唤鏂囦欢鍒楄〃澶辫触
-                    msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGetBackupFileListFail);
-                }
-                this.ShowErrorMsg(msg);
-                return false;
-            }
-            return true;
-        }
-
-        #endregion
-
-        #region 鈻� 浠庝簯绔笅杞藉浠芥枃浠禵________________
-
-        /// <summary>
-        /// 浠庝簯绔笅杞藉浠芥枃浠�
-        /// </summary>
-        /// <param name="realGateway"></param>
-        /// <param name="backupClassId"></param>
-        /// <returns></returns>
-        private bool DownloadGatewayFile(ZbGateway realGateway, string backupClassId, int isAutoBack)
-        {
-            //姝e湪涓嬭浇澶囦唤鏂囦欢
-            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileDownloading));
-            ProgressFormBar.Current.ResetProgressBar();
-            System.Threading.Thread.Sleep(1000);
-
-            bool threadAction = true;
-            bool success = false;
-            int timeOut = 0;
-            Action<string, string> action = (topic, message) =>
-            {
-                var gatewayID = topic.Split('/')[0];
-                if (topic == gatewayID + "/RestoreDataFileProgress_Respon")
-                {
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                    var result = Convert.ToInt32(jobject["Data"]["Status"].ToString());
-                    if (result == 1 || result == 3)
-                    {
-                        //涓嬭浇澶囦唤鏂囦欢澶辫触
-                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDownloadBackupFileFail));
-                        threadAction = false;
-                        return;
-                    }
-                    else if (result == 2)
-                    {
-                        //涓嬭浇鎴愬姛
-                        success = true;
-                        threadAction = false;
-                        return;
-                    }
-                    else if (result == 0)
-                    {
-                        //鍒锋柊绛夊緟鏃堕棿
-                        timeOut = 0;
-                        //璁剧疆杩涘害鐧惧垎姣�
-                        var persent = Convert.ToInt32(jobject["Data"]["RestoreDataPercent"].ToString());
-                        //缃戝叧涓嬭浇瀹屾垚涔嬪悗锛屽畠鑷繁浼氬崱涓�浼氾紝鎵嶄細鍙戦��2杩囨潵
-                        ProgressFormBar.Current.SetValue(persent - 1, 100);
-                    }
-                }
-            };
-            realGateway.Actions += action;
-
-            //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
-            string fullUrl = string.Empty;
-            var connectMode = UserCenterLogic.GetHttpConnectMode(true);
-            if (connectMode == HttpConnectMode.Normal)
-            {
-                //鏅�氳闂�
-                fullUrl = $"{Common.CommonPage.RequestHttpsHost}/{"App/DownloadSomeDataBackup"}";
-            }
-            else if (connectMode == HttpConnectMode.Admin)
-            {
-                //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛�
-                fullUrl = $"{Common.Config.Instance.AdminRequestBaseUrl}/{"App/DownloadSomeDataBackup"}";
-            }
-
-            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 6203 } };
-            var data = new Newtonsoft.Json.Linq.JObject {
-                { "url", fullUrl }, { "RequestVersion", Common.CommonPage.RequestVersion },
-                { "LoginAccessToken", UserCenterLogic.GetConnectMainToken() }, { "IsGatewayAutoBackup", isAutoBack },
-                { "BackupClassId", backupClassId },{ "GatewayUniqueId",realGateway.GwId},
-                { "IsOtherAccountCtrl",connectMode == HttpConnectMode.Admin?1:0}
-            };
-            jObject.Add("Data", data);
-            realGateway.Send("GetDataFileList", jObject.ToString());
-
-            while (threadAction == true && timeOut < 30)
-            {
-                System.Threading.Thread.Sleep(1000);
-                timeOut++;
-            }
-            realGateway.Actions -= action;
-            if (timeOut >= 30)
-            {
-                //鍝嶅簲瓒呮椂,涓嬭浇澶囦唤鏂囦欢澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndDownloadBackupFileFail);
-                this.ShowErrorMsg(msg);
-                return false;
-            }
-            return success;
         }
 
         #endregion
@@ -605,131 +751,11 @@
                     //鍝嶅簲瓒呮椂,鎭㈠鍗忚皟鍣╪v鍒嗗尯澶辫触
                     msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndRestoreGatewayNVFail);
                 }
-                this.ShowErrorMsg(msg);
+                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, msg);
                 return false;
             }
 
             return true;
-        }
-
-        #endregion
-
-        #region 鈻� 閲嶅惎缃戝叧绯荤粺_______________________
-
-        /// <summary>
-        /// 閲嶅惎缃戝叧绯荤粺
-        /// </summary>
-        /// <param name="realGateway"></param>
-        /// <returns></returns>
-        private bool GatewayReboot(ZbGateway realGateway)
-        {
-            //姝e湪閲嶅惎缃戝叧绯荤粺
-            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uGatewayRerooting));
-            ProgressFormBar.Current.ResetProgressBar();
-            System.Threading.Thread.Sleep(1000);
-
-            int result = -1;
-            Action<string, string> action = (topic, message) =>
-            {
-                var gatewayID = topic.Split('/')[0];
-                if (topic == gatewayID + "/" + "GwReboot_Respon")
-                {
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                    result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
-                }
-            };
-            realGateway.Actions += action;
-
-            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 83 } };
-            realGateway.Send("GwReboot", jObject.ToString());
-
-            int timeOut = 0;
-            while (result == -1 && timeOut < 30)
-            {
-                System.Threading.Thread.Sleep(1000);
-                timeOut++;
-            }
-            realGateway.Actions -= action;
-            if (result != 0)
-            {
-                //閲嶅惎缃戝叧绯荤粺澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayRerootFail);
-                if (result == -1)
-                {
-                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂");
-                }
-                this.ShowErrorMsg(msg);
-                return false;
-            }
-
-            //缃戝叧宸茬粡鎺ユ敹鍒伴噸鍚懡浠�,鎺ヤ笅鏉ュ幓鍒ゆ柇缃戝叧鏄惁閲嶅惎瀹屾垚
-            timeOut = 0;
-            while (true)
-            {
-                //澶ф缃戝叧閲嶅惎瑕�60绉�
-                if (timeOut >= 65 && timeOut % 5 == 0)
-                {
-                    //5绉掍竴娆�,鍘昏幏鍙栫増鏈�
-                    var data = HdlGatewayLogic.Current.GetGatewayInfo(realGateway, false, ShowErrorMode.NO);
-                    if (data != null)
-                    {
-                        break;
-                    }
-                }
-                System.Threading.Thread.Sleep(1000);
-                timeOut++;
-                //璁剧疆杩涘害鍊�
-                ProgressFormBar.Current.SetValue(timeOut, 180);
-                if (timeOut >= 180)
-                {
-                    //180绉掕繕绛変笉鍒扮殑璇濓紝缃戝叧搴旇鍑洪棶棰樹簡
-                    break;
-                }
-            }
-            if (timeOut < 180)
-            {
-                //璁剧疆杩涘害鍊�:100%
-                ProgressFormBar.Current.SetValue(1, 1);
-                System.Threading.Thread.Sleep(1000);
-                return true;
-            }
-            else
-            {
-                //鍝嶅簲瓒呮椂,閲嶅惎缃戝叧绯荤粺澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndGatewayRerootFail);
-                this.ShowErrorMsg(msg);
-                return false;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 涓�鑸柟娉昣__________________________
-
-        /// <summary>
-        /// 鏄剧ず閿欒淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowErrorMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
-                contr.Show();
-            });
-        }
-
-        /// <summary>
-        /// 鏄剧ずTip淇℃伅绐楀彛
-        /// </summary>
-        /// <param name="msg"></param>
-        private void ShowTipMsg(string msg)
-        {
-            Application.RunOnMainThread(() =>
-            {
-                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
-                contr.Show();
-            });
         }
 
         #endregion

--
Gitblit v1.8.0