From c1de48884fa145a16a0f8bcee93274dcfaa0ff82 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 07 五月 2020 10:40:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-2020xm

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

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
new file mode 100755
index 0000000..2d8c35d
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -0,0 +1,632 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.Device
+{
+    /// <summary>
+    /// 鎼滅储璁惧鐨勭晫闈�
+    /// </summary>
+    public class DeviceSearchForm : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鏂颁笂鎶ョ殑璁惧
+        /// </summary>
+        private Dictionary<string, List<CommonDevice>> dicNewDevice = new Dictionary<string, List<CommonDevice>>();
+        /// <summary>
+        /// 鏄剧ず璁惧绾跨▼鏄惁宸茬粡寮�鍚�
+        /// </summary>
+        private bool isDeviceThreadStart = false;
+        /// <summary>
+        /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱櫨姣)
+        /// </summary>
+        private int waitDeviceTimeOut = 20;
+        /// <summary>
+        /// 涓婚瓒呮椂鐨勭嚎绋嬫槸鍚﹀紑鍚�
+        /// </summary>
+        private bool isTopicTimeOutThreadStart = false;
+        /// <summary>
+        /// 涓婚闂寸殑瓒呮椂鏃堕棿 -100:涓柇绾跨▼(鍗曚綅锛氱)
+        /// </summary>
+        private int topTimeOut = 120;
+        /// <summary>
+        /// 瓒呮椂鏈�澶ф椂闂�
+        /// </summary>
+        private int topMaxTime = 120;
+        /// <summary>
+        /// 鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨�
+        /// </summary>
+        private string targetFormId = string.Empty;
+        /// <summary>
+        /// 缃戝叧ID
+        /// </summary>
+        private string gatewayId = string.Empty;
+        /// <summary>
+        /// 鐪熷疄缃戝叧
+        /// </summary>
+        private ZbGateway realGateway = null;
+        /// <summary>
+        /// 杩涘害鏉�
+        /// </summary>
+        private FrameLayout btnProgressBar = null;
+        /// <summary>
+        /// 杩涘害鍊兼樉绀烘枃鏈殑鏁翠綋
+        /// </summary>
+        private FrameLayout frameProgress = null;
+        /// <summary>
+        /// 杩涘害鍊肩殑鏄剧ず鏂囨湰
+        /// </summary>
+        private NormalViewControl btnProgressView = null;
+        /// <summary>
+        /// 缃戝叧鏄惁鍏佽鍏ョ綉鐨勬爣璇�
+        /// </summary>
+        private bool gatewayCanAddDevice = false;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_formId">鐢婚潰ID,鏍囪瀹冪敱鍝釜鐣岄潰璋冪敤骞舵墦寮�鐨�</param>
+        public void ShowForm(string i_formId)
+        {
+            this.targetFormId = i_formId;
+
+            //璁剧疆鏍囬淇℃伅
+            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice));
+
+            this.gatewayId = GatewayResourse.NowSelectGatewayId;
+            HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId);
+
+            //鍒濆鍖栦腑閮ㄦ帶浠�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄦ帶浠�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖bodyFrame
+            this.ClearBodyFrame();
+
+            //鍥剧墖
+            var framePic = new FrameLayout();
+            framePic.Width = this.GetPictrueRealSize(878);
+            framePic.Height = this.GetPictrueRealSize(478);
+            framePic.Y = Application.GetRealHeight(251);
+            framePic.Gravity = Gravity.CenterHorizontal;
+            framePic.BackgroundImagePath = "Instruct/DeviceSearch.png";
+            bodyFrameLayout.AddChidren(framePic);
+
+            //姝e湪鎼滅储璁惧锛岃绋嶅�欌��
+            var btnSearch = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false);
+            btnSearch.TextAlignment = TextAlignment.Center;
+            btnSearch.TextID = R.MyInternationalizationString.uDeviceSearching;
+            btnSearch.Y = Application.GetRealHeight(1037);
+            btnSearch.TextColor = UserCenterColor.Current.TextGrayColor3;
+            bodyFrameLayout.AddChidren(btnSearch);
+
+            //杩涘害鏉�
+            var btnProRow = new FrameLayout();
+            btnProRow.Gravity = Gravity.CenterHorizontal;
+            btnProRow.Y = Application.GetRealHeight(861);
+            btnProRow.Width = Application.GetRealWidth(559);
+            btnProRow.Height = Application.GetRealHeight(29);
+            btnProRow.BackgroundColor = 0xffe6e6e6;
+            btnProRow.Radius = (uint)Application.GetRealHeight(29) / 2;
+            bodyFrameLayout.AddChidren(btnProRow);
+            this.btnProgressBar = new FrameLayout();
+            btnProgressBar.Width = 0;
+            btnProgressBar.Height = btnProRow.Height;
+            btnProgressBar.BackgroundColor = 0xfffb744a;
+            btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2;
+            btnProRow.AddChidren(btnProgressBar);
+
+            //杩涘害鍊兼枃鏈�
+            this.frameProgress = new FrameLayout();
+            frameProgress.Width = Application.GetRealWidth(84);
+            frameProgress.Height = Application.GetRealHeight(60);
+            frameProgress.Y = Application.GetRealHeight(772);
+            bodyFrameLayout.AddChidren(frameProgress);
+            frameProgress.X = btnProRow.X + btnProgressBar.Right - frameProgress.Width / 2;
+            var btnProgressPic = new PicViewControl(84, 60);
+            btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png";
+            frameProgress.AddChidren(btnProgressPic);
+            this.btnProgressView = new NormalViewControl(84, 32, true);
+            btnProgressView.TextSize = 10;
+            btnProgressView.TextAlignment = TextAlignment.Center;
+            btnProgressView.Text = "0%";
+            frameProgress.AddChidren(btnProgressView);
+
+            if (this.realGateway != null)
+            {
+                //鍏佽璁惧鍏ョ綉
+                this.StartDeviceCanAddToGateway(false);
+                //娣诲姞鐩戣璁惧鏂颁笂鎶ョ殑浜嬩欢
+                this.realGateway.GwResDataAction += this.AdjustGatewayResultData;
+            }
+            //寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼
+            this.StartConcetionAnimeteThread(framePic);
+        }
+
+        #endregion
+
+        #region 鈻� 鏂拌澶囧叆缃戞帴鏀禵____________________
+
+        /// <summary>
+        /// 澶勭悊缃戝叧涓婚涓婃姤
+        /// </summary>
+        /// <param name="topic">涓婚</param>
+        /// <param name="resultData">涓婃姤鏁版嵁</param>
+        private void AdjustGatewayResultData(string topic, string resultData)
+        {
+            //妫�娴嬩富棰�(-1:寮傚父 0:涓嶆槸鐩稿叧鐨勪富棰� 1:璁惧鏈�鍚庣殑涓婚涓婃姤 2:璁惧鏈�缁堜笂鎶ヤ箣鍓嶇殑涓婚)
+            var result = this.CheckIsDeviceComming(topic, resultData);
+            if (result == -1)
+            {
+                //鍋滄鎺ユ敹
+                this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
+
+                Application.RunOnMainThread(() =>
+                {
+                    this.CloseForm();
+                });
+                return;
+            }
+            else if (result == 0) { return; }
+            else if (result == 2)
+            {
+                //寮�鍚富棰橀棿闅旇秴鏃剁嚎绋�
+                this.StartTopicTimeOutThread();
+                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)
+                {
+                    //涓嶉渶瑕佽櫄鎷熻澶�
+                    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 = HdlGatewayLogic.Current.GetGatewayId(this.realGateway);
+                //灏咲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();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鏄剧ず璁惧淇℃伅鐢婚潰___________________
+
+        /// <summary>
+        /// 寮�鍚樉绀鸿澶囦俊鎭晫闈㈢殑绾跨▼
+        /// </summary>
+        private void StartShowDeviceAddSuccessFormThread()
+        {
+            if (this.isDeviceThreadStart == true)
+            {
+                //绾跨▼宸茬粡寮�鍚�
+                return;
+            }
+            this.isDeviceThreadStart = true;
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                while (this.waitDeviceTimeOut >= 0)
+                {
+                    //绛夊緟涓嬩竴涓洖璺�
+                    System.Threading.Thread.Sleep(100);
+                    this.waitDeviceTimeOut--;
+                }
+                //鍋滄鎺ユ敹
+                this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
+                System.Threading.Thread.Sleep(200);
+
+                //鐩墠灏卞紕涓�涓�
+                Application.RunOnMainThread(() =>
+                {
+                    foreach (var listDevice in this.dicNewDevice.Values)
+                    {
+                        //閲嶆柊鍙樻洿UI
+                        foreach (var device in listDevice)
+                        {
+                            if (device is OTADevice)
+                            {
+                                continue;
+                            }
+                            device.IconPath = string.Empty;
+                            device.ReSave();
+                        }
+                        //鏄剧ず璁惧淇℃伅鐢婚潰
+                        this.ShowDeviceAddSuccessForm(listDevice);
+                        break;
+                    }
+                });
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ず璁惧淇℃伅鐢婚潰
+        /// </summary>
+        /// <param name="listMacDevice">鏂拌澶囧垪琛�</param>
+        private void ShowDeviceAddSuccessForm(List<CommonDevice> listMacDevice)
+        {
+            if (this.Parent == null)
+            {
+                return;
+            }
+            //鍏抽棴鑷韩
+            this.CloseForm();
+            if (this.targetFormId != string.Empty)
+            {
+                //鍐嶅叧闂澶囧叆缃戞寚瀵肩晫闈�
+                this.CloseFormByFormName(this.targetFormId);
+            }
+
+            //娣诲姞璁惧
+            var form = new DeviceAddSuccessForm();
+            form.AddForm(listMacDevice[0].DeviceAddr);
+        }
+
+        #endregion
+
+        #region 鈻� 鍋囨兂鍔ㄧ敾___________________________
+
+        /// <summary>
+        /// 寮�鍚繛鎺ョ殑鍋囨兂鍔ㄧ敾鏁堟灉绾跨▼
+        /// </summary>
+        private void StartConcetionAnimeteThread(FrameLayout framePic)
+        {
+            int iconSize = this.GetPictrueRealSize(23);
+
+            var listPoint = new List<int>();
+            for (int i = 0; i < 9; i++)
+            {
+                //X杞�+Index*(鍥炬爣澶у皬+闂磋窛)
+                listPoint.Add(this.GetPictrueRealSize(300) + i * (iconSize + this.GetPictrueRealSize(10)));
+            }
+
+            var btnRound = new PicViewControl(iconSize, iconSize, false);
+            btnRound.Radius = (uint)iconSize / 2;
+            btnRound.BackgroundColor = UserCenterColor.Current.ConcetionRoundColor;
+            btnRound.X = listPoint[0];
+            btnRound.Y = this.GetPictrueRealSize(225);
+            framePic.AddChidren(btnRound);
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                int index = 1;
+                int timeCount = 0;
+                while (this.Parent != null)
+                {
+                    System.Threading.Thread.Sleep(500);
+
+                    //缃戝叧鍏佽璁惧鍏ョ綉鍚庢墠寮�濮嬭鏃�
+                    if (this.gatewayCanAddDevice == true)
+                    {
+                        timeCount++;
+                        if (timeCount >= 360)
+                        {
+                            this.gatewayCanAddDevice = false;
+                            //鍐嶆鍙戦�佸厑璁歌澶囧叆缃�
+                            this.StartDeviceCanAddToGateway(true);
+                            timeCount = 0;
+                        }
+                    }
+                    Application.RunOnMainThread(() =>
+                    {
+                        if (btnRound != null)
+                        {
+                            btnRound.X = listPoint[index];
+                            index++;
+                            if (index == listPoint.Count)
+                            {
+                                index = 0;
+                            }
+                        }
+                    });
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 妫�娴嬩富棰榑__________________________
+
+        /// <summary>
+        /// 妫�娴嬩富棰�(-1:寮傚父 0:涓嶆槸鐩稿叧鐨勪富棰� 1:璁惧鏈�鍚庣殑涓婚涓婃姤 2:璁惧鏈�缁堜笂鎶ヤ箣鍓嶇殑涓婚)
+        /// </summary>
+        /// <param name="topic"></param>
+        /// <param name="resultData"></param>
+        /// <returns></returns>
+        private int CheckIsDeviceComming(string topic, string resultData)
+        {
+            if (topic == gatewayId + "/Device/SearchNewDevice")
+            {
+                //缃戝叧鍥炲璁惧宸茬粡鍙互鍏ョ綉
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchNewDeviceResult>(jobject["Data"].ToString());
+                if (info.time > 0)
+                {
+                    this.gatewayCanAddDevice = true;
+                }
+                return 0;
+            }
+            else if (topic == gatewayId + "/Device/DeviceAnnounce_Respon")
+            {
+                this.topTimeOut = topMaxTime;
+
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceAnnounceInfo>(jobject["Data"].ToString());
+                if (info.IsNew == 6 || info.IsNew == 7)
+                {
+                    return 0;
+                }
+                //缃戝叧鍛婄煡瀹㈡埛绔湁璁惧澹版槑
+                this.SetDeviceProgressValue(1);
+                return 2;
+            }
+            else if (topic == gatewayId + "/Device/DeviceGetActiveEP_Respon")
+            {
+                this.topTimeOut = topMaxTime;
+                //缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囨椿鍔ㄧ鐐逛俊鎭�
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
+                if (info.Result != 0)
+                {
+                    //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃�
+                    //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
+                    HdlLogLogic.Current.WriteLog(-1, resultData);
+                    return 2;
+                }
+                //璁剧疆杩涘害鍊�
+                this.SetDeviceProgressValue(2);
+                return 2;
+            }
+            else if (topic == gatewayId + "/Device/DeviceGetActiveEPSimpleDesc_Respon")
+            {
+                this.topTimeOut = topMaxTime;
+                //缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囨墍鏈夋椿鍔ㄧ鐐圭畝鍗曟弿杩扮淇℃伅
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
+                if (info.Result != 0)
+                {
+                    //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃�
+                    //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
+                    HdlLogLogic.Current.WriteLog(-1, resultData);
+                    return 2;
+                }
+                //璁剧疆杩涘害鍊�
+                this.SetDeviceProgressValue(3);
+                return 2;
+            }
+            else if (topic == gatewayId + "/Device/DeviceGetDefaultBind_Respon")
+            {
+                this.topTimeOut = topMaxTime;
+                //缃戝叧鍛婄煡瀹㈡埛绔幏鍙栬澶囬粯璁ょ粦瀹氳〃淇℃伅
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
+                if (info.Result != 0)
+                {
+                    //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃�
+                    //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
+                    HdlLogLogic.Current.WriteLog(-1, resultData);
+                    return 2;
+                }
+                //璁剧疆杩涘害鍊�
+                this.SetDeviceProgressValue(4);
+                return 2;
+            }
+            else if (topic == gatewayId + "/Device/DeviceAutoBindZBCoord_Respon")
+            {
+                this.topTimeOut = topMaxTime;
+                //缃戝叧鍛婄煡瀹㈡埛绔澶囪嚜鍔ㄧ粦瀹氬崗璋冨櫒淇℃伅
+                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
+                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
+                if (info.Result != 0)
+                {
+                    //鍑虹幇鏈煡閿欒,璇烽噸鏂板叆缃�
+                    //this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndReAccessNetwork));
+                    HdlLogLogic.Current.WriteLog(-1, resultData);
+                    return 2;
+                }
+                //璁剧疆杩涘害鍊�
+                this.SetDeviceProgressValue(5);
+                return 2;
+            }
+            else if (topic == gatewayId + "/DeviceInComingRespon")
+            {
+                this.topTimeOut = topMaxTime;
+                //缃戝叧鏈�缁堜笂鎶ヨ妭鐐硅澶囦俊鎭�
+                this.SetDeviceProgressValue(6);
+                return 1;
+            }
+            return 0;
+        }
+
+        /// <summary>
+        /// 璁剧疆璁惧鐨勮繘搴﹀��
+        /// </summary>
+        /// <param name="value"></param>
+        private void SetDeviceProgressValue(decimal value)
+        {
+            Application.RunOnMainThread(() =>
+            {
+                //杩涘害鏉�
+                decimal result = value / 6;
+                int width = (int)(result * Application.GetRealWidth(559));
+                if (btnProgressBar.Width >= width)
+                {
+                    //鏈変簺璁惧浼氫笂鎶ヤ袱娆�,杩欓噷涓嶈兘璁╁畠鐨勮繘搴︽潯寰�鍥炶蛋
+                    return;
+                }
+                btnProgressBar.Width = width;
+
+                //鏂囨湰鏄剧ず
+                btnProgressView.Text = ((int)(result * 100)) + "%";
+                //鏂囨湰鏄剧ず鐨勯偅涓浘鐗囨绉诲姩
+                frameProgress.X = Application.GetRealWidth(262) + btnProgressBar.Right - frameProgress.Width / 2;
+            });
+        }
+
+        /// <summary>
+        /// 寮�鍚富棰橀棿鐨勮秴鏃剁嚎绋�
+        /// </summary>
+        private void StartTopicTimeOutThread()
+        {
+            if (this.isTopicTimeOutThreadStart == true)
+            {
+                return;
+            }
+            this.isTopicTimeOutThreadStart = true;
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                while (this.Parent != null && this.topTimeOut >= 0)
+                {
+                    //绛夊緟涓嬩竴涓富棰�
+                    System.Threading.Thread.Sleep(1000);
+                    this.topTimeOut--;
+                }
+                if (this.topTimeOut < 0)
+                {
+                    //鍝嶅簲瓒呮椂,璇烽噸鏂板叆缃�
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork));
+                    Application.RunOnMainThread(() =>
+                    {
+                        //鍏抽棴鐣岄潰
+                        this.CloseForm();
+                    });
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍏佽璁惧鍏ョ綉_______________________
+
+        /// <summary>
+        /// 鍏佽璁惧鍏ョ綉
+        /// </summary>
+        /// <param name="close"></param>
+        private void StartDeviceCanAddToGateway(bool close)
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                if (close == true)
+                {
+                    //鍏抽棴鍏ョ綉妯″紡
+                    this.realGateway.AddNewDeviceToGateway(0);
+                    System.Threading.Thread.Sleep(2000);
+                }
+                while (gatewayCanAddDevice == false && this.Parent != null)
+                {
+                    //璁╃綉鍏冲厑璁稿叆缃�
+                    this.realGateway.AddNewDeviceToGateway(180);
+                    System.Threading.Thread.Sleep(6000);
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鐢婚潰鍏抽棴___________________________
+
+        /// <summary>
+        /// 鐢婚潰鍏抽棴
+        /// </summary>
+        public override void CloseFormBefore()
+        {
+            if (this.realGateway != null)
+            {
+                //鍋滄鎺ユ敹
+                this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
+
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    System.Threading.Thread.Sleep(1200);
+                    //鍏抽棴鍏ョ綉妯″紡
+                    this.realGateway.AddNewDeviceToGateway(0);
+                });
+            }
+            base.CloseFormBefore();
+        }
+
+        #endregion
+
+        #region 鈻� 缁撴瀯浣揰____________________________
+
+        /// <summary>
+        /// 缃戝叧鎺ㄩ�佺殑璁惧缁撴灉淇℃伅
+        /// </summary>
+        private class DeviceResultInfo
+        {
+            /// <summary>
+            /// 缁撴灉(0:鎴愬姛,浠ュ閮芥槸澶辫触)
+            /// </summary>
+            public int Result = -1;
+        }
+
+        /// <summary>
+        /// 缃戝叧鍛婄煡瀹㈡埛绔湁璁惧澹版槑
+        /// </summary>
+        private class DeviceAnnounceInfo
+        {
+            /// <summary>
+            /// 钃濇墠鍒氳 6鍜�7 杩欎袱涓槸璁惧閲嶅惎涓婃姤鐨勶紝鐩墠鏆傛椂涓嶈兘鏄剧ず鍒板叆缃戞楠ら偅閲岀殑
+            /// </summary>
+            public int IsNew = -1;
+        }
+
+        /// <summary>
+        /// 缃戝叧鍥炲鍏佽璁惧鍏ョ綉
+        /// </summary>
+        private class SearchNewDeviceResult
+        {
+            /// <summary>
+            /// 鍏佽璁惧鍏ョ綉鐨勬椂闂�
+            /// </summary>
+            public int time = 0;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0