From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs |  172 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 108 insertions(+), 64 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
index 7af7f6f..52239f1 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -15,7 +15,7 @@
         /// <summary>
         /// 鏂颁笂鎶ョ殑璁惧
         /// </summary>
-        private Dictionary<string, List<CommonDevice>> dicNewDevice = new Dictionary<string, List<CommonDevice>>();
+        private List<CommonDevice> listNewDevice = new List<CommonDevice>();
         /// <summary>
         /// 鏄剧ず璁惧绾跨▼鏄惁宸茬粡寮�鍚�
         /// </summary>
@@ -72,7 +72,7 @@
             //璁剧疆鏍囬淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice));
 
-            this.gatewayId = GatewayResourse.NowSelectGatewayId;
+            this.gatewayId = HdlGatewayResourse.NowSelectGatewayId;
             HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId);
 
             //鍒濆鍖栦腑閮ㄦ帶浠�
@@ -106,6 +106,7 @@
 
             //杩涘害鏉�
             this.btnProgressBar = new ProgressRowBar(559, 29);
+            btnProgressBar.ProgressBarGoback = false;
             btnProgressBar.Gravity = Gravity.CenterHorizontal;
             btnProgressBar.Y = Application.GetRealHeight(861);
             bodyFrameLayout.AddChidren(btnProgressBar);
@@ -140,7 +141,7 @@
                 //鍋滄鎺ユ敹
                 this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
 
-                Application.RunOnMainThread(() =>
+                HdlThreadLogic.Current.RunMain(() =>
                 {
                     this.CloseForm();
                 });
@@ -154,50 +155,39 @@
                 return;
             }
 
-            lock (this.dicNewDevice)
+            var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+            CommonDevice.DeviceInfoData info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString());
+            if (info.DriveCode != 0)
             {
-                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
-                CommonDevice.DeviceInfoData info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString());
-                if (info.DriveCode != 0)
-                {
-                    //涓嶉渶瑕佽櫄鎷熻澶�
-                    return;
-                }
-                //鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞�
-                var device = Common.LocalDevice.Current.NewDeviceObjectByDeviceId((DeviceType)jobject.Value<int>("Device_ID"));
-                if (device == null)
-                {
-                    return;
-                }
-                device.DeviceInfo = info;
-
-                //缁欐柊璁惧璁剧疆涓婚敭灞炴��
-                Common.LocalDevice.Current.SetNewDeviceMainKeys(device, jobject);
-                device.CurrentGateWayId = this.realGateway.GwId;
-                //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
-                Common.LocalDevice.Current.SetDeviceInfoToMain(device, device);
-
-                //娣诲姞璁惧鐨勭紦瀛�
-                device.IsOnline = 1;
-                Common.LocalDevice.Current.AddDeviceToMemory(ref device);
- 
-                if (this.dicNewDevice.ContainsKey(device.DeviceAddr) == false)
-                {
-                    this.dicNewDevice[device.DeviceAddr] = new List<CommonDevice>();
-                }
-
-                //鍒锋柊瓒呮椂鏃堕棿
-                this.waitDeviceTimeOut = 20;
-
-                //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
-                HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
-
-                //涓嶉渶瑕�200绔偣鐨勯偅涓澶�  2020.01.13 鍙樻洿:ota涔熷姞杩涙潵
-                this.dicNewDevice[device.DeviceAddr].Add(device);
-
-                //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
-                this.StartShowDeviceAddSuccessFormThread();
+                //涓嶉渶瑕佽櫄鎷熻澶�
+                return;
             }
+            //鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞�
+            var device = HdlDeviceCommonLogic.Current.NewDeviceObjectByDeviceId((DeviceType)jobject.Value<int>("Device_ID"), jobject.Value<int>("Epoint"));
+            if (device == null)
+            {
+                return;
+            }
+            device.DeviceInfo = info;
+
+            //缁欐柊璁惧璁剧疆涓婚敭灞炴��
+            HdlDeviceCommonLogic.Current.SetNewDeviceMainKeys(device, jobject);
+            device.CurrentGateWayId = this.realGateway.GwId;
+            //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
+            HdlDeviceCommonLogic.Current.SetDeviceInfoToMain(device, device);
+
+            //娣诲姞璁惧鐨勭紦瀛�
+            device.IsOnline = 1;
+            HdlDeviceCommonLogic.Current.AddDeviceToMemory(ref device);
+
+            //鍒锋柊瓒呮椂鏃堕棿
+            this.waitDeviceTimeOut = 20;
+
+            //涓嶉渶瑕�200绔偣鐨勯偅涓澶�  2020.01.13 鍙樻洿:ota涔熷姞杩涙潵
+            this.listNewDevice.Add(device);
+
+            //鏈夋柊璁惧锛屽紑鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�)
+            this.StartShowDeviceAddSuccessFormThread();
         }
 
         #endregion
@@ -228,25 +218,41 @@
                 this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
                 System.Threading.Thread.Sleep(200);
 
-                //鐩墠灏卞紕涓�涓�
-                Application.RunOnMainThread(() =>
+                var listDevice = new List<CommonDevice>();
+                for (int i = 0; i < this.listNewDevice.Count; i++)
                 {
-                    foreach (var listDevice in this.dicNewDevice.Values)
+                    var device = this.listNewDevice[i];
+                    if (device.DeviceAddr != this.listNewDevice[0].DeviceAddr)
                     {
-                        //閲嶆柊鍙樻洿UI
-                        foreach (var device in listDevice)
-                        {
-                            if (device is OTADevice)
-                            {
-                                continue;
-                            }
-                            device.IconPath = string.Empty;
-                            device.ReSave();
-                        }
-                        //鏄剧ず璁惧淇℃伅鐢婚潰
-                        this.ShowDeviceAddSuccessForm(listDevice);
-                        break;
+                        continue;
                     }
+                    listDevice.Add(device);
+                    //閲嶆柊鍙樻洿UI
+                    if (device is OTADevice)
+                    {
+                        continue;
+                    }
+                    device.IconPath = string.Empty;
+                    device.ReSave();
+
+                    //璁剧疆璁惧鍔熻兘绫诲瀷 (涓嶈兘鍦ㄦ帴鏀跺洖璺殑鍦版柟鍐欏叆,涓嶇劧缃戝叧鍙兘浼氳秴璐熻嵎)
+                    HdlDeviceCommonLogic.Current.RefreshDeviceFunctionType(device, device, true);
+                    System.Threading.Thread.Sleep(200);
+                    //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
+                    if (HdlDeviceAttributeLogic.Current.ReadDeviceAllFixedAttribute(device) == true)
+                    {
+                        System.Threading.Thread.Sleep(200);
+                    }
+                }
+
+                //璇诲彇璁惧鐨勫叾浠栦俊鎭�
+                this.ReadDeviceOtherInfo(listDevice);
+
+                //鐩墠灏卞紕涓�涓�
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //鏄剧ず璁惧淇℃伅鐢婚潰
+                    this.ShowDeviceAddSuccessForm(listDevice);
                 });
             });
         }
@@ -266,7 +272,7 @@
             if (this.targetFormId != string.Empty)
             {
                 //鍐嶅叧闂澶囧叆缃戞寚瀵肩晫闈�
-                this.CloseFormByFormName(this.targetFormId);
+                HdlFormLogic.Current.CloseFormByFormName(this.targetFormId);
             }
 
             //娣诲姞璁惧
@@ -319,7 +325,7 @@
                             timeCount = 0;
                         }
                     }
-                    Application.RunOnMainThread(() =>
+                    HdlThreadLogic.Current.RunMain(() =>
                     {
                         if (btnRound != null)
                         {
@@ -443,6 +449,15 @@
             else if (topic == gatewayId + "/DeviceInComingRespon")
             {
                 this.topTimeOut = topMaxTime;
+
+                //璁惧鍏ョ綉鏃�,鏈夋椂鍊欑綉鍏充細涓婃姤铏氭嫙璁惧
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                CommonDevice.DeviceInfoData info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString());
+                if (info.DriveCode != 0)
+                {
+                    //涓嶉渶瑕佽櫄鎷熻澶�
+                    return 0;
+                }
                 //缃戝叧鏈�缁堜笂鎶ヨ妭鐐硅澶囦俊鎭�
                 this.btnProgressBar.SetValue(6, 6);
                 return 1;
@@ -472,7 +487,7 @@
                 {
                     //鍝嶅簲瓒呮椂,璇烽噸鏂板叆缃�
                     this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork));
-                    Application.RunOnMainThread(() =>
+                    HdlThreadLogic.Current.RunMain(() =>
                     {
                         //鍏抽棴鐣岄潰
                         this.CloseForm();
@@ -534,6 +549,35 @@
 
         #endregion
 
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 璇诲彇璁惧鐨勫叾浠栦俊鎭�
+        /// </summary>
+        /// <param name="listDevice"></param>
+        private void ReadDeviceOtherInfo(List<CommonDevice> listDevice)
+        {
+            var myTypeInfo = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(listDevice);
+            if (myTypeInfo.BeloneType == DeviceBeloneType.A绐楀笜 && listDevice[0] is Rollershade)
+            {
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+                    for (int i = 1; i <= 3; i++)
+                    {
+                        //閲嶇疆绐楀笜
+                        var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain((Rollershade)listDevice[0], i != 3 ? ShowErrorMode.NO : ShowErrorMode.YES);
+                        if (result == true)
+                        {
+                            return;
+                        }
+                        await System.Threading.Tasks.Task.Delay(1000);
+                    }
+                });
+            }
+        }
+
+        #endregion
+
         #region 鈻� 缁撴瀯浣揰____________________________
 
         /// <summary>

--
Gitblit v1.8.0