From dc0309e64f02227d8e1468b7326c07955f804612 Mon Sep 17 00:00:00 2001
From: chenqiyang <1406175257@qq.com>
Date: 星期三, 22 六月 2022 11:22:18 +0800
Subject: [PATCH] 修改引用路径

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayUpdateLogic.cs | 2058 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 1,029 insertions(+), 1,029 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayUpdateLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayUpdateLogic.cs
old mode 100755
new mode 100644
index 81fd930..eb94ed6
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayUpdateLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayUpdateLogic.cs
@@ -1,1029 +1,1029 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// 缃戝叧鐨勫崌绾ч�昏緫
-    /// </summary>
-    public class HdlGatewayUpdateLogic : HdlDeviceUpdateCommonLogic
-    {
-        #region 鈻� 鍙橀噺澹版槑___________________________
-
-        /// <summary>
-        /// <para>鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢</para>
-        /// <para>绗竴涓弬鏁颁负:</para>
-        /// <para>-1:鏇存柊寮傚父,鍚庨潰鐨勫�间负寮傚父淇℃伅鐨勭炕璇戞枃鏈�</para>
-        /// <para> 0:鏇存柊鐘舵�佹甯稿彉鍖�,鍚庨潰鐨勫�间负鐘舵�佸彉鏇寸殑鏂囨湰缈昏瘧</para>
-        /// <para> 1:鍗囩骇鎴愬姛</para>
-        /// <para> 3:浠庣瓑寰呬腑鍙栨秷(鐩墠杩樻病鏈夌敤)</para>
-        /// </summary>
-        public Action<int, string> UpdateStatuChangedEvent = null;
-        /// <summary>
-        /// 杩涘害鍊间簨浠�(宸茬粡鏄櫨鍒嗘瘮鐨勫��)
-        /// </summary>
-        public Action<decimal> ProgressEvent = null;
-        /// <summary>
-        /// 铏氭嫙璁惧鐨勫浐浠朵俊鎭�
-        /// </summary>
-        public FirmwareVersionInfo virtualFirmware = null;
-        /// <summary>
-        /// 鍗忚皟鍣ㄦ柊鐗堟湰鐨勫浐浠朵俊鎭�
-        /// </summary>
-        public FirmwareVersionInfo coordinatorFirmware = null;
-        /// <summary>
-        /// 缃戝叧鏂扮増鏈殑鍥轰欢淇℃伅
-        /// </summary>
-        public FirmwareVersionInfo gatewayFirmware = null;
-
-        /// <summary>
-        /// 鍓嶄竴娆$殑鏈�缁堢姸鎬�
-        /// </summary>
-        private UpdateStatuMode oldUpdateStatu = UpdateStatuMode.None;
-        /// <summary>
-        /// 瑕佸崌绾х殑缃戝叧
-        /// </summary>
-        private ZbGateway upDatezbGateway = null;
-
-        #endregion
-
-        #region 鈻� 鍒濆鍖朹____________________________
-
-        /// <summary>
-        /// 缃戝叧鍗囩骇鎺т欢
-        /// </summary>
-        /// <param name="listView">鍒楄〃鎺т欢</param>
-        /// <param name="zbGateway">缃戝叧</param>
-        /// <param name="i_virtualFirmware">铏氭嫙璁惧鐨勫浐浠朵俊鎭�</param>
-        /// <param name="i_coordinatorFirmware">鍗忚皟鍣ㄦ柊鐗堟湰鐨勫浐浠朵俊鎭�</param>
-        /// <param name="i_gatewayFirmware">缃戝叧鏂扮増鏈殑鍥轰欢淇℃伅</param>
-        public HdlGatewayUpdateLogic(ZbGateway zbGateway, FirmwareVersionInfo i_virtualFirmware,
-            FirmwareVersionInfo i_coordinatorFirmware, FirmwareVersionInfo i_gatewayFirmware)
-        {
-            this.ClassDiv = 1;
-            this.upDatezbGateway = zbGateway;
-            this.virtualFirmware = i_virtualFirmware;
-            this.coordinatorFirmware = i_coordinatorFirmware;
-            this.gatewayFirmware = i_gatewayFirmware;
-        }
-
-        #endregion
-
-        #region 鈻� 寮�濮嬫洿鏂癬__________________________
-
-        /// <summary>
-        /// 杩涘叆鎵ц鏇存柊鎿嶄綔鍑嗗闃舵
-        /// </summary>
-        public void StartUpdateReady()
-        {
-            if (this.UpdateStatu == UpdateStatuMode.Wait)
-            {
-                //濡傛灉鏄瓑寰呮ā寮忥紝鍐嶆鐐瑰嚮鏃讹紝绉婚櫎鍒楄〃
-                string gwId = this.upDatezbGateway.GwId;
-                if (FirmwareUpdateResourse.dicUpdateList.ContainsKey(gwId) == true)
-                {
-                    FirmwareUpdateResourse.dicUpdateList.Remove(gwId);
-                }
-                this.UpdateStatu = UpdateStatuMode.None;
-                //鍙栨秷
-                this.UpdateStatuChangedEvent?.Invoke(3, "");
-                return;
-            }
-            //濡傛灉瀹冩湁鐘舵�侊紝鍒欒〃绀轰箣鍓嶅畠琚粈涔堥敊璇腑鏂簡
-            if (this.UpdateStatu != UpdateStatuMode.None)
-            {
-                //淇濆瓨璧锋潵锛屽悗闈㈡湁鐢ㄥ
-                this.oldUpdateStatu = this.UpdateStatu;
-            }
-
-            //杩涘叆绛夊緟妯″紡
-            this.UpdateStatu = UpdateStatuMode.Wait;
-            string gwId2 = this.upDatezbGateway.GwId;
-            FirmwareUpdateResourse.dicUpdateList[gwId2] = this;
-            //绛夊緟涓��
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
-
-            //鎵ц涓嬩竴涓彲鏇存柊鐨勫浐浠剁殑鏇存柊鎿嶄綔
-            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-        }
-
-        /// <summary>
-        /// 寮�濮嬫墽琛屾洿鏂版搷浣�(FirmwareUpdateLogic璋冪敤)
-        /// </summary>
-        public override void DoStartUpdate()
-        {
-            //鐘舵�佸彉鏇�
-            this.IsFinishUpdate = false;
-            this.UpdateStatu = UpdateStatuMode.Action;
-            //璁剧疆鎷ユ湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
-            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(true);
-            //鏍规嵁鐘舵�佹墽琛屾搷浣�
-            this.DoAdjustByStatuMode();
-        }
-
-        /// <summary>
-        /// 鏍规嵁鐘舵�佹墽琛屾搷浣�
-        /// </summary>
-        private void DoAdjustByStatuMode()
-        {
-            //棣栧彂鏃讹紝浠庡紑濮嬫墽琛�
-            if (this.oldUpdateStatu == UpdateStatuMode.None)
-            {
-                //涓嬭浇铏氭嫙椹卞姩鏂囦欢
-                this.DownLoadVirtualFile();
-            }
-            //铏氭嫙椹卞姩涓嬭浇澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.VirtualDownLoadFail)
-            {
-                //涓嬭浇铏氭嫙椹卞姩鏂囦欢
-                this.DownLoadVirtualFile();
-            }
-            //铏氭嫙椹卞姩鏇存柊澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.VirtualUpdateFail)
-            {
-                //鎵ц铏氭嫙椹卞姩鏇存柊
-                this.DoUpdateVirtual();
-            }
-            //鍗忚皟鍣ㄤ笅杞藉け璐�
-            else if (this.oldUpdateStatu == UpdateStatuMode.CoordinatorDownLoadFail)
-            {
-                //涓嬭浇铏氭嫙椹卞姩鏂囦欢(浠庡ご鍐嶆潵)
-                this.DownLoadVirtualFile();
-            }
-            //鍗忚皟鍣ㄥ崌绾уけ璐�
-            else if (this.oldUpdateStatu == UpdateStatuMode.CoordinatorUpdateFail)
-            {
-                //鎵ц铏氭嫙椹卞姩鏇存柊(浠庡ご鍐嶆潵)
-                this.DoUpdateVirtual();
-            }
-            //缃戝叧涓嬭浇澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.GatewayDownLoadFail)
-            {
-                //涓嬭浇铏氭嫙椹卞姩鏂囦欢(浠庡ご鍐嶆潵)
-                this.DownLoadVirtualFile();
-            }
-            //缃戝叧鍗囩骇澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.GatewayUpdateFail)
-            {
-                //鎵ц铏氭嫙椹卞姩鏇存柊(浠庡ご鍐嶆潵)
-                this.DoUpdateVirtual();
-            }
-            else
-            {
-                //閲嶆柊鍐嶆潵
-                this.DownLoadVirtualFile();
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 铏氭嫙椹卞姩涓嬭浇_______________________
-
-        /// <summary>
-        /// 涓嬭浇铏氭嫙椹卞姩鏂囦欢
-        /// </summary>
-        private async void DownLoadVirtualFile()
-        {
-            //寮�鍚綉鍏充笅杞借秴鏃剁嚎绋�
-            this.StartDownLoadTimeOutThread();
-
-            //濡傛灉铏氭嫙椹卞姩涓嶉渶瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
-            if (this.virtualFirmware == null)
-            {
-                //涓嬭浇鍗忚皟鍣ㄦ枃浠�
-                this.DownLoadCoordinatorFile();
-                return;
-            }
-
-            this.UpdateStatu = UpdateStatuMode.VirtualDownLoad;
-            //铏氭嫙椹卞姩鍥轰欢涓嬭浇涓�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoading));
-
-            //涓嬭浇铏氭嫙椹卞姩鏂囦欢鐨勮繘搴�
-            this.upDatezbGateway.ReportAction += this.DownLoadVirtualFileProgress;
-
-            //涓嬭浇铏氭嫙椹卞姩鏂囦欢
-            var result = await this.upDatezbGateway.DownloadFileAsync(this.virtualFirmware.DistributedMark, this.virtualFirmware.Name);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-                //铏氭嫙椹卞姩鍥轰欢璧勬簮涓嬭浇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.VirtualDownLoadFail;
-
-                return;
-            }
-        }
-
-        /// <summary>
-        /// 涓嬭浇铏氭嫙椹卞姩鏂囦欢鐨勮繘搴�
-        /// </summary>
-        /// <param name="CommadDiv"></param>
-        /// <param name="objValue"></param>
-        private void DownLoadVirtualFileProgress(string CommadDiv, object objValue)
-        {
-            if (CommadDiv != "DownloadFileProgress" || objValue == null)
-            {
-                return;
-            }
-            var tempZb = (ZbGateway)objValue;
-            if (tempZb.GwId != this.upDatezbGateway.GwId)
-            {
-                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
-                return;
-            }
-
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-
-            //璁剧疆杩涘害
-            var responData = tempZb.downloadFileProgressResponData;
-
-            //铏氭嫙椹卞姩鍥轰欢涓嬭浇涓�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoading));
-
-            if (responData.Status == 2)
-            {
-                //铏氭嫙椹卞姩鍥轰欢璧勬簮涓嬭浇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.VirtualDownLoadFail;
-            }
-            else if (responData.Status == 0)
-            {
-                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
-                //铏氭嫙椹卞姩涓嬭浇瀹屼簡涔嬪悗锛屼笅杞藉崗璋冨櫒鏂囦欢
-                this.DownLoadCoordinatorFile();
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 铏氭嫙椹卞姩鍗囩骇_______________________
-
-        /// <summary>
-        /// 鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
-        /// </summary>
-        private async void DoUpdateVirtual()
-        {
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-            //寮�鍚綉鍏冲崌绾ц櫄鎷熻繘搴︾嚎绋�
-            this.StartUpdateVirtualThread();
-            //鍗囩骇涓�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uLevelUping));
-
-            //濡傛灉铏氭嫙椹卞姩涓嶉渶瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
-            if (this.virtualFirmware == null)
-            {
-                //鎵ц鍗忚皟鍣ㄥ崌绾х▼搴�
-                this.DoUpdateCoordinator();
-                return;
-            }
-
-            this.UpdateStatu = UpdateStatuMode.VirtualUpdateReady;
-            //鍗囩骇铏氭嫙椹卞姩鐨勮繘搴�
-            this.upDatezbGateway.ReportAction += this.UpdateVirtualProgress;
-
-            //铏氭嫙椹卞姩鍗囩骇
-            var result = await this.upDatezbGateway.VirtualDriveUpgradeAsync(this.virtualFirmware.Name, this.virtualFirmware.VirtualCode);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-                if ((int)this.UpdateStatu > (int)UpdateStatuMode.VirtualUpdateReady)
-                {
-                    //铏界劧浣犺鎶ラ敊浜嗭紝浣嗘槸涔嬪悗鎷ユ湁姝e父鎿嶄綔鐨勮瘽锛岀洿鎺ユ棤瑙嗚繖涓敊璇�
-                    //鐘舵�佺殑鏁板�煎嵆涓烘搷浣滈『搴�,鐘舵�佸�煎ぇ浜庡綋鍓嶅�硷紝鍗宠〃绀哄彲浠ュ線涓嬫墽琛�
-                    return;
-                }
-
-                //铏氭嫙椹卞姩鍗囩骇澶辫触
-                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uVirtualUpdatingFail));
-
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-
-                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
-
-                this.UpdateStatu = UpdateStatuMode.VirtualUpdateFail;
-            }
-        }
-
-        /// <summary>
-        /// 鍗囩骇铏氭嫙椹卞姩鐨勮繘搴�
-        /// </summary>
-        /// <param name="CommadDiv"></param>
-        /// <param name="objValue"></param>
-        private void UpdateVirtualProgress(string CommadDiv, object objValue)
-        {
-            if (CommadDiv != "VirtualDriveUpgrade" || objValue == null)
-            {
-                return;
-            }
-            var tempZb = (ZbGateway)objValue;
-            if (tempZb.GwId != this.upDatezbGateway.GwId)
-            {
-                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
-                return;
-            }
-
-            //缃戝叧鏈夊洖搴�,鍒欒秴鏃舵椂闂村埛鏂�
-            this.UpdateTimeOutRefresh();
-
-            //璁剧疆杩涘害
-            var responData = tempZb.virtualDriveUpgradeResponData;
-            if (responData.Flag != 0 && responData.Flag != 2)
-            {
-                //铏氭嫙椹卞姩鍗囩骇澶辫触
-                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uVirtualUpdatingFail));
-
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-
-                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
-
-                this.UpdateStatu = UpdateStatuMode.VirtualUpdateFail;
-            }
-            else if (responData.Flag == 0)
-            {
-                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
-                //铏氭嫙椹卞姩鍗囩骇瀹屼簡涔嬪悗锛屽崌绾у崗璋冨櫒
-                this.DoUpdateCoordinator();
-            }
-            else
-            {
-                //铏氭嫙椹卞姩鍗囩骇涓�
-                this.UpdateStatu = UpdateStatuMode.VirtualUpdating;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鍗忚皟鍣ㄤ笅杞絖________________________
-
-        /// <summary>
-        /// 涓嬭浇鍗忚皟鍣ㄦ枃浠�
-        /// </summary>
-        private async void DownLoadCoordinatorFile()
-        {
-            //濡傛灉鍗忚皟鍣ㄤ笉闇�瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
-            if (this.coordinatorFirmware == null)
-            {
-                //涓嬭浇缃戝叧鏂囦欢
-                this.DownLoadGatewayFile();
-                return;
-            }
-
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-
-            this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoad;
-            //绛変釜1绉�
-            await Task.Delay(1000);
-
-            //鍗忚皟鍣ㄥ浐浠朵笅杞戒腑
-            this.UpdateStatuChangedEvent(0, Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoading));
-            this.SetProgressValue(0, 100);
-
-            //涓嬭浇鍗忚皟鍣ㄦ枃浠剁殑杩涘害
-            this.upDatezbGateway.ReportAction += this.DownLoadCoordinatorFileProgress;
-
-            //涓嬭浇鍗忚皟鍣ㄦ枃浠�
-            var result = await this.upDatezbGateway.DownloadFileAsync(this.coordinatorFirmware.DistributedMark, this.coordinatorFirmware.Name);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-                //鍗忚皟鍣ㄥ浐浠惰祫婧愪笅杞藉け璐�
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoadFail;
-
-                return;
-            }
-        }
-
-        /// <summary>
-        /// 涓嬭浇鍗忚皟鍣ㄦ枃浠剁殑杩涘害
-        /// </summary>
-        /// <param name="CommadDiv"></param>
-        /// <param name="objValue"></param>
-        private void DownLoadCoordinatorFileProgress(string CommadDiv, object objValue)
-        {
-            if (CommadDiv != "DownloadFileProgress" || objValue == null)
-            {
-                return;
-            }
-            var tempZb = (ZbGateway)objValue;
-            if (tempZb.GwId != this.upDatezbGateway.GwId)
-            {
-                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
-                return;
-            }
-
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-
-            //璁剧疆杩涘害
-            var responData = tempZb.downloadFileProgressResponData;
-            this.SetProgressValue(responData.DownloadPercent, 100);
-
-            //鍗忚皟鍣ㄥ浐浠朵笅杞戒腑
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoading));
-
-            if (responData.Status == 2)
-            {
-                //鍗忚皟鍣ㄥ浐浠惰祫婧愪笅杞藉け璐�
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoadFail;
-            }
-            else if (responData.Status == 0)
-            {
-                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
-                //鍗忚皟鍣ㄤ笅杞藉畬浜嗕箣鍚庯紝涓嬭浇缃戝叧鏂囦欢
-                this.DownLoadGatewayFile();
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鍗忚皟鍣ㄥ崌绾________________________
-
-        /// <summary>
-        /// 鎵ц鍗忚皟鍣ㄥ崌绾х▼搴�
-        /// </summary>
-        private async void DoUpdateCoordinator()
-        {
-            //濡傛灉鍗忚皟鍣ㄤ笉闇�瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
-            if (this.coordinatorFirmware == null)
-            {
-                //鎵ц缃戝叧鍗囩骇绋嬪簭
-                this.DoUpdateGateway();
-                return;
-            }
-
-            this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateReady;
-            //鍗囩骇鍗忚皟鍣ㄧ殑杩涘害
-            this.upDatezbGateway.ReportAction += this.UpdateCoordinatorProgress;
-
-            //鍗忚皟鍣ㄥ崌绾�
-            var result = await this.upDatezbGateway.UpgradeNVAsync(this.coordinatorFirmware.Name);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-                if ((int)this.UpdateStatu > (int)UpdateStatuMode.CoordinatorUpdateReady)
-                {
-                    //铏界劧浣犺鎶ラ敊浜嗭紝浣嗘槸涔嬪悗鎷ユ湁姝e父鎿嶄綔鐨勮瘽锛岀洿鎺ユ棤瑙嗚繖涓敊璇�
-                    //鐘舵�佺殑鏁板�煎嵆涓烘搷浣滈『搴�,鐘舵�佸�煎ぇ浜庡綋鍓嶅�硷紝鍗宠〃绀哄彲浠ュ線涓嬫墽琛�
-                    return;
-                }
-
-                //鍗忚皟鍣ㄥ崌绾уけ璐�
-                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uCoordinatorUpdatingFail));
-
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-
-                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
-
-                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateFail;
-            }
-        }
-
-        /// <summary>
-        /// 鍗囩骇鍗忚皟鍣ㄧ殑杩涘害
-        /// </summary>
-        /// <param name="CommadDiv"></param>
-        /// <param name="objValue"></param>
-        private void UpdateCoordinatorProgress(string CommadDiv, object objValue)
-        {
-            if (CommadDiv != "CordinatorUpgradePercent" || objValue == null)
-            {
-                return;
-            }
-
-            var tempZb = (ZbGateway)objValue;
-            if (tempZb.GwId != this.upDatezbGateway.GwId)
-            {
-                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
-                return;
-            }
-
-            //缃戝叧鏈夊洖搴�,鍒欒秴鏃舵椂闂村埛鏂�
-            this.UpdateTimeOutRefresh();
-
-            //璁剧疆杩涘害
-            var responData = tempZb.zbGwOperationUpgradeData;
-            if (responData.Flag != 0 && responData.Flag != 2)
-            {
-                //鍗忚皟鍣ㄥ崌绾уけ璐�
-                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uCoordinatorUpdatingFail));
-
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-
-                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
-
-                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateFail;
-            }
-            else if (responData.Flag == 0)
-            {
-                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
-                //鍗忚皟鍣ㄥ崌绾у畬浜嗕箣鍚庯紝鍗囩骇缃戝叧
-                this.DoUpdateGateway();
-            }
-            else
-            {
-                //鍗忚皟鍣ㄥ崌绾т腑
-                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdating;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 缃戝叧涓嬭浇___________________________
-
-        /// <summary>
-        /// 涓嬭浇缃戝叧鏂囦欢
-        /// </summary>
-        private async void DownLoadGatewayFile()
-        {
-            //濡傛灉缃戝叧涓嶇敤鍗囩骇锛屽垯鐩存帴璺宠浆涓嬩竴姝�
-            if (this.gatewayFirmware == null)
-            {
-                //鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
-                this.DoUpdateVirtual();
-                return;
-            }
-            this.UpdateStatu = UpdateStatuMode.GatewayDownLoad;
-
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-
-            //绛変釜1绉�
-            await Task.Delay(1000);
-
-            //缃戝叧鍥轰欢涓嬭浇涓�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoading));
-            this.SetProgressValue(0, 100);
-
-            //涓嬭浇缃戝叧鏂囦欢鐨勮繘搴�
-            this.upDatezbGateway.ReportAction += this.DownLoadGatewayFileProgress;
-
-            //涓嬭浇缃戝叧鏂囦欢
-            var result = await this.upDatezbGateway.DownloadFileAsync(this.gatewayFirmware.DistributedMark, this.gatewayFirmware.Name);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-                //缃戝叧鍥轰欢璧勬簮涓嬭浇澶辫触
-                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
-            }
-        }
-
-        /// <summary>
-        /// 涓嬭浇缃戝叧鏂囦欢鐨勮繘搴�
-        /// </summary>
-        /// <param name="CommadDiv"></param>
-        /// <param name="objValue"></param>
-        private void DownLoadGatewayFileProgress(string CommadDiv, object objValue)
-        {
-            if (CommadDiv != "DownloadFileProgress" || objValue == null)
-            {
-                return;
-            }
-            var tempZb = (ZbGateway)objValue;
-            if (tempZb.GwId != this.upDatezbGateway.GwId)
-            {
-                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
-                return;
-            }
-
-            //鍒锋柊瓒呮椂鏃堕棿
-            this.DownLoadTimeOutRefresh();
-
-            //璁剧疆杩涘害
-            var responData = tempZb.downloadFileProgressResponData;
-            this.SetProgressValue(responData.DownloadPercent, 100);
-
-            if (responData.Status == 2)
-            {
-                //缃戝叧鍥轰欢璧勬簮涓嬭浇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
-
-                this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
-            }
-            else if (responData.Status == 0)
-            {
-                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
-                //鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
-                this.DoUpdateVirtual();
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 缃戝叧鍗囩骇___________________________
-
-        /// <summary>
-        /// 鎵ц缃戝叧鍗囩骇绋嬪簭
-        /// </summary>
-        private async void DoUpdateGateway()
-        {
-            //濡傛灉缃戝叧涓嶇敤鍗囩骇锛屽垯鐩存帴璺宠浆涓嬩竴姝�
-            if (this.gatewayFirmware == null)
-            {
-                //鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
-                this.ShowFinishMsg();
-                return;
-            }
-
-            this.UpdateStatu = UpdateStatuMode.GatewayUpdateReady;
-
-            //缃戝叧鍗囩骇
-            var result = await this.upDatezbGateway.LinuxUpgradeAsync(this.gatewayFirmware.Name);
-            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
-            {
-                if (result.errorMessageBase.Contains("鍥炲瓒呮椂") == true)
-                {
-                    //缃戝叧鍗囩骇鐨勬椂鍊欙紝鏈夊彲鑳藉畠涓嶅啀鍥炰粈涔堜俊鎭�
-                    return;
-                }
-                if (result.errorResponData != null && result.errorResponData.Error == 2)
-                {
-                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
-                    return;
-                }
-
-                //缃戝叧鍗囩骇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGatewayUpdatingFail));
-
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-
-                this.UpdateStatu = UpdateStatuMode.GatewayUpdateFail;
-
-                return;
-            }
-
-            //缃戝叧鍗囩骇涓�
-            this.UpdateStatu = UpdateStatuMode.GatewayUpdating;
-
-            //寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼
-            this.StartGetGatewayVersionThread();
-        }
-
-        #endregion
-
-        #region 鈻� 鍗囩骇瀹屾垚鎻愮ず_______________________
-
-        /// <summary>
-        /// 鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
-        /// </summary>
-        private void ShowFinishMsg()
-        {
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                //鐘舵�佸彉鏇�
-                this.IsFinishUpdate = true;
-                System.Threading.Thread.Sleep(2000);
-
-                //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
-                HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
-
-                this.UpdateStatu = UpdateStatuMode.UpdateSuccess;
-                //鎵ц涓嬩竴涓崌绾�
-                HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-                //缃戝叧鍗囩骇鎴愬姛!
-                this.SetProgressValue(100, 100);
-                System.Threading.Thread.Sleep(1500);
-
-                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uGatewayUpdateSuccess));
-            });
-        }
-
-        #endregion
-
-        #region 鈻� 澶勭悊缁撴灉鎻愮ず_______________________
-
-        /// <summary>
-        /// 鏄剧ず閲嶆柊瀹夎鐨勪俊鎭�
-        /// </summary>
-        private void ShowReSetupMsg()
-        {
-            //鐘舵�佸彉鏇�
-            this.IsFinishUpdate = true;
-            //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
-            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
-
-            //鎵ц涓嬩竴涓崌绾�
-            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-        }
-
-        /// <summary>
-        /// 鏄剧ず閲嶆柊涓嬭浇妯″紡
-        /// </summary>
-        private void ShowReDownLoadMode()
-        {
-            //鐘舵�佸彉鏇�
-            this.IsFinishUpdate = true;
-            //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
-            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
-
-            //鎵ц涓嬩竴涓崌绾�
-            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-        }
-
-        #endregion
-
-        #region 鈻� 璁剧疆杩涘害___________________________
-
-        /// <summary>
-        /// 璁惧畾杩涘害鍊�
-        /// </summary>
-        /// <param name="value">杩涘害鍊�</param>
-        /// <param name="maxValue">鏈�澶у��</param>
-        private void SetProgressValue(decimal value, decimal maxValue)
-        {
-            if (value > maxValue)
-            {
-                //鏈夋椂鍊欎細鐬庡彂浠�涔堥杩囨潵
-                return;
-            }
-            decimal result = value / maxValue;
-            this.ProgressEvent?.Invoke(result);
-        }
-
-        /// <summary>
-        /// 璁剧疆閿欒淇℃伅
-        /// </summary>
-        /// <param name="value"></param>
-        private void ShowErrorMsg(string value)
-        {
-            this.UpdateStatuChangedEvent?.Invoke(-1, value);
-        }
-
-        #endregion
-
-        #region 鈻� 缃戝叧涓嬭浇瓒呮椂绾跨▼___________________
-
-        /// <summary>
-        /// 瓒呮椂鏃堕棿璁剧疆
-        /// </summary>
-        private int downLoadTimeOutCount = 30;
-
-        /// <summary>
-        /// 寮�鍚綉鍏充笅杞借秴鏃剁嚎绋�
-        /// </summary>
-        private void StartDownLoadTimeOutThread()
-        {
-            this.downLoadTimeOutCount = 30;
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                while (true)
-                {
-                    var value = this.UpdateStatu.ToString();
-                    if (value.EndsWith("DownLoad") == false)
-                    {
-                        //鎵ц瀹屾垚涓嬭浇鎿嶄綔
-                        break;
-                    }
-                    System.Threading.Thread.Sleep(1000);
-                    this.downLoadTimeOutCount--;
-                    if (this.downLoadTimeOutCount < 0)
-                    {
-                        this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
-                        this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
-                        this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
-
-                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
-                        string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail);
-                        //浠庡ご鍐嶆潵
-                        this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
-                        //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                        this.ShowReDownLoadMode();
-                        //璁剧疆閿欒淇℃伅
-                        this.ShowErrorMsg(msg);
-                        break;
-                    }
-                }
-            });
-        }
-
-        /// <summary>
-        /// 瓒呮椂鏃堕棿鍒锋柊
-        /// </summary>
-        private void DownLoadTimeOutRefresh()
-        {
-            this.downLoadTimeOutCount = 30;
-        }
-
-        #endregion
-
-        #region 鈻� 缃戝叧鍗囩骇铏氭嫙杩涘害绾跨▼_______________
-
-        /// <summary>
-        /// 瓒呮椂鏃堕棿璁剧疆
-        /// </summary>
-        private int updateTimeOutCount = 60;
-
-        /// <summary>
-        /// 寮�鍚綉鍏冲崌绾ц櫄鎷熻繘搴︾嚎绋�
-        /// </summary>
-        private void StartUpdateVirtualThread()
-        {
-            //鑾峰彇鍗囩骇鐨勫ぇ鑷存�诲叡鏃堕棿
-            int timeCount = this.GetUpdateTimeCount();
-            //缃戝叧鍗囩骇涓�,鍓╀綑鏃堕棿澶х害涓�:
-            string msg = Language.StringByID(R.MyInternationalizationString.uGatewaiUpdatingAndRemainingTimeMsg);
-            //褰撳墠鐢ㄦ椂
-            int nowTimeCount = 0;
-            //瓒呮椂鏃堕棿璁剧疆
-            this.updateTimeOutCount = 60;
-
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                while (this.IsFinishUpdate == false)
-                {
-                    System.Threading.Thread.Sleep(1000);
-                    nowTimeCount++;
-
-                    //瓒呮椂
-                    updateTimeOutCount--;
-                    if (updateTimeOutCount == 0)
-                    {
-                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
-                        this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail));
-                        //浠庡ご鍐嶆潵
-                        this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
-                        //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                        this.ShowReDownLoadMode();
-
-                        break;
-                    }
-
-                    //鍓╀綑鏃堕棿
-                    int remainingTime = timeCount - nowTimeCount;
-                    if (remainingTime <= -1)
-                    {
-                        //鏃堕棿鐢ㄥ畬浜嗭紝鐩存帴鏄剧ず鎴愬姛
-                        this.IsFinishUpdate = true;
-                        break;
-                    }
-                    //璁剧疆杩涘害鍊�
-                    this.UpdateStatuChangedEvent?.Invoke(0, msg + remainingTime + "s");
-                    this.SetProgressValue(nowTimeCount, timeCount);
-                }
-            });
-        }
-
-        /// <summary>
-        /// 鑾峰彇鍗囩骇鐨勫ぇ鑷存�诲叡鏃堕棿
-        /// </summary>
-        /// <returns></returns>
-        private int GetUpdateTimeCount()
-        {
-            int timeCount = 0;
-            if (this.virtualFirmware != null)
-            {
-                //铏氭嫙椹卞姩鍗囩骇
-                timeCount += 20;
-            }
-            if (this.coordinatorFirmware != null)
-            {
-                //鍗忚皟鍣ㄥ崌绾�
-                timeCount += 120;
-            }
-            if (this.gatewayFirmware != null)
-            {
-                //缃戝叧鍗囩骇
-                timeCount += 50;
-                //缃戝叧閲嶅惎
-                timeCount += 250;
-            }
-            return timeCount;
-        }
-
-        /// <summary>
-        /// 瓒呮椂鏃堕棿鍒锋柊
-        /// </summary>
-        private void UpdateTimeOutRefresh()
-        {
-            this.updateTimeOutCount = 60;
-        }
-
-        #endregion
-
-        #region 鈻� 寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼_____________
-
-        /// <summary>
-        /// 寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼
-        /// </summary>
-        /// <returns></returns>
-        private void StartGetGatewayVersionThread()
-        {
-            HdlThreadLogic.Current.RunThread(() =>
-            {
-                //鍏堢瓑涓�120绉掑惂锛岀綉鍏冲崌绾у拰缃戝叧瀹屽叏閲嶅惎闇�瑕佸緢闀挎椂闂�
-                int count = 12;
-                for (int i = 0; i < count; i++)
-                {
-                    if (this.IsFinishUpdate == true)
-                    {
-                        //鍗囩骇瀹屼簡锛屽洜涓烘湁閿欒
-                        break;
-                    }
-                    //杩欎釜鏃跺�欙紝涓嶅簲璇ユ彁绀鸿秴鏃�
-                    this.UpdateTimeOutRefresh();
-
-                    System.Threading.Thread.Sleep(10000);
-                }
-                while (this.IsFinishUpdate == false)
-                {
-                    //鑾峰彇鐗堟湰
-                    var result = HdlGatewayLogic.Current.GetGatewayInfo(this.upDatezbGateway, false, ShowErrorMode.NO);
-                    if (result != null)
-                    {
-                        break;
-                    }
-                    //杩欎釜鏃跺�欙紝涓嶅簲璇ユ彁绀鸿秴鏃�
-                    this.UpdateTimeOutRefresh();
-
-                    System.Threading.Thread.Sleep(5000);
-                }
-                //宸茬粡鑳藉鑾峰彇鏁版嵁
-                this.ShowFinishMsg();
-            });
-        }
-
-        #endregion
-
-        #region 鈻� 閲婃斁缂撳瓨___________________________
-
-        /// <summary>
-        /// 閲婃斁缂撳瓨
-        /// </summary>
-        public override void Dispose()
-        {
-            this.ProgressEvent = null;
-            this.UpdateStatuChangedEvent = null;
-        }
-
-        #endregion
-    }
-}
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 缃戝叧鐨勫崌绾ч�昏緫
+    /// </summary>
+    public class HdlGatewayUpdateLogic : HdlDeviceUpdateCommonLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// <para>鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢</para>
+        /// <para>绗竴涓弬鏁颁负:</para>
+        /// <para>-1:鏇存柊寮傚父,鍚庨潰鐨勫�间负寮傚父淇℃伅鐨勭炕璇戞枃鏈�</para>
+        /// <para> 0:鏇存柊鐘舵�佹甯稿彉鍖�,鍚庨潰鐨勫�间负鐘舵�佸彉鏇寸殑鏂囨湰缈昏瘧</para>
+        /// <para> 1:鍗囩骇鎴愬姛</para>
+        /// <para> 3:浠庣瓑寰呬腑鍙栨秷(鐩墠杩樻病鏈夌敤)</para>
+        /// </summary>
+        public Action<int, string> UpdateStatuChangedEvent = null;
+        /// <summary>
+        /// 杩涘害鍊间簨浠�(宸茬粡鏄櫨鍒嗘瘮鐨勫��)
+        /// </summary>
+        public Action<decimal> ProgressEvent = null;
+        /// <summary>
+        /// 铏氭嫙璁惧鐨勫浐浠朵俊鎭�
+        /// </summary>
+        public FirmwareVersionInfo virtualFirmware = null;
+        /// <summary>
+        /// 鍗忚皟鍣ㄦ柊鐗堟湰鐨勫浐浠朵俊鎭�
+        /// </summary>
+        public FirmwareVersionInfo coordinatorFirmware = null;
+        /// <summary>
+        /// 缃戝叧鏂扮増鏈殑鍥轰欢淇℃伅
+        /// </summary>
+        public FirmwareVersionInfo gatewayFirmware = null;
+
+        /// <summary>
+        /// 鍓嶄竴娆$殑鏈�缁堢姸鎬�
+        /// </summary>
+        private UpdateStatuMode oldUpdateStatu = UpdateStatuMode.None;
+        /// <summary>
+        /// 瑕佸崌绾х殑缃戝叧
+        /// </summary>
+        private ZbGateway upDatezbGateway = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 缃戝叧鍗囩骇鎺т欢
+        /// </summary>
+        /// <param name="listView">鍒楄〃鎺т欢</param>
+        /// <param name="zbGateway">缃戝叧</param>
+        /// <param name="i_virtualFirmware">铏氭嫙璁惧鐨勫浐浠朵俊鎭�</param>
+        /// <param name="i_coordinatorFirmware">鍗忚皟鍣ㄦ柊鐗堟湰鐨勫浐浠朵俊鎭�</param>
+        /// <param name="i_gatewayFirmware">缃戝叧鏂扮増鏈殑鍥轰欢淇℃伅</param>
+        public HdlGatewayUpdateLogic(ZbGateway zbGateway, FirmwareVersionInfo i_virtualFirmware,
+            FirmwareVersionInfo i_coordinatorFirmware, FirmwareVersionInfo i_gatewayFirmware)
+        {
+            this.ClassDiv = 1;
+            this.upDatezbGateway = zbGateway;
+            this.virtualFirmware = i_virtualFirmware;
+            this.coordinatorFirmware = i_coordinatorFirmware;
+            this.gatewayFirmware = i_gatewayFirmware;
+        }
+
+        #endregion
+
+        #region 鈻� 寮�濮嬫洿鏂癬__________________________
+
+        /// <summary>
+        /// 杩涘叆鎵ц鏇存柊鎿嶄綔鍑嗗闃舵
+        /// </summary>
+        public void StartUpdateReady()
+        {
+            if (this.UpdateStatu == UpdateStatuMode.Wait)
+            {
+                //濡傛灉鏄瓑寰呮ā寮忥紝鍐嶆鐐瑰嚮鏃讹紝绉婚櫎鍒楄〃
+                string gwId = this.upDatezbGateway.GwId;
+                if (FirmwareUpdateResourse.dicUpdateList.ContainsKey(gwId) == true)
+                {
+                    FirmwareUpdateResourse.dicUpdateList.Remove(gwId);
+                }
+                this.UpdateStatu = UpdateStatuMode.None;
+                //鍙栨秷
+                this.UpdateStatuChangedEvent?.Invoke(3, "");
+                return;
+            }
+            //濡傛灉瀹冩湁鐘舵�侊紝鍒欒〃绀轰箣鍓嶅畠琚粈涔堥敊璇腑鏂簡
+            if (this.UpdateStatu != UpdateStatuMode.None)
+            {
+                //淇濆瓨璧锋潵锛屽悗闈㈡湁鐢ㄥ
+                this.oldUpdateStatu = this.UpdateStatu;
+            }
+
+            //杩涘叆绛夊緟妯″紡
+            this.UpdateStatu = UpdateStatuMode.Wait;
+            string gwId2 = this.upDatezbGateway.GwId;
+            FirmwareUpdateResourse.dicUpdateList[gwId2] = this;
+            //绛夊緟涓��
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
+
+            //鎵ц涓嬩竴涓彲鏇存柊鐨勫浐浠剁殑鏇存柊鎿嶄綔
+            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+        }
+
+        /// <summary>
+        /// 寮�濮嬫墽琛屾洿鏂版搷浣�(FirmwareUpdateLogic璋冪敤)
+        /// </summary>
+        public override void DoStartUpdate()
+        {
+            //鐘舵�佸彉鏇�
+            this.IsFinishUpdate = false;
+            this.UpdateStatu = UpdateStatuMode.Action;
+            //璁剧疆鎷ユ湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(true);
+            //鏍规嵁鐘舵�佹墽琛屾搷浣�
+            this.DoAdjustByStatuMode();
+        }
+
+        /// <summary>
+        /// 鏍规嵁鐘舵�佹墽琛屾搷浣�
+        /// </summary>
+        private void DoAdjustByStatuMode()
+        {
+            //棣栧彂鏃讹紝浠庡紑濮嬫墽琛�
+            if (this.oldUpdateStatu == UpdateStatuMode.None)
+            {
+                //涓嬭浇铏氭嫙椹卞姩鏂囦欢
+                this.DownLoadVirtualFile();
+            }
+            //铏氭嫙椹卞姩涓嬭浇澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.VirtualDownLoadFail)
+            {
+                //涓嬭浇铏氭嫙椹卞姩鏂囦欢
+                this.DownLoadVirtualFile();
+            }
+            //铏氭嫙椹卞姩鏇存柊澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.VirtualUpdateFail)
+            {
+                //鎵ц铏氭嫙椹卞姩鏇存柊
+                this.DoUpdateVirtual();
+            }
+            //鍗忚皟鍣ㄤ笅杞藉け璐�
+            else if (this.oldUpdateStatu == UpdateStatuMode.CoordinatorDownLoadFail)
+            {
+                //涓嬭浇铏氭嫙椹卞姩鏂囦欢(浠庡ご鍐嶆潵)
+                this.DownLoadVirtualFile();
+            }
+            //鍗忚皟鍣ㄥ崌绾уけ璐�
+            else if (this.oldUpdateStatu == UpdateStatuMode.CoordinatorUpdateFail)
+            {
+                //鎵ц铏氭嫙椹卞姩鏇存柊(浠庡ご鍐嶆潵)
+                this.DoUpdateVirtual();
+            }
+            //缃戝叧涓嬭浇澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.GatewayDownLoadFail)
+            {
+                //涓嬭浇铏氭嫙椹卞姩鏂囦欢(浠庡ご鍐嶆潵)
+                this.DownLoadVirtualFile();
+            }
+            //缃戝叧鍗囩骇澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.GatewayUpdateFail)
+            {
+                //鎵ц铏氭嫙椹卞姩鏇存柊(浠庡ご鍐嶆潵)
+                this.DoUpdateVirtual();
+            }
+            else
+            {
+                //閲嶆柊鍐嶆潵
+                this.DownLoadVirtualFile();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 铏氭嫙椹卞姩涓嬭浇_______________________
+
+        /// <summary>
+        /// 涓嬭浇铏氭嫙椹卞姩鏂囦欢
+        /// </summary>
+        private async void DownLoadVirtualFile()
+        {
+            //寮�鍚綉鍏充笅杞借秴鏃剁嚎绋�
+            this.StartDownLoadTimeOutThread();
+
+            //濡傛灉铏氭嫙椹卞姩涓嶉渶瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
+            if (this.virtualFirmware == null)
+            {
+                //涓嬭浇鍗忚皟鍣ㄦ枃浠�
+                this.DownLoadCoordinatorFile();
+                return;
+            }
+
+            this.UpdateStatu = UpdateStatuMode.VirtualDownLoad;
+            //铏氭嫙椹卞姩鍥轰欢涓嬭浇涓�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoading));
+
+            //涓嬭浇铏氭嫙椹卞姩鏂囦欢鐨勮繘搴�
+            this.upDatezbGateway.ReportAction += this.DownLoadVirtualFileProgress;
+
+            //涓嬭浇铏氭嫙椹卞姩鏂囦欢
+            var result = await this.upDatezbGateway.DownloadFileAsync(this.virtualFirmware.DistributedMark, this.virtualFirmware.Name);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+                //铏氭嫙椹卞姩鍥轰欢璧勬簮涓嬭浇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.VirtualDownLoadFail;
+
+                return;
+            }
+        }
+
+        /// <summary>
+        /// 涓嬭浇铏氭嫙椹卞姩鏂囦欢鐨勮繘搴�
+        /// </summary>
+        /// <param name="CommadDiv"></param>
+        /// <param name="objValue"></param>
+        private void DownLoadVirtualFileProgress(string CommadDiv, object objValue)
+        {
+            if (CommadDiv != "DownloadFileProgress" || objValue == null)
+            {
+                return;
+            }
+            var tempZb = (ZbGateway)objValue;
+            if (tempZb.GwId != this.upDatezbGateway.GwId)
+            {
+                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
+                return;
+            }
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+
+            //璁剧疆杩涘害
+            var responData = tempZb.downloadFileProgressResponData;
+
+            //铏氭嫙椹卞姩鍥轰欢涓嬭浇涓�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoading));
+
+            if (responData.Status == 2)
+            {
+                //铏氭嫙椹卞姩鍥轰欢璧勬簮涓嬭浇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVirtualFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.VirtualDownLoadFail;
+            }
+            else if (responData.Status == 0)
+            {
+                this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
+                //铏氭嫙椹卞姩涓嬭浇瀹屼簡涔嬪悗锛屼笅杞藉崗璋冨櫒鏂囦欢
+                this.DownLoadCoordinatorFile();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 铏氭嫙椹卞姩鍗囩骇_______________________
+
+        /// <summary>
+        /// 鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
+        /// </summary>
+        private async void DoUpdateVirtual()
+        {
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+            //寮�鍚綉鍏冲崌绾ц櫄鎷熻繘搴︾嚎绋�
+            this.StartUpdateVirtualThread();
+            //鍗囩骇涓�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uLevelUping));
+
+            //濡傛灉铏氭嫙椹卞姩涓嶉渶瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
+            if (this.virtualFirmware == null)
+            {
+                //鎵ц鍗忚皟鍣ㄥ崌绾х▼搴�
+                this.DoUpdateCoordinator();
+                return;
+            }
+
+            this.UpdateStatu = UpdateStatuMode.VirtualUpdateReady;
+            //鍗囩骇铏氭嫙椹卞姩鐨勮繘搴�
+            this.upDatezbGateway.ReportAction += this.UpdateVirtualProgress;
+
+            //铏氭嫙椹卞姩鍗囩骇
+            var result = await this.upDatezbGateway.VirtualDriveUpgradeAsync(this.virtualFirmware.Name, this.virtualFirmware.VirtualCode);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+                if ((int)this.UpdateStatu > (int)UpdateStatuMode.VirtualUpdateReady)
+                {
+                    //铏界劧浣犺鎶ラ敊浜嗭紝浣嗘槸涔嬪悗鎷ユ湁姝e父鎿嶄綔鐨勮瘽锛岀洿鎺ユ棤瑙嗚繖涓敊璇�
+                    //鐘舵�佺殑鏁板�煎嵆涓烘搷浣滈『搴�,鐘舵�佸�煎ぇ浜庡綋鍓嶅�硷紝鍗宠〃绀哄彲浠ュ線涓嬫墽琛�
+                    return;
+                }
+
+                //铏氭嫙椹卞姩鍗囩骇澶辫触
+                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uVirtualUpdatingFail));
+
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+
+                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
+
+                this.UpdateStatu = UpdateStatuMode.VirtualUpdateFail;
+            }
+        }
+
+        /// <summary>
+        /// 鍗囩骇铏氭嫙椹卞姩鐨勮繘搴�
+        /// </summary>
+        /// <param name="CommadDiv"></param>
+        /// <param name="objValue"></param>
+        private void UpdateVirtualProgress(string CommadDiv, object objValue)
+        {
+            if (CommadDiv != "VirtualDriveUpgrade" || objValue == null)
+            {
+                return;
+            }
+            var tempZb = (ZbGateway)objValue;
+            if (tempZb.GwId != this.upDatezbGateway.GwId)
+            {
+                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
+                return;
+            }
+
+            //缃戝叧鏈夊洖搴�,鍒欒秴鏃舵椂闂村埛鏂�
+            this.UpdateTimeOutRefresh();
+
+            //璁剧疆杩涘害
+            var responData = tempZb.virtualDriveUpgradeResponData;
+            if (responData.Flag != 0 && responData.Flag != 2)
+            {
+                //铏氭嫙椹卞姩鍗囩骇澶辫触
+                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uVirtualUpdatingFail));
+
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+
+                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
+
+                this.UpdateStatu = UpdateStatuMode.VirtualUpdateFail;
+            }
+            else if (responData.Flag == 0)
+            {
+                this.upDatezbGateway.ReportAction -= this.UpdateVirtualProgress;
+                //铏氭嫙椹卞姩鍗囩骇瀹屼簡涔嬪悗锛屽崌绾у崗璋冨櫒
+                this.DoUpdateCoordinator();
+            }
+            else
+            {
+                //铏氭嫙椹卞姩鍗囩骇涓�
+                this.UpdateStatu = UpdateStatuMode.VirtualUpdating;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鍗忚皟鍣ㄤ笅杞絖________________________
+
+        /// <summary>
+        /// 涓嬭浇鍗忚皟鍣ㄦ枃浠�
+        /// </summary>
+        private async void DownLoadCoordinatorFile()
+        {
+            //濡傛灉鍗忚皟鍣ㄤ笉闇�瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
+            if (this.coordinatorFirmware == null)
+            {
+                //涓嬭浇缃戝叧鏂囦欢
+                this.DownLoadGatewayFile();
+                return;
+            }
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+
+            this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoad;
+            //绛変釜1绉�
+            await Task.Delay(1000);
+
+            //鍗忚皟鍣ㄥ浐浠朵笅杞戒腑
+            this.UpdateStatuChangedEvent(0, Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoading));
+            this.SetProgressValue(0, 100);
+
+            //涓嬭浇鍗忚皟鍣ㄦ枃浠剁殑杩涘害
+            this.upDatezbGateway.ReportAction += this.DownLoadCoordinatorFileProgress;
+
+            //涓嬭浇鍗忚皟鍣ㄦ枃浠�
+            var result = await this.upDatezbGateway.DownloadFileAsync(this.coordinatorFirmware.DistributedMark, this.coordinatorFirmware.Name);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+                //鍗忚皟鍣ㄥ浐浠惰祫婧愪笅杞藉け璐�
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoadFail;
+
+                return;
+            }
+        }
+
+        /// <summary>
+        /// 涓嬭浇鍗忚皟鍣ㄦ枃浠剁殑杩涘害
+        /// </summary>
+        /// <param name="CommadDiv"></param>
+        /// <param name="objValue"></param>
+        private void DownLoadCoordinatorFileProgress(string CommadDiv, object objValue)
+        {
+            if (CommadDiv != "DownloadFileProgress" || objValue == null)
+            {
+                return;
+            }
+            var tempZb = (ZbGateway)objValue;
+            if (tempZb.GwId != this.upDatezbGateway.GwId)
+            {
+                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
+                return;
+            }
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+
+            //璁剧疆杩涘害
+            var responData = tempZb.downloadFileProgressResponData;
+            this.SetProgressValue(responData.DownloadPercent, 100);
+
+            //鍗忚皟鍣ㄥ浐浠朵笅杞戒腑
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoading));
+
+            if (responData.Status == 2)
+            {
+                //鍗忚皟鍣ㄥ浐浠惰祫婧愪笅杞藉け璐�
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCoordinatorFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.CoordinatorDownLoadFail;
+            }
+            else if (responData.Status == 0)
+            {
+                this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
+                //鍗忚皟鍣ㄤ笅杞藉畬浜嗕箣鍚庯紝涓嬭浇缃戝叧鏂囦欢
+                this.DownLoadGatewayFile();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鍗忚皟鍣ㄥ崌绾________________________
+
+        /// <summary>
+        /// 鎵ц鍗忚皟鍣ㄥ崌绾х▼搴�
+        /// </summary>
+        private async void DoUpdateCoordinator()
+        {
+            //濡傛灉鍗忚皟鍣ㄤ笉闇�瑕佸崌绾э紝鍒欑洿鎺ヨ烦杞笅涓�姝�
+            if (this.coordinatorFirmware == null)
+            {
+                //鎵ц缃戝叧鍗囩骇绋嬪簭
+                this.DoUpdateGateway();
+                return;
+            }
+
+            this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateReady;
+            //鍗囩骇鍗忚皟鍣ㄧ殑杩涘害
+            this.upDatezbGateway.ReportAction += this.UpdateCoordinatorProgress;
+
+            //鍗忚皟鍣ㄥ崌绾�
+            var result = await this.upDatezbGateway.UpgradeNVAsync(this.coordinatorFirmware.Name);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+                if ((int)this.UpdateStatu > (int)UpdateStatuMode.CoordinatorUpdateReady)
+                {
+                    //铏界劧浣犺鎶ラ敊浜嗭紝浣嗘槸涔嬪悗鎷ユ湁姝e父鎿嶄綔鐨勮瘽锛岀洿鎺ユ棤瑙嗚繖涓敊璇�
+                    //鐘舵�佺殑鏁板�煎嵆涓烘搷浣滈『搴�,鐘舵�佸�煎ぇ浜庡綋鍓嶅�硷紝鍗宠〃绀哄彲浠ュ線涓嬫墽琛�
+                    return;
+                }
+
+                //鍗忚皟鍣ㄥ崌绾уけ璐�
+                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uCoordinatorUpdatingFail));
+
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+
+                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
+
+                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateFail;
+            }
+        }
+
+        /// <summary>
+        /// 鍗囩骇鍗忚皟鍣ㄧ殑杩涘害
+        /// </summary>
+        /// <param name="CommadDiv"></param>
+        /// <param name="objValue"></param>
+        private void UpdateCoordinatorProgress(string CommadDiv, object objValue)
+        {
+            if (CommadDiv != "CordinatorUpgradePercent" || objValue == null)
+            {
+                return;
+            }
+
+            var tempZb = (ZbGateway)objValue;
+            if (tempZb.GwId != this.upDatezbGateway.GwId)
+            {
+                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
+                return;
+            }
+
+            //缃戝叧鏈夊洖搴�,鍒欒秴鏃舵椂闂村埛鏂�
+            this.UpdateTimeOutRefresh();
+
+            //璁剧疆杩涘害
+            var responData = tempZb.zbGwOperationUpgradeData;
+            if (responData.Flag != 0 && responData.Flag != 2)
+            {
+                //鍗忚皟鍣ㄥ崌绾уけ璐�
+                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uCoordinatorUpdatingFail));
+
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+
+                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
+
+                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdateFail;
+            }
+            else if (responData.Flag == 0)
+            {
+                this.upDatezbGateway.ReportAction -= this.UpdateCoordinatorProgress;
+                //鍗忚皟鍣ㄥ崌绾у畬浜嗕箣鍚庯紝鍗囩骇缃戝叧
+                this.DoUpdateGateway();
+            }
+            else
+            {
+                //鍗忚皟鍣ㄥ崌绾т腑
+                this.UpdateStatu = UpdateStatuMode.CoordinatorUpdating;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 缃戝叧涓嬭浇___________________________
+
+        /// <summary>
+        /// 涓嬭浇缃戝叧鏂囦欢
+        /// </summary>
+        private async void DownLoadGatewayFile()
+        {
+            //濡傛灉缃戝叧涓嶇敤鍗囩骇锛屽垯鐩存帴璺宠浆涓嬩竴姝�
+            if (this.gatewayFirmware == null)
+            {
+                //鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
+                this.DoUpdateVirtual();
+                return;
+            }
+            this.UpdateStatu = UpdateStatuMode.GatewayDownLoad;
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+
+            //绛変釜1绉�
+            await Task.Delay(1000);
+
+            //缃戝叧鍥轰欢涓嬭浇涓�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoading));
+            this.SetProgressValue(0, 100);
+
+            //涓嬭浇缃戝叧鏂囦欢鐨勮繘搴�
+            this.upDatezbGateway.ReportAction += this.DownLoadGatewayFileProgress;
+
+            //涓嬭浇缃戝叧鏂囦欢
+            var result = await this.upDatezbGateway.DownloadFileAsync(this.gatewayFirmware.DistributedMark, this.gatewayFirmware.Name);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+                //缃戝叧鍥轰欢璧勬簮涓嬭浇澶辫触
+                this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
+            }
+        }
+
+        /// <summary>
+        /// 涓嬭浇缃戝叧鏂囦欢鐨勮繘搴�
+        /// </summary>
+        /// <param name="CommadDiv"></param>
+        /// <param name="objValue"></param>
+        private void DownLoadGatewayFileProgress(string CommadDiv, object objValue)
+        {
+            if (CommadDiv != "DownloadFileProgress" || objValue == null)
+            {
+                return;
+            }
+            var tempZb = (ZbGateway)objValue;
+            if (tempZb.GwId != this.upDatezbGateway.GwId)
+            {
+                //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
+                return;
+            }
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.DownLoadTimeOutRefresh();
+
+            //璁剧疆杩涘害
+            var responData = tempZb.downloadFileProgressResponData;
+            this.SetProgressValue(responData.DownloadPercent, 100);
+
+            if (responData.Status == 2)
+            {
+                //缃戝叧鍥轰欢璧勬簮涓嬭浇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGatewayFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
+
+                this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
+            }
+            else if (responData.Status == 0)
+            {
+                this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
+                //鎵ц铏氭嫙椹卞姩鍗囩骇绋嬪簭
+                this.DoUpdateVirtual();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 缃戝叧鍗囩骇___________________________
+
+        /// <summary>
+        /// 鎵ц缃戝叧鍗囩骇绋嬪簭
+        /// </summary>
+        private async void DoUpdateGateway()
+        {
+            //濡傛灉缃戝叧涓嶇敤鍗囩骇锛屽垯鐩存帴璺宠浆涓嬩竴姝�
+            if (this.gatewayFirmware == null)
+            {
+                //鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
+                this.ShowFinishMsg();
+                return;
+            }
+
+            this.UpdateStatu = UpdateStatuMode.GatewayUpdateReady;
+
+            //缃戝叧鍗囩骇
+            var result = await this.upDatezbGateway.LinuxUpgradeAsync(this.gatewayFirmware.Name);
+            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
+            {
+                if (result.errorMessageBase.Contains("鍥炲瓒呮椂") == true)
+                {
+                    //缃戝叧鍗囩骇鐨勬椂鍊欙紝鏈夊彲鑳藉畠涓嶅啀鍥炰粈涔堜俊鎭�
+                    return;
+                }
+                if (result.errorResponData != null && result.errorResponData.Error == 2)
+                {
+                    //鍥犱负tcp搴曞眰鍦ㄧ綉缁滀笉濂界殑鏃跺�欙紝鏈夊彲鑳戒細閲嶅彂澶氭锛屾墍浠ヨ繖閲屽拷鐣ユ帀銆愬崗璋冨櫒姝e湪鍗囩骇鎴栧浠�/鎭㈠鏁版嵁銆戠殑閿欒
+                    return;
+                }
+
+                //缃戝叧鍗囩骇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGatewayUpdatingFail));
+
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+
+                this.UpdateStatu = UpdateStatuMode.GatewayUpdateFail;
+
+                return;
+            }
+
+            //缃戝叧鍗囩骇涓�
+            this.UpdateStatu = UpdateStatuMode.GatewayUpdating;
+
+            //寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼
+            this.StartGetGatewayVersionThread();
+        }
+
+        #endregion
+
+        #region 鈻� 鍗囩骇瀹屾垚鎻愮ず_______________________
+
+        /// <summary>
+        /// 鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
+        /// </summary>
+        private void ShowFinishMsg()
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鐘舵�佸彉鏇�
+                this.IsFinishUpdate = true;
+                System.Threading.Thread.Sleep(2000);
+
+                //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+                HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
+
+                this.UpdateStatu = UpdateStatuMode.UpdateSuccess;
+                //鎵ц涓嬩竴涓崌绾�
+                HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+                //缃戝叧鍗囩骇鎴愬姛!
+                this.SetProgressValue(100, 100);
+                System.Threading.Thread.Sleep(1500);
+
+                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uGatewayUpdateSuccess));
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 澶勭悊缁撴灉鎻愮ず_______________________
+
+        /// <summary>
+        /// 鏄剧ず閲嶆柊瀹夎鐨勪俊鎭�
+        /// </summary>
+        private void ShowReSetupMsg()
+        {
+            //鐘舵�佸彉鏇�
+            this.IsFinishUpdate = true;
+            //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
+
+            //鎵ц涓嬩竴涓崌绾�
+            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+        }
+
+        /// <summary>
+        /// 鏄剧ず閲嶆柊涓嬭浇妯″紡
+        /// </summary>
+        private void ShowReDownLoadMode()
+        {
+            //鐘舵�佸彉鏇�
+            this.IsFinishUpdate = true;
+            //璁剧疆娌℃湁缃戝叧姝e湪鍗囩骇鐨勬爣璇�
+            HdlGatewayLogic.Current.SetHadGatewayUpdateFlage(false);
+
+            //鎵ц涓嬩竴涓崌绾�
+            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆杩涘害___________________________
+
+        /// <summary>
+        /// 璁惧畾杩涘害鍊�
+        /// </summary>
+        /// <param name="value">杩涘害鍊�</param>
+        /// <param name="maxValue">鏈�澶у��</param>
+        private void SetProgressValue(decimal value, decimal maxValue)
+        {
+            if (value > maxValue)
+            {
+                //鏈夋椂鍊欎細鐬庡彂浠�涔堥杩囨潵
+                return;
+            }
+            decimal result = value / maxValue;
+            this.ProgressEvent?.Invoke(result);
+        }
+
+        /// <summary>
+        /// 璁剧疆閿欒淇℃伅
+        /// </summary>
+        /// <param name="value"></param>
+        private void ShowErrorMsg(string value)
+        {
+            this.UpdateStatuChangedEvent?.Invoke(-1, value);
+        }
+
+        #endregion
+
+        #region 鈻� 缃戝叧涓嬭浇瓒呮椂绾跨▼___________________
+
+        /// <summary>
+        /// 瓒呮椂鏃堕棿璁剧疆
+        /// </summary>
+        private int downLoadTimeOutCount = 30;
+
+        /// <summary>
+        /// 寮�鍚綉鍏充笅杞借秴鏃剁嚎绋�
+        /// </summary>
+        private void StartDownLoadTimeOutThread()
+        {
+            this.downLoadTimeOutCount = 30;
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                while (true)
+                {
+                    var value = this.UpdateStatu.ToString();
+                    if (value.EndsWith("DownLoad") == false)
+                    {
+                        //鎵ц瀹屾垚涓嬭浇鎿嶄綔
+                        break;
+                    }
+                    System.Threading.Thread.Sleep(1000);
+                    this.downLoadTimeOutCount--;
+                    if (this.downLoadTimeOutCount < 0)
+                    {
+                        this.upDatezbGateway.ReportAction -= this.DownLoadVirtualFileProgress;
+                        this.upDatezbGateway.ReportAction -= this.DownLoadCoordinatorFileProgress;
+                        this.upDatezbGateway.ReportAction -= this.DownLoadGatewayFileProgress;
+
+                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
+                        string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail);
+                        //浠庡ご鍐嶆潵
+                        this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
+                        //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                        this.ShowReDownLoadMode();
+                        //璁剧疆閿欒淇℃伅
+                        this.ShowErrorMsg(msg);
+                        break;
+                    }
+                }
+            });
+        }
+
+        /// <summary>
+        /// 瓒呮椂鏃堕棿鍒锋柊
+        /// </summary>
+        private void DownLoadTimeOutRefresh()
+        {
+            this.downLoadTimeOutCount = 30;
+        }
+
+        #endregion
+
+        #region 鈻� 缃戝叧鍗囩骇铏氭嫙杩涘害绾跨▼_______________
+
+        /// <summary>
+        /// 瓒呮椂鏃堕棿璁剧疆
+        /// </summary>
+        private int updateTimeOutCount = 60;
+
+        /// <summary>
+        /// 寮�鍚綉鍏冲崌绾ц櫄鎷熻繘搴︾嚎绋�
+        /// </summary>
+        private void StartUpdateVirtualThread()
+        {
+            //鑾峰彇鍗囩骇鐨勫ぇ鑷存�诲叡鏃堕棿
+            int timeCount = this.GetUpdateTimeCount();
+            //缃戝叧鍗囩骇涓�,鍓╀綑鏃堕棿澶х害涓�:
+            string msg = Language.StringByID(R.MyInternationalizationString.uGatewaiUpdatingAndRemainingTimeMsg);
+            //褰撳墠鐢ㄦ椂
+            int nowTimeCount = 0;
+            //瓒呮椂鏃堕棿璁剧疆
+            this.updateTimeOutCount = 60;
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                while (this.IsFinishUpdate == false)
+                {
+                    System.Threading.Thread.Sleep(1000);
+                    nowTimeCount++;
+
+                    //瓒呮椂
+                    updateTimeOutCount--;
+                    if (updateTimeOutCount == 0)
+                    {
+                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
+                        this.UpdateStatuChangedEvent?.Invoke(-1, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail));
+                        //浠庡ご鍐嶆潵
+                        this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
+                        //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                        this.ShowReDownLoadMode();
+
+                        break;
+                    }
+
+                    //鍓╀綑鏃堕棿
+                    int remainingTime = timeCount - nowTimeCount;
+                    if (remainingTime <= -1)
+                    {
+                        //鏃堕棿鐢ㄥ畬浜嗭紝鐩存帴鏄剧ず鎴愬姛
+                        this.IsFinishUpdate = true;
+                        break;
+                    }
+                    //璁剧疆杩涘害鍊�
+                    this.UpdateStatuChangedEvent?.Invoke(0, msg + remainingTime + "s");
+                    this.SetProgressValue(nowTimeCount, timeCount);
+                }
+            });
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍗囩骇鐨勫ぇ鑷存�诲叡鏃堕棿
+        /// </summary>
+        /// <returns></returns>
+        private int GetUpdateTimeCount()
+        {
+            int timeCount = 0;
+            if (this.virtualFirmware != null)
+            {
+                //铏氭嫙椹卞姩鍗囩骇
+                timeCount += 20;
+            }
+            if (this.coordinatorFirmware != null)
+            {
+                //鍗忚皟鍣ㄥ崌绾�
+                timeCount += 120;
+            }
+            if (this.gatewayFirmware != null)
+            {
+                //缃戝叧鍗囩骇
+                timeCount += 50;
+                //缃戝叧閲嶅惎
+                timeCount += 250;
+            }
+            return timeCount;
+        }
+
+        /// <summary>
+        /// 瓒呮椂鏃堕棿鍒锋柊
+        /// </summary>
+        private void UpdateTimeOutRefresh()
+        {
+            this.updateTimeOutCount = 60;
+        }
+
+        #endregion
+
+        #region 鈻� 寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼_____________
+
+        /// <summary>
+        /// 寮�鍚幏鍙栫綉鍏崇増鏈殑绾跨▼
+        /// </summary>
+        /// <returns></returns>
+        private void StartGetGatewayVersionThread()
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鍏堢瓑涓�120绉掑惂锛岀綉鍏冲崌绾у拰缃戝叧瀹屽叏閲嶅惎闇�瑕佸緢闀挎椂闂�
+                int count = 12;
+                for (int i = 0; i < count; i++)
+                {
+                    if (this.IsFinishUpdate == true)
+                    {
+                        //鍗囩骇瀹屼簡锛屽洜涓烘湁閿欒
+                        break;
+                    }
+                    //杩欎釜鏃跺�欙紝涓嶅簲璇ユ彁绀鸿秴鏃�
+                    this.UpdateTimeOutRefresh();
+
+                    System.Threading.Thread.Sleep(10000);
+                }
+                while (this.IsFinishUpdate == false)
+                {
+                    //鑾峰彇鐗堟湰
+                    var result = HdlGatewayLogic.Current.GetGatewayInfo(this.upDatezbGateway, false, ShowErrorMode.NO);
+                    if (result != null)
+                    {
+                        break;
+                    }
+                    //杩欎釜鏃跺�欙紝涓嶅簲璇ユ彁绀鸿秴鏃�
+                    this.UpdateTimeOutRefresh();
+
+                    System.Threading.Thread.Sleep(5000);
+                }
+                //宸茬粡鑳藉鑾峰彇鏁版嵁
+                this.ShowFinishMsg();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 閲婃斁缂撳瓨___________________________
+
+        /// <summary>
+        /// 閲婃斁缂撳瓨
+        /// </summary>
+        public override void Dispose()
+        {
+            this.ProgressEvent = null;
+            this.UpdateStatuChangedEvent = null;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0