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/Panel/PanelSimpleMutilfunctionTargetsForm.cs | 263 +++++++++++++++++----------------------------------- 1 files changed, 86 insertions(+), 177 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs index aaab4fc..d9b1c8c 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelSimpleMutilfunctionTargetsForm.cs @@ -21,16 +21,9 @@ /// 鏋勯�犲嚱鏁� /// </summary> /// <param name="deviceMac">绠�绾﹀鍔熻兘闈㈡澘Mac</param> - public PanelSimpleMutilfunctionTargetsForm(string deviceMac) + public PanelSimpleMutilfunctionTargetsForm(Panel controlDev) { - curControlDev = new Panel(); - var dev = Common.LocalDevice.Current.GetDevice(deviceMac, 62);//绠�绾﹂潰鏉块殢渚夸竴涓洖璺潵鑾峰彇璁惧 - if (dev != null) - { - curControlDev.CurrentGateWayId = dev.CurrentGateWayId; - } - curControlDev.Type = DeviceType.OnOffSwitch; - curControlDev.DeviceAddr = deviceMac; + this.curControlDev = controlDev; } #endregion @@ -88,8 +81,6 @@ /// 鐗规畩绫诲瀷鐨勪釜鏁般�愬紑鍏�/鎻掑骇/鐏厜銆戦渶瑕佽绠楁樉绀虹殑涓暟聽 /// </summary> int specialTypeCount = 0; - - private Action bindReceiveAction = null; /// <summary> /// 鍥炶皟缁戝畾鐩爣椤甸潰鍒锋柊 /// </summary> @@ -111,7 +102,7 @@ CommonPage.Loading.Start(""); InitLocalDeviceList(); - if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Count == 0) + if (curControlDev.bindTargetsFromMutilfunctionPanelList.Count == 0) { IsRead = true; } @@ -157,7 +148,7 @@ btnAddFrameLayout.AddChidren(btnBindAdd); EventHandler<MouseEventArgs> eHandlerAdd = (sender, e) => { - var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev.DeviceAddr, curBindType); + var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev, curBindType); Shared.Phone.UserView.HomePage.Instance.AddChidren(simpleMutilfunctionBindTargetsForm); Shared.Phone.UserView.HomePage.Instance.PageIndex += 1; simpleMutilfunctionBindTargetsForm.Show(); @@ -374,23 +365,23 @@ void RefreshBindListUI() { midVerticalScrolViewLayout.RemoveAll(); - curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curBindType); + curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curControlDev, curBindType); //娉ㄦ剰锛佸悓涓寜閿鐐瑰鏋滄敮鎸佺粦瀹氬绉嶅姛鑳界被鍨嬶紝闇�瑕佹敞鎰忓涓嬪鐞� //褰撴洿鎹㈣澶囧姛鑳界被鍨嬪悗 // 缁戝畾鐨勫紑鍏炽�佹彃搴с�佺伅鍏夋墍鐢ㄧ殑鎸夐敭鍥炶矾浜掔浉鍏宠仈锛屾墍浠ヨ繖閲岄噸鏂拌幏鍙栧皢杩欎笁绉嶇被鍨嬬殑鍏朵粬2绉嶏紝涓轰簡鑾峰彇姝g‘鐨勫紑鍏炽�佹彃搴с�佺伅鍏夌粦瀹氱殑涓暟 switch (curBindType) { case 1: - MutilfunctionPanelMethod.GetMatchBindList(2); - MutilfunctionPanelMethod.GetMatchBindList(3); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 2); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 3); break; case 2: - MutilfunctionPanelMethod.GetMatchBindList(1); - MutilfunctionPanelMethod.GetMatchBindList(3); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 1); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 3); break; case 3: - MutilfunctionPanelMethod.GetMatchBindList(1); - MutilfunctionPanelMethod.GetMatchBindList(2); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 1); + MutilfunctionPanelMethod.GetMatchBindList(curControlDev, 2); break; } int curIndex = 0; @@ -452,7 +443,7 @@ { //琚粦瀹氳澶囧浘鐗囥�愬彲鑳藉拰澶栭潰璁惧绛夊浘鐗囦笉鍚岋紝鍥犱负杩欓噷鏄互鍔熻兘鏉ョ粦瀹氱殑銆� //devicePic.UnSelectedImagePath = tempDev.IconPath; - var device = LocalDevice.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint); + var device = HdlDeviceCommonLogic.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint); switch (curBindType) { case 1: @@ -492,7 +483,7 @@ if (device != null) { //璁惧鍚嶅瓧 - btnBindNameText = Common.LocalDevice.Current.GetDeviceEpointName(device); + btnBindNameText = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device); //鑾峰彇璁惧鎵�灞炴埧闂� var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(device); @@ -546,7 +537,7 @@ var btnDel = rowLayout.AddDeleteControl(); btnDel.ButtonClickEvent += (sender, e) => { - RemoveTargets(bindObj, btnDel); + ClearTargets(bindObj); }; #endregion } @@ -580,7 +571,7 @@ localDeviceList.Clear(); scList.Clear(); //璁惧 - foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice) + foreach (var dev in HdlDeviceCommonLogic.Current.listAllDevice) { localDeviceList.Add(dev); } @@ -600,7 +591,7 @@ GetDeviceBindResponseAllData getBindList = null; if (IsRead) { - MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Clear(); + curControlDev.bindTargetsFromMutilfunctionPanelList.Clear(); var epointList = new List<int>(); for (int i = 2; i < 62; i++) { @@ -632,11 +623,10 @@ curD.BindScenesId = dev.BindScenesId; curD.BindMacAddr = dev.BindMacAddr; curD.BindEpoint = dev.BindEpoint; - curD.ESName = dev.ESName; curD.BindType = dev.BindType; bList.Add(curD); } - MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList); + curControlDev.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList); oldReadEpoint++; } @@ -665,7 +655,7 @@ //鑾峰彇鎵�鏈夌被鍨嬬殑缁戝畾鐩爣涓暟 for (int i = 0; i < 7; i++) { - curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(i); + curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curControlDev, i); } Application.RunOnMainThread(() => @@ -706,7 +696,7 @@ /// <param name="bindDevice"></param> /// <param name="btnDel"></param> /// <returns></returns> - private void RemoveTargets(BindListAllInfo bindDevice, Button btnDel) + private void RemoveTargets(BindListAllInfo bindDevice) { var delDevice = new DelDeviceBindData(); delDevice.DeviceAddr = bindDevice.KeyMacAddr; @@ -725,7 +715,7 @@ switch (curBindType) { case 3: - var device = LocalDevice.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint); + var device = HdlDeviceCommonLogic.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint); if (device != null) { if (device.Type == DeviceType.DimmableLight) @@ -789,9 +779,9 @@ { if (d.Result == 0 || d.Result == 1) { - if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) + if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) { - MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); + curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); } Application.RunOnMainThread(() => { @@ -824,9 +814,9 @@ { if (delResult.removeBindResultResponseData.Result == 0) { - if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) + if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) { - MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); + curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); } Application.RunOnMainThread(() => { @@ -857,7 +847,68 @@ }); } - + /// <summary> + /// 娓呴櫎澶氬姛鑳介潰鏉跨殑鐩爣 + /// </summary> + /// <param name="bindDevice"></param> + /// <param name="btnDel"></param> + /// <returns></returns> + private void ClearTargets(BindListAllInfo bindDevice) + { + System.Threading.Tasks.Task.Run(() => + { + try + { + Application.RunOnMainThread(() => + { + CommonPage.Loading.Start(""); + }); + var currentKey = new Panel(); + currentKey.DeviceAddr = bindDevice.KeyMacAddr; + currentKey.DeviceEpoint = bindDevice.KeyEpoint; + currentKey.CurrentGateWayId = curControlDev.CurrentGateWayId; + var bindResult = HdlDeviceBindLogic.Current.ClearBindInfoAsync(currentKey); + if (bindResult != null && bindResult.clearBindInfoResponseData != null) + { + if (bindResult.clearBindInfoResponseData.Result != 0) + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(CommonPage.Instance); + CommonPage.Loading.Hide(); + }); + } + else + { + if (curControlDev.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint)) + { + curControlDev.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint); + } + Application.RunOnMainThread(() => + { + RefreshBindListUI(); + CommonPage.Loading.Hide(); + }); + } + } + else + { + Application.RunOnMainThread(() => + { + new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5006" + ")", Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(CommonPage.Instance); + }); + } + } + catch { } + finally + { + Application.RunOnMainThread(() => + { + CommonPage.Loading.Hide(); + }); + } + }); + } /// <summary> /// 鍖归厤鐨勭被鍨嬪垪琛� @@ -876,148 +927,6 @@ return textTypelist; } - #endregion - - #region 鍏朵粬鏂规硶 - /// <summary> - /// 鏄剧ず缁戝畾璁惧绾跨▼鏄惁宸茬粡寮�鍚� - /// </summary> - private bool isDeviceThreadStart = false; - /// <summary> - /// 涓婚瓒呮椂鐨勭嚎绋嬫槸鍚﹀紑鍚� - /// </summary> - private bool isTopicTimeOutThreadStart = false; - /// <summary> - /// 绛夊緟璁惧鐨勫洖棣堢殑瓒呮椂鏃堕棿(鍗曚綅锛氱櫨姣) - /// </summary> - private int waitDeviceTimeOut = 20; - /// <summary> - /// 缃戝叧ID - /// </summary> - private string gatewayId = string.Empty; - /// <summary> - /// 鎺ユ敹涓暟 - /// </summary> - private int countBind = 0; - /// <summary> - /// 鏂颁笂鎶ョ殑璁惧 - /// </summary> - private Dictionary<int, GetPanelBindResponseDataByMac> dicPanelResInfo = new Dictionary<int, GetPanelBindResponseDataByMac>(); - - ///<summary > - /// 鍙戦�佽幏鍙栭潰鏉垮懡浠閫氳繃DeviceAddr鑾峰彇] - /// </summary> - private void SendPanelCommand() - { - var jObject = new JObject { { "DeviceAddr", curControlDev.DeviceAddr }, { "Cluster_ID", 0 }, { "Command", 5009 } }; - curControlDev.Gateway.Send(("SearchNewDevice"), jObject.ToString()); - } - - /// <summary> - /// 妫�娴嬭澶囩粦瀹氱殑涓婚 - /// </summary> - /// <param name="topic"></param> - /// <param name="resultData"></param> - /// <returns></returns> - public bool CheckIsDeviceBindTopic(string topic) - { - if (topic == gatewayId + "Bind/GetDeviceLocalBind_Respon") - { - return true; - } - return false; - } - - /// <summary> - /// 澶勭悊闈㈡澘缁戝畾鐨勮澶囷紝鍜岀鐐规病鏈夊叧绯� - /// </summary> - /// <param name="topic">涓婚</param> - /// <param name="resultData">涓婃姤鏁版嵁</param> - private void AdjustGatewayResultData(string topic, string resultData) - { - - //鎺ユ敹缁戝畾璁惧锛屽紑鍚帴鏀剁粦瀹氳澶囦俊鎭殑绾跨▼(閲岄潰浼氱瓑寰呬笁绉掕繖鏍�) - this.ReceiveSuccessFormThread(); - - var result = this.CheckIsDeviceBindTopic(topic); - if (result) - { - lock (dicPanelResInfo) - { - var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData); - var info = Newtonsoft.Json.JsonConvert.DeserializeObject<GetPanelBindResponseDataByMac>(jobject["Data"].ToString()); - countBind = info.MaxNumItems; - if (info != null) - { - foreach (var bDev in info.BindList) - { - if (this.dicPanelResInfo.ContainsKey(bDev.ControllerEpoint) == false) - { - this.dicPanelResInfo[bDev.ControllerEpoint] = info; - } - } - } - - if (this.dicPanelResInfo.Count == countBind) - { - //鍋滄鎺ユ敹 - curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData; - //鍒锋柊瓒呮椂鏃堕棿 - this.waitDeviceTimeOut = -1; - } - else - { - //鍒锋柊瓒呮椂鏃堕棿 - this.waitDeviceTimeOut = 20; - } - } - } - } - - /// <summary> - /// 寮�鍚帴鏀剁粦瀹氳澶囩殑瓒呮椂绾跨▼ - /// </summary> - private void ReceiveSuccessFormThread() - { - if (this.isDeviceThreadStart == true) - { - //绾跨▼宸茬粡寮�鍚� - return; - } - this.isDeviceThreadStart = true; - - HdlThreadLogic.Current.RunThread(() => - { - System.Console.WriteLine($"1AAAAA"); - while (this.waitDeviceTimeOut >= 0) - { - //绛夊緟涓嬩竴涓洖璺� - System.Threading.Thread.Sleep(100); - this.waitDeviceTimeOut--; - System.Console.WriteLine($"2AAAAA"); - } - System.Console.WriteLine($"3AAAAA"); - //鍋滄鎺ユ敹 - bindReceiveAction.Invoke(); - curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData; - System.Console.WriteLine($"4AAAAA"); - System.Threading.Thread.Sleep(200); - System.Console.WriteLine($"5AAAAA"); - - //鐩墠灏卞紕涓�涓� - Application.RunOnMainThread(() => - { - if (this.dicPanelResInfo.Count < countBind) - { - //鍝嶅簲瓒呮椂,璇烽噸鏂颁笅鎷夊埛鏂拌幏鍙栫粦瀹氫俊鎭� - new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); - //鍋滄鎺ユ敹 - curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData; - } - System.Console.WriteLine($"6AAAAA"); - }); - }); - } #endregion } -- Gitblit v1.8.0