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/HdlDeviceBindLogic.cs | 1500 +++++++++++++++++++++++++++++++----------------------------
1 files changed, 789 insertions(+), 711 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
old mode 100755
new mode 100644
index 97a36c8..30cbe5b
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
@@ -1,725 +1,803 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using ZigBee.Device;
-using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
-
-namespace Shared.Phone.UserCenter
-{
- /// <summary>
- /// 璁惧缁戝畾鐨勯�昏緫
- /// </summary>
- public class HdlDeviceBindLogic
- {
- #region 鈻� 鍙橀噺澹版槑___________________________
-
- /// <summary>
- /// 璁惧缁戝畾鐨勯�昏緫
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
+
+namespace Shared.Phone.UserCenter
+{
+ /// <summary>
+ /// 璁惧缁戝畾鐨勯�昏緫
+ /// </summary>
+ public class HdlDeviceBindLogic
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// 璁惧缁戝畾鐨勯�昏緫
/// </summary>
private static HdlDeviceBindLogic m_Current = null;
- /// <summary>
- /// 璁惧缁戝畾鐨勯�昏緫
+ /// <summary>
+ /// 璁惧缁戝畾鐨勯�昏緫
/// </summary>
- public static HdlDeviceBindLogic Current
- {
- get
- {
- if (m_Current == null)
- {
- m_Current = new HdlDeviceBindLogic();
- }
- return m_Current;
- }
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶嘷____________
-
- /// <summary>
- /// 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶�(閿欒鏃惰繑鍥瀗ull),杩欎釜鏄粰pir浼犳劅鍣ㄧ敤鐨�
- /// </summary>
- /// <param name="mainDevice">璁惧瀵硅薄</param>
- /// <returns></returns>
- public List<CommonDevice> GetBindTargetDevice(CommonDevice mainDevice)
- {
- var result = this.GetDeviceBindAsync(mainDevice);
- if (result == null || result.getAllBindResponseData == null)
- {
- //鑾峰彇璁惧鐨勭粦瀹氱洰鏍囧け璐�
- string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail);
- //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-
- this.ShowErrorMsg(msg);
- return null;
- }
- var listDevice = new List<CommonDevice>();
- foreach (var data in result.getAllBindResponseData.BindList)
- {
- CommonDevice deviceTemp = Common.LocalDevice.Current.GetDevice(data.BindMacAddr, data.BindEpoint);
- if (deviceTemp == null)
- {
- continue;
- }
- listDevice.Add(deviceTemp);
- }
- return listDevice;
- }
-
- /// <summary>
- ///鑾峰彇鎵�鏈夌粦瀹�
- /// </summary>
- public BindObj.GetDeviceBindResponseAllData GetDeviceBindAsync(CommonDevice device)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- var listBind = ModelData.DeviceModelDataLogic.Current.GetDeviceBindList(device, "Bind/GetDeviceBind");
- return new BindObj.GetDeviceBindResponseAllData()
- {
- getAllBindResponseData = new BindObj.GetDeviceBindResponseData
- {
- Result = 0,
- BindList = listBind
- }
- };
- }
-
- var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
- string sendData = jObject.ToString();
- //鍙戦��
- var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/GetDeviceBind", sendData, "Bind/GetDeviceBind_Respon", 6);
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.GetDeviceBindResponseData>(result.ReceiptData);
- return new BindObj.GetDeviceBindResponseAllData() { getAllBindResponseData = tempData };
- }
-
- #endregion
-
- #region 鈻� 鎵ц缁戝畾璁惧鐩爣___________________
-
- /// <summary>
- /// 缁戝畾璁惧鐨勭洰鏍�(杩斿洖鎴愬姛璁剧疆鐨勮澶�,閿欒鏃讹紝杩斿洖null)
- /// </summary>
- /// <param name="mainDevice">璁惧瀵硅薄</param>
- /// <param name="listDevice">瑕佺粦瀹氱殑鐩爣璁惧</param>
- /// <param name="BindCluster">BindCluster</param>
- /// <returns></returns>
- public List<CommonDevice> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
- {
- if (listDevice.Count == 0)
- {
- return new List<CommonDevice>();
- }
-
- var dicDevice = new Dictionary<string, CommonDevice>();
-
- //缁勮鏁版嵁
- var addData = new IASZone.AddBindData();
- addData.DeviceAddr = mainDevice.DeviceAddr;
- addData.Epoint = mainDevice.DeviceEpoint;
- foreach (var device in listDevice)
- {
- var info = new IASZone.AddBindListObj();
- info.BindCluster = BindCluster;
- info.BindMacAddr = device.DeviceAddr;
- info.BindEpoint = device.DeviceEpoint;
- info.BindType = 0;
-
- addData.BindList.Add(info);
-
- //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢�
- string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
- dicDevice[mainkeys] = device;
- }
- //鎵ц缁戝畾
- var result = this.AddDeviceBindAsync(addData);
- if (result == null || result.addedDeviceBindResponseData == null)
- {
- //缁戝畾鐩爣璁剧疆澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
- //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-
- this.ShowErrorMsg(msg);
- return null;
- }
-
- var listSuccess = new List<CommonDevice>();
- foreach (var data in result.addedDeviceBindResponseData.BindList)
- {
- string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
- if (dicDevice.ContainsKey(mainkeys) == true)
- {
- listSuccess.Add(dicDevice[mainkeys]);
- }
- }
-
- if (listSuccess.Count == 0)
- {
- //缁戝畾鐩爣璁剧疆澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
- this.ShowTipMsg(msg);
- }
- return listSuccess;
- }
-
- /// <summary>
- ///璁惧缁戝畾
- /// </summary>
- public BindObj.AddedDeviceBindResponseAllData AddDeviceBindAsync(BindObj.AddBindData addBindData)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- return ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind");
- }
-
- var device = Common.LocalDevice.Current.GetDevice(addBindData.DeviceAddr, addBindData.Epoint);
- //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
- var sendData = this.GetAddDeviceListBindCommandText(addBindData);
- //鍙戦��
- var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetBind", sendData, "Bind/SetBind_Respon", 20);
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
-
- //淇敼缂撳瓨
- ModelData.DeviceModelDataLogic.Current.AddDeviceBindList(addBindData, "Bind/GetDeviceBind");
-
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceBindResponseData>(result.ReceiptData);
- return new BindObj.AddedDeviceBindResponseAllData() { addedDeviceBindResponseData = tempData };
- }
-
- /// <summary>
- /// 鑾峰彇娣诲姞璁惧缁戝畾鐨勫懡浠ゅ瓧绗�
- /// </summary>
- /// <param name="addBindData"></param>
- /// <returns></returns>
- public string GetAddDeviceListBindCommandText(BindObj.AddBindData addBindData)
- {
- var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
- var bindList = new JArray { };
- foreach (var bindInfo in addBindData.BindList)
- {
- if (bindInfo.BindType == 0)
- {
- var dInfo = new JObject{{ "BindMacAddr",bindInfo.BindMacAddr},{ "BindEpoint", bindInfo.BindEpoint} ,
- { "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}};
- bindList.Add(dInfo);
- }
- else if (bindInfo.BindType == 1)
- {
- var dInfo = new JObject{{ "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType},
- { "BindScenesId", bindInfo.BindScenesId}};
- bindList.Add(dInfo);
- }
- }
- var data = new JObject { { "BindName", addBindData.BindName }, { "BindList", bindList } };
- jObject.Add("Data", data);
- return jObject.ToString();
- }
-
- #endregion
-
- #region 鈻� 鍒犻櫎璁惧缁戝畾鐨勭洰鏍嘷________________
-
- /// <summary>
- /// 鍒犻櫎璁惧缁戝畾鐨勭洰鏍�
- /// </summary>
- /// <param name="mainDevice">璁惧瀵硅薄</param>
- /// <param name="deleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
- /// <param name="BindCluster">BindCluster</param>
- /// <returns></returns>
- public bool DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
- {
- //缁勮鏁版嵁
- var deleteData = new IASZone.DelDeviceBindData();
- deleteData.DeviceAddr = mainDevice.DeviceAddr;
- deleteData.Epoint = mainDevice.DeviceEpoint;
-
- var info = new IASZone.RemoveBindListObj();
- info.BindCluster = BindCluster;
- info.BindMacAddr = deleteDevice.DeviceAddr;
- info.BindEpoint = deleteDevice.DeviceEpoint;
- info.BindType = 0;
-
- deleteData.RemoveBindList.Add(info);
-
- //鎵ц鍒犻櫎
- var result = this.DelDeviceBindAsync(deleteData);
- if (result == null || result.delDeviceBindResponseData == null)
- {
- //鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-
- this.ShowErrorMsg(msg);
- return false;
- }
-
- foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
- {
- //0:鎴愬姛 1:璁惧涓嶅湪缁戝畾鍒楄〃涓� 锛屼篃鍙互浠h〃鎴愬姛
- if (data.Result == 0 || data.Result == 1 || data.Result == 5)
- {
- return true;
- }
- //3:澶辫触锛屽湪绛夊緟鑺傜偣璁惧纭鏄惁瑙i櫎缁戝畾鎴愬姛
- else if (data.Result == 3)
- {
- //鍏朵粬缁戝畾鐩爣姝e湪鍒犻櫎涓紝璇风◢鍚庡啀璇�
- string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
- this.ShowErrorMsg(msg);
- return false;
- }
- //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
- else if (data.Result == 2)
- {
- if (result.removeBindResultResponseData == null)
- {
- //鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- this.ShowErrorMsg(msg);
- return false;
- }
- else
- {
- //鎴愬姛
- if (result.removeBindResultResponseData.Result == 0)
- {
- return true;
- }
- //136锛氭帶鍒惰澶囨湰鍦扮粦瀹氬垪琛ㄤ腑鏃犳缁戝畾
- else if (result.removeBindResultResponseData.Result == 136)
- {
- //杩欎釜鍙互褰撳仛鎴愬姛
- return true;
- }
- else
- {
- //鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- this.ShowErrorMsg(msg);
- return false;
- }
- }
- }
- }
- return false;
- }
-
- /// <summary>
- /// 鍒犻櫎璁惧缁戝畾鐨勭洰鏍�
- /// </summary>
- /// <param name="mainDevice">璁惧瀵硅薄</param>
- /// <param name="listDeleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
- /// <param name="BindCluster">BindCluster</param>
- /// <returns>杩斿洖鐨勬槸鎴愬姛鍒犻櫎鐨勮澶�</returns>
- public List<CommonDevice> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
- {
- //缁勮鏁版嵁
- var deleteData = new IASZone.DelDeviceBindData();
- deleteData.DeviceAddr = mainDevice.DeviceAddr;
- deleteData.Epoint = mainDevice.DeviceEpoint;
-
- var dicDevice = new Dictionary<string, CommonDevice>();
- foreach (var device in listDeleteDevice)
- {
- var info = new IASZone.RemoveBindListObj();
- info.BindCluster = BindCluster;
- info.BindMacAddr = device.DeviceAddr;
- info.BindEpoint = device.DeviceEpoint;
- info.BindType = 0;
-
- deleteData.RemoveBindList.Add(info);
- //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢�
- string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
- dicDevice[mainkeys] = device;
- }
- var listSuccess = new List<CommonDevice>();
-
- var result = this.DelDeviceBindAsync(deleteData);
- if (result == null || result.delDeviceBindResponseData == null)
- {
- //鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
- msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
-
- this.ShowErrorMsg(msg);
- return listSuccess;
- }
-
- foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
- {
- string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
- //0:鎴愬姛 1:璁惧涓嶅湪缁戝畾鍒楄〃涓� 锛屼篃鍙互浠h〃鎴愬姛
- if (data.Result == 0 || data.Result == 1)
- {
- listSuccess.Add(dicDevice[mainkeys]);
- }
- //3:澶辫触锛屽湪绛夊緟鑺傜偣璁惧纭鏄惁瑙i櫎缁戝畾鎴愬姛
- else if (data.Result == 3)
- {
- //璁惧鍚嶇О 鍏朵粬缁戝畾鐩爣姝e湪鍒犻櫎涓紝璇风◢鍚庡啀璇�
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
- this.ShowErrorMsg(msg);
- }
- //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
- else if (data.Result == 2)
- {
- if (result.removeBindResultResponseData == null)
- {
- //璁惧鍚嶇О 鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- this.ShowErrorMsg(msg);
- }
- else
- {
- //鎴愬姛
- if (result.removeBindResultResponseData.Result == 0)
- {
- listSuccess.Add(dicDevice[mainkeys]);
- }
- //136锛氭帶鍒惰澶囨湰鍦扮粦瀹氬垪琛ㄤ腑鏃犳缁戝畾
- else if (result.removeBindResultResponseData.Result == 136)
- {
- //杩欎釜鍙互褰撳仛鎴愬姛
- listSuccess.Add(dicDevice[mainkeys]);
- }
- else
- {
- //璁惧鍚嶇О 鍒犻櫎缁戝畾鐩爣澶辫触
- string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
- msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
- this.ShowErrorMsg(msg);
- }
- }
- }
- }
- return listSuccess;
- }
-
- /// <summary>
- /// 鍒犻櫎璁惧鐨勭粦瀹氱洰鏍�
- /// </summary>
- /// <param name="delDeviceBindData"></param>
- /// <returns></returns>
- public BindObj.DelDeviceBindResponseAllData DelDeviceBindAsync(BindObj.DelDeviceBindData delDeviceBindData)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- return ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
- }
- var device = Common.LocalDevice.Current.GetDevice(delDeviceBindData.DeviceAddr, delDeviceBindData.Epoint);
- //鑾峰彇闇�瑕佸彂閫佺殑鏁版嵁
- var sendData = this.GetDeleteDeviceBindCommandText(delDeviceBindData);
- //鍙戦�佸懡浠�
- var result = this.SendDeleteBindJobjectDataToGateway(device, "Bind/RemoveBind",
- sendData, new List<string>() { "Bind/RemoveBind_Respon", "Bind/RemoveBindResult" }, 6);
-
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
- var responseData = new BindObj.DelDeviceBindResponseAllData();
- if (result.listReceiptData[0] != null)
- {
- var tempData1 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(result.listReceiptData[0]);
- responseData.delDeviceBindResponseData = tempData1;
- }
-
- if (result.listReceiptData[1] != null)
- {
- var tempData2 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(result.listReceiptData[1]);
- responseData.removeBindResultResponseData = tempData2;
- }
-
- //淇敼缂撳瓨
- ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
-
- return responseData;
- }
-
- /// <summary>
- ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭�
- /// </summary>
- public BindObj.ClearBindInfoResponseAllData ClearBindInfoAsync(CommonDevice device)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- return ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
- }
-
- var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
- var sendData = jObject.ToString();
- var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/ClearBindInfo", sendData, "Bind/ClearBindInfo_Respon", 25);
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
-
- //淇敼缂撳瓨
- ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
-
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.ClearBindInfoResponseData>(result.ReceiptData);
- return new BindObj.ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
- }
-
-
- /// <summary>
- /// 鑾峰彇鍒犻櫎璁惧缁戝畾鍒楄〃鐨勫懡浠ゅ瓧绗�
- /// </summary>
- /// <param name="delDeviceBindData"></param>
- /// <returns></returns>
- public string GetDeleteDeviceBindCommandText(BindObj.DelDeviceBindData delDeviceBindData)
- {
- var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
- var removeBindList = new JArray { };
- foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
- {
- //鍒犻櫎璁惧
- if (removeBindInfo.BindType == 0)
- {
- var dInfo = new JObject{{ "BindMacAddr",removeBindInfo.BindMacAddr},{ "BindEpoint", removeBindInfo.BindEpoint} ,
- { "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType}};
- removeBindList.Add(dInfo);
- }
- //鍒犻櫎鍦烘櫙
- else if (removeBindInfo.BindType == 1)
- {
- var dInfo = new JObject{{ "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType},
- { "BindScenesId", removeBindInfo.BindScenesId}};
- removeBindList.Add(dInfo);
- }
- }
- var data = new JObject { { "RemoveBindList", removeBindList } };
- jObject.Add("Data", data);
-
- return jObject.ToString();
- }
-
- /// <summary>
- /// 鍙戦�佸垹闄ょ粦瀹氱殑鏁版嵁鍒扮綉鍏筹紝骞舵帴鍙楃綉鍏宠繑鍥炵殑鏁版嵁,listReceiptData涓鸿繑鍥炲��(鍒犻櫎缁戝畾鐨勬帴鍙e緢鐗规畩,闇�瑕佺嫭绔嬪嚭鏉�)
- /// </summary>
- /// <param name="device">璁惧瀵硅薄</param>
- /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
- /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param>
- /// <param name="listReceiptTopic">鎸囧畾鎺ユ敹鍝簺涓婚</param>
- /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
- /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
- private ReceiptGatewayResult SendDeleteBindJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 3)
- {
- var reResult = new ReceiptGatewayResult();
- reResult.listReceiptData = new string[listReceiptTopic.Count];
- var myGateway = device.Gateway;
- if (myGateway == null)
- {
- //鑾峰彇缃戝叧瀵硅薄澶辫触
- reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
- reResult.ErrorMsgDiv = -1;
- return reResult;
- }
- //缃戝叧ID
- string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
- //閿欒涓婚
- string errorTopic = gatewayID + "/" + "Error_Respon";
- //妫�娴嬪璞$殑涓婚
- for (int i = 0; i < listReceiptTopic.Count; i++)
- {
- listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
- }
-
- bool canbreak = false;
- Action<string, string> receiptAction = (topic, message) =>
- {
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- //缃戝叧鍥炲閿欒
- if (topic == errorTopic)
- {
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
- reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
- }
- //濡傛灉鏄寚瀹氱殑涓婚
- for (int i = 0; i < listReceiptTopic.Count; i++)
- {
- if (topic == listReceiptTopic[i])
- {
- string deviceMac = jobject["DeviceAddr"].ToString();
- int deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
- if (device.DeviceAddr != deviceMac)
- {
- //涓嶆槸鍚屼竴涓笢瑗縈ac
- return;
- }
- if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
- {
- //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣
- return;
- }
- reResult.listReceiptData[i] = jobject["Data"].ToString();
- if (i == 0)
- {
- //鍙湁鏄疊ind/RemoveBind_Respon涓婚,鎵嶈兘涓柇
- canbreak = true;
- }
- }
- }
-
- };
- myGateway.Actions += receiptAction;
- //鍙戦�佹暟鎹�
- myGateway.Send(sendTopic, sendData);
-
- //瓒呮椂鏃堕棿
- int TimeOut = 0;
- waitTime = 20 * waitTime;
- while (canbreak == false && TimeOut < waitTime)
- {
- //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
- System.Threading.Thread.Sleep(50);
- TimeOut++;
- }
- myGateway.Actions -= receiptAction;
- receiptAction = null;
- if (canbreak == false)
- {
- //瓒呮椂
- reResult.ErrorMsgDiv = 0;
- }
- else
- {
- //姝e父鎺ユ敹鍒扮綉鍏宠繑鍥炵殑鏁版嵁
- if (reResult.listReceiptData.Length == 1)
- {
- //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲�
- reResult.ReceiptData = reResult.listReceiptData[0];
- reResult.listReceiptData = null;
- }
- }
-
- return reResult;
- }
-
-
- #endregion
-
- #region 鈻� 閰嶇疆闈㈡澘鍔熻兘_______________________
-
- ///<summary >
- ///閰嶇疆闈㈡澘鍔熻兘
- ///<para>value:缁欓潰鏉块厤缃殑妯″紡</para>
- /// </summary>
- public CommonDevice.SetWritableValueResponAllData ConfigureHdlKeyValueAsync(CommonDevice device, Panel.KeyMode value, int clusterID = 6)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- return ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
- }
- //鑾峰彇鍙戦�佹暟鎹�
- var sendData = this.GetConfigureHdlKeyCommandText(device.DeviceAddr, device.DeviceEpoint, value, clusterID);
- var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
-
- //淇敼缂撳瓨
- ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
-
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
- return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
- }
-
+ public static HdlDeviceBindLogic Current
+ {
+ get
+ {
+ if (m_Current == null)
+ {
+ m_Current = new HdlDeviceBindLogic();
+ }
+ return m_Current;
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶嘷____________
+
+ /// <summary>
+ /// 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶�(閿欒鏃惰繑鍥瀗ull),杩欎釜鏄粰pir浼犳劅鍣ㄧ敤鐨�
+ /// </summary>
+ /// <param name="mainDevice">璁惧瀵硅薄</param>
+ /// <returns></returns>
+ public List<CommonDevice> GetBindTargetDevice(CommonDevice mainDevice)
+ {
+ var result = this.GetDeviceBindAsync(mainDevice);
+ if (result == null || result.getAllBindResponseData == null)
+ {
+ //鑾峰彇璁惧鐨勭粦瀹氱洰鏍囧け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowErrorMsg(msg);
+ return null;
+ }
+ var listDevice = new List<CommonDevice>();
+ foreach (var data in result.getAllBindResponseData.BindList)
+ {
+ CommonDevice deviceTemp = Common.LocalDevice.Current.GetDevice(data.BindMacAddr, data.BindEpoint);
+ if (deviceTemp == null)
+ {
+ continue;
+ }
+ listDevice.Add(deviceTemp);
+ }
+ return listDevice;
+ }
+
+ /// <summary>
+ ///鑾峰彇鎵�鏈夌粦瀹�
+ /// </summary>
+ public BindObj.GetDeviceBindResponseAllData GetDeviceBindAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ var listBind = TemplateData.TemplateDeviceDataLogic.Current.GetDeviceBindList(device);
+ return new BindObj.GetDeviceBindResponseAllData()
+ {
+ getAllBindResponseData = new BindObj.GetDeviceBindResponseData
+ {
+ Result = 0,
+ BindList = listBind
+ }
+ };
+ }
+
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
+ string sendData = jObject.ToString();
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/GetDeviceBind", sendData, "Bind/GetDeviceBind_Respon", 6);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.GetDeviceBindResponseData>(result.ReceiptData);
+ return new BindObj.GetDeviceBindResponseAllData() { getAllBindResponseData = tempData };
+ }
+
+ #endregion
+
+ #region 鈻� 鎵ц缁戝畾璁惧鐩爣___________________
+
+ /// <summary>
+ /// 缁戝畾璁惧鐨勭洰鏍�(杩斿洖鎴愬姛璁剧疆鐨勮澶�,閿欒鏃讹紝杩斿洖null)
+ /// </summary>
+ /// <param name="mainDevice">璁惧瀵硅薄</param>
+ /// <param name="listDevice">瑕佺粦瀹氱殑鐩爣璁惧</param>
+ /// <param name="BindCluster">BindCluster</param>
+ /// <returns></returns>
+ public List<CommonDevice> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
+ {
+ if (listDevice.Count == 0)
+ {
+ return new List<CommonDevice>();
+ }
+
+ var dicDevice = new Dictionary<string, CommonDevice>();
+
+ //缁勮鏁版嵁
+ var addData = new IASZone.AddBindData();
+ addData.DeviceAddr = mainDevice.DeviceAddr;
+ addData.Epoint = mainDevice.DeviceEpoint;
+ foreach (var device in listDevice)
+ {
+ var info = new IASZone.AddBindListObj();
+ info.BindCluster = BindCluster;
+ info.BindMacAddr = device.DeviceAddr;
+ info.BindEpoint = device.DeviceEpoint;
+ info.BindType = 0;
+
+ addData.BindList.Add(info);
+
+ //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢�
+ string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+ dicDevice[mainkeys] = device;
+ }
+ //鎵ц缁戝畾
+ var result = this.AddDeviceBindAsync(addData);
+ if (result == null || result.addedDeviceBindResponseData == null)
+ {
+ //缁戝畾鐩爣璁剧疆澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowErrorMsg(msg);
+ return null;
+ }
+
+ var listSuccess = new List<CommonDevice>();
+ foreach (var data in result.addedDeviceBindResponseData.BindList)
+ {
+ string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
+ if (dicDevice.ContainsKey(mainkeys) == true)
+ {
+ listSuccess.Add(dicDevice[mainkeys]);
+ }
+ }
+
+ if (listSuccess.Count == 0)
+ {
+ //缁戝畾鐩爣璁剧疆澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
+ this.ShowTipMsg(msg);
+ }
+ return listSuccess;
+ }
+
+ /// <summary>
+ ///璁惧缁戝畾
+ /// </summary>
+ public BindObj.AddedDeviceBindResponseAllData AddDeviceBindAsync(BindObj.AddBindData addBindData)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.AddDeviceBindList(addBindData, null);
+ }
+
+ var device = Common.LocalDevice.Current.GetDevice(addBindData.DeviceAddr, addBindData.Epoint);
+ //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+ var sendData = this.GetAddDeviceListBindCommandText(addBindData);
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetBind", sendData, "Bind/SetBind_Respon", 20);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.AddDeviceBindList(addBindData, result.JsonData[0]);
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceBindResponseData>(result.ReceiptData);
+ return new BindObj.AddedDeviceBindResponseAllData() { addedDeviceBindResponseData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇娣诲姞璁惧缁戝畾鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="addBindData"></param>
+ /// <returns></returns>
+ public string GetAddDeviceListBindCommandText(BindObj.AddBindData addBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
+ var bindList = new JArray { };
+ foreach (var bindInfo in addBindData.BindList)
+ {
+ if (bindInfo.BindType == 0)
+ {
+ var dInfo = new JObject{{ "BindMacAddr",bindInfo.BindMacAddr},{ "BindEpoint", bindInfo.BindEpoint} ,
+ { "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType}};
+ bindList.Add(dInfo);
+ }
+ else if (bindInfo.BindType == 1)
+ {
+ var dInfo = new JObject{{ "BindCluster", bindInfo.BindCluster} ,{ "BindType",bindInfo.BindType},
+ { "BindScenesId", bindInfo.BindScenesId}};
+ bindList.Add(dInfo);
+ }
+ }
+ var data = new JObject { { "BindName", addBindData.BindName }, { "BindList", bindList } };
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ ///璁惧缁戝畾銆愪竴瀵逛竴 缁戝畾锛屼竴涓寜閿洖璺彧鑳界粦瀹氫竴涓澶囥��
+ /// </summary>
+ public BindObj.AddedDeviceSingleBindResponseAllData AddDeviceSingleBindAsync(BindObj.AddSingleBindData addSingleBindData)
+ {
+ var device = Common.LocalDevice.Current.GetDevice(addSingleBindData.DeviceAddr, addSingleBindData.Epoint);
+ //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+ var sendData = this.GetAddDeviceListSingleBindCommandText(addSingleBindData);
+ //鍙戦��
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/SetSingleBind", sendData, "Bind/SetSingleBind_Respon", 20);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.AddedDeviceSingleBindResponseData>(result.ReceiptData);
+ return new BindObj.AddedDeviceSingleBindResponseAllData() { addedDeviceSingleBindResponseData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇娣诲姞璁惧缁戝畾鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="addBindData"></param>
+ /// <returns></returns>
+ public string GetAddDeviceListSingleBindCommandText(BindObj.AddSingleBindData addSingleBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", addSingleBindData.DeviceAddr }, { "Epoint", addSingleBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5020 } };
+ var data = new JObject { };
+ var bindClusterList = new JArray { };
+ foreach (var cluster in addSingleBindData.BindClusterList)
+ {
+ bindClusterList.Add(cluster);
+ }
+ if (addSingleBindData.BindType == 0)
+ {
+ data = new JObject { { "BindName", addSingleBindData.BindName }, { "BindType", addSingleBindData.BindType }, { "BindClusterList", bindClusterList }, { "BindMacAddr", addSingleBindData.BindMacAddr }, { "BindEpoint", addSingleBindData.BindEpoint } };
+ }
+ else if (addSingleBindData.BindType == 1)
+ {
+ data = new JObject { { "BindName", addSingleBindData.BindName }, { "BindType", addSingleBindData.BindType }, { "BindClusterList", bindClusterList }, { "BindScenesId", addSingleBindData.BindScenesId } };
+
+ }
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
+
+
+ #endregion
+
+ #region 鈻� 鍒犻櫎璁惧缁戝畾鐨勭洰鏍嘷________________
+
+ /// <summary>
+ /// 鍒犻櫎璁惧缁戝畾鐨勭洰鏍�
+ /// </summary>
+ /// <param name="mainDevice">璁惧瀵硅薄</param>
+ /// <param name="deleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
+ /// <param name="BindCluster">BindCluster</param>
+ /// <returns></returns>
+ public bool DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
+ {
+ //缁勮鏁版嵁
+ var deleteData = new IASZone.DelDeviceBindData();
+ deleteData.DeviceAddr = mainDevice.DeviceAddr;
+ deleteData.Epoint = mainDevice.DeviceEpoint;
+
+ var info = new IASZone.RemoveBindListObj();
+ info.BindCluster = BindCluster;
+ info.BindMacAddr = deleteDevice.DeviceAddr;
+ info.BindEpoint = deleteDevice.DeviceEpoint;
+ info.BindType = 0;
+
+ deleteData.RemoveBindList.Add(info);
+
+ //鎵ц鍒犻櫎
+ var result = this.DelDeviceBindAsync(deleteData);
+ if (result == null || result.delDeviceBindResponseData == null)
+ {
+ //鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+
+ foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
+ {
+ //0:鎴愬姛 1:璁惧涓嶅湪缁戝畾鍒楄〃涓� 锛屼篃鍙互浠h〃鎴愬姛
+ if (data.Result == 0 || data.Result == 1 || data.Result == 5)
+ {
+ return true;
+ }
+ //3:澶辫触锛屽湪绛夊緟鑺傜偣璁惧纭鏄惁瑙i櫎缁戝畾鎴愬姛
+ else if (data.Result == 3)
+ {
+ //鍏朵粬缁戝畾鐩爣姝e湪鍒犻櫎涓紝璇风◢鍚庡啀璇�
+ string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+ //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
+ else if (data.Result == 2)
+ {
+ if (result.removeBindResultResponseData == null)
+ {
+ //鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+ else
+ {
+ //鎴愬姛
+ if (result.removeBindResultResponseData.Result == 0)
+ {
+ return true;
+ }
+ //136锛氭帶鍒惰澶囨湰鍦扮粦瀹氬垪琛ㄤ腑鏃犳缁戝畾
+ else if (result.removeBindResultResponseData.Result == 136)
+ {
+ //杩欎釜鍙互褰撳仛鎴愬姛
+ return true;
+ }
+ else
+ {
+ //鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// 鍒犻櫎璁惧缁戝畾鐨勭洰鏍�
+ /// </summary>
+ /// <param name="mainDevice">璁惧瀵硅薄</param>
+ /// <param name="listDeleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param>
+ /// <param name="BindCluster">BindCluster</param>
+ /// <returns>杩斿洖鐨勬槸鎴愬姛鍒犻櫎鐨勮澶�</returns>
+ public List<CommonDevice> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
+ {
+ //缁勮鏁版嵁
+ var deleteData = new IASZone.DelDeviceBindData();
+ deleteData.DeviceAddr = mainDevice.DeviceAddr;
+ deleteData.Epoint = mainDevice.DeviceEpoint;
+
+ var dicDevice = new Dictionary<string, CommonDevice>();
+ foreach (var device in listDeleteDevice)
+ {
+ var info = new IASZone.RemoveBindListObj();
+ info.BindCluster = BindCluster;
+ info.BindMacAddr = device.DeviceAddr;
+ info.BindEpoint = device.DeviceEpoint;
+ info.BindType = 0;
+
+ deleteData.RemoveBindList.Add(info);
+ //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢�
+ string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+ dicDevice[mainkeys] = device;
+ }
+ var listSuccess = new List<CommonDevice>();
+
+ var result = this.DelDeviceBindAsync(deleteData);
+ if (result == null || result.delDeviceBindResponseData == null)
+ {
+ //鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowErrorMsg(msg);
+ return listSuccess;
+ }
+
+ foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
+ {
+ string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
+ //0:鎴愬姛 1:璁惧涓嶅湪缁戝畾鍒楄〃涓� 锛屼篃鍙互浠h〃鎴愬姛
+ if (data.Result == 0 || data.Result == 1)
+ {
+ listSuccess.Add(dicDevice[mainkeys]);
+ }
+ //3:澶辫触锛屽湪绛夊緟鑺傜偣璁惧纭鏄惁瑙i櫎缁戝畾鎴愬姛
+ else if (data.Result == 3)
+ {
+ //璁惧鍚嶇О 鍏朵粬缁戝畾鐩爣姝e湪鍒犻櫎涓紝璇风◢鍚庡啀璇�
+ string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
+ msg += Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
+ this.ShowErrorMsg(msg);
+ }
+ //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
+ else if (data.Result == 2)
+ {
+ if (result.removeBindResultResponseData == null)
+ {
+ //璁惧鍚嶇О 鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
+ msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ this.ShowErrorMsg(msg);
+ }
+ else
+ {
+ //鎴愬姛
+ if (result.removeBindResultResponseData.Result == 0)
+ {
+ listSuccess.Add(dicDevice[mainkeys]);
+ }
+ //136锛氭帶鍒惰澶囨湰鍦扮粦瀹氬垪琛ㄤ腑鏃犳缁戝畾
+ else if (result.removeBindResultResponseData.Result == 136)
+ {
+ //杩欎釜鍙互褰撳仛鎴愬姛
+ listSuccess.Add(dicDevice[mainkeys]);
+ }
+ else
+ {
+ //璁惧鍚嶇О 鍒犻櫎缁戝畾鐩爣澶辫触
+ string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
+ msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
+ this.ShowErrorMsg(msg);
+ }
+ }
+ }
+ }
+ return listSuccess;
+ }
+
+ /// <summary>
+ /// 鍒犻櫎璁惧鐨勭粦瀹氱洰鏍�
+ /// </summary>
+ /// <param name="delDeviceBindData"></param>
+ /// <returns></returns>
+ public BindObj.DelDeviceBindResponseAllData DelDeviceBindAsync(BindObj.DelDeviceBindData delDeviceBindData)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
+ }
+ var device = Common.LocalDevice.Current.GetDevice(delDeviceBindData.DeviceAddr, delDeviceBindData.Epoint);
+ //鑾峰彇闇�瑕佸彂閫佺殑鏁版嵁
+ var sendData = this.GetDeleteDeviceBindCommandText(delDeviceBindData);
+ //鍙戦�佸懡浠�
+ var result = this.SendDeleteBindJobjectDataToGateway(device, "Bind/RemoveBind",
+ sendData, new List<string>() { "Bind/RemoveBind_Respon", "Bind/RemoveBindResult" }, 6);
+
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var responseData = new BindObj.DelDeviceBindResponseAllData();
+ if (result.listReceiptData[0] != null)
+ {
+ var tempData1 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(result.listReceiptData[0]);
+ responseData.delDeviceBindResponseData = tempData1;
+ }
+
+ if (result.listReceiptData[1] != null)
+ {
+ var tempData2 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(result.listReceiptData[1]);
+ responseData.removeBindResultResponseData = tempData2;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
+
+ return responseData;
+ }
+
+ /// <summary>
+ ///鍒犻櫎涓�涓帶鍒惰澶囨墍鏈夌粦瀹氫俊鎭�
+ /// </summary>
+ public BindObj.ClearBindInfoResponseAllData ClearBindInfoAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ClearDeviceAllBind(device);
+ }
+
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
+ var sendData = jObject.ToString();
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/ClearBindInfo", sendData, "Bind/ClearBindInfo_Respon", 25);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.ClearDeviceAllBind(device);
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.ClearBindInfoResponseData>(result.ReceiptData);
+ return new BindObj.ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
+ }
+
+
+ /// <summary>
+ /// 鑾峰彇鍒犻櫎璁惧缁戝畾鍒楄〃鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="delDeviceBindData"></param>
+ /// <returns></returns>
+ public string GetDeleteDeviceBindCommandText(BindObj.DelDeviceBindData delDeviceBindData)
+ {
+ var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
+ var removeBindList = new JArray { };
+ foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
+ {
+ //鍒犻櫎璁惧
+ if (removeBindInfo.BindType == 0)
+ {
+ var dInfo = new JObject{{ "BindMacAddr",removeBindInfo.BindMacAddr},{ "BindEpoint", removeBindInfo.BindEpoint} ,
+ { "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType}};
+ removeBindList.Add(dInfo);
+ }
+ //鍒犻櫎鍦烘櫙
+ else if (removeBindInfo.BindType == 1)
+ {
+ var dInfo = new JObject{{ "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType},
+ { "BindScenesId", removeBindInfo.BindScenesId}};
+ removeBindList.Add(dInfo);
+ }
+ }
+ var data = new JObject { { "RemoveBindList", removeBindList } };
+ jObject.Add("Data", data);
+
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 鍙戦�佸垹闄ょ粦瀹氱殑鏁版嵁鍒扮綉鍏筹紝骞舵帴鍙楃綉鍏宠繑鍥炵殑鏁版嵁,listReceiptData涓鸿繑鍥炲��(鍒犻櫎缁戝畾鐨勬帴鍙e緢鐗规畩,闇�瑕佺嫭绔嬪嚭鏉�)
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <param name="sendTopic">鍙戦�佺殑涓婚</param>
+ /// <param name="sendData">闇�瑕佸彂閫佺殑鏁版嵁 JObject.ToString()鐨勪笢瑗�</param>
+ /// <param name="listReceiptTopic">鎸囧畾鎺ユ敹鍝簺涓婚</param>
+ /// <param name="waitTime">瓒呮椂鏃堕棿(绉�)</param>
+ /// <returns>缃戝叧杩斿洖鐨勬暟鎹�</returns>
+ private ReceiptGatewayResult SendDeleteBindJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 3)
+ {
+ var reResult = new ReceiptGatewayResult();
+ reResult.listReceiptData = new string[listReceiptTopic.Count];
+ var myGateway = device.Gateway;
+ if (myGateway == null)
+ {
+ //鑾峰彇缃戝叧瀵硅薄澶辫触
+ reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
+ reResult.ErrorMsgDiv = -1;
+ return reResult;
+ }
+ //缃戝叧ID
+ string gatewayID = device.Gateway.GwId;
+ //閿欒涓婚
+ string errorTopic = gatewayID + "/" + "Error_Respon";
+ //妫�娴嬪璞$殑涓婚
+ for (int i = 0; i < listReceiptTopic.Count; i++)
+ {
+ listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
+ }
+
+ bool canbreak = false;
+ BindObj.DelDeviceBindResponseData delDeviceBindData = null;
+ BindObj.RemoveBindResultResponseData removeBindResult = null;
+
+ Action<string, string> receiptAction = (topic, message) =>
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+ //缃戝叧鍥炲閿欒
+ if (topic == errorTopic)
+ {
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+ reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
+ }
+ //濡傛灉鏄寚瀹氱殑涓婚
+ for (int i = 0; i < listReceiptTopic.Count; i++)
+ {
+ if (topic == listReceiptTopic[i])
+ {
+ string deviceMac = jobject["DeviceAddr"].ToString();
+ int deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
+ if (device.DeviceAddr != deviceMac)
+ {
+ //涓嶆槸鍚屼竴涓笢瑗縈ac
+ return;
+ }
+ if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
+ {
+ //涓嶆槸鍚屼竴涓笢瑗�,杩欓噷搴旇闇�瑕佺壒娈婂鐞�200绔偣
+ return;
+ }
+ reResult.listReceiptData[i] = jobject["Data"].ToString();
+
+ if (i == 0)
+ {
+ //"Bind/RemoveBind_Respon"涓婚
+ delDeviceBindData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(reResult.listReceiptData[i]);
+ }
+ else if (i == 1)
+ {
+ //"Bind/RemoveBindResult"涓婚
+ removeBindResult = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(reResult.listReceiptData[i]);
+ }
+
+ if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
+ {
+ canbreak = true;
+ }
+ else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
+ {
+ if (removeBindResult != null)
+ {
+ canbreak = true;
+ }
+ }
+ else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
+ {
+ if (removeBindResult != null)
+ {
+ canbreak = true;
+ }
+ }
+ else
+ {
+ canbreak = true;
+ }
+ }
+ }
+
+ };
+ myGateway.Actions += receiptAction;
+ //鍙戦�佹暟鎹�
+ myGateway.Send(sendTopic, sendData);
+
+ //瓒呮椂鏃堕棿
+ int TimeOut = 0;
+ waitTime = 20 * waitTime;
+ while (canbreak == false && TimeOut < waitTime)
+ {
+ //鍏ㄩ儴鎺ユ敹鎵嶉��鍑�
+ System.Threading.Thread.Sleep(50);
+ TimeOut++;
+ }
+ myGateway.Actions -= receiptAction;
+ receiptAction = null;
+ if (canbreak == false)
+ {
+ //瓒呮椂
+ reResult.ErrorMsgDiv = 0;
+ }
+ else
+ {
+ //姝e父鎺ユ敹鍒扮綉鍏宠繑鍥炵殑鏁版嵁
+ if (reResult.listReceiptData.Length == 1)
+ {
+ //濡傛灉鍙湁涓�涓富棰�,鍒欐浛鎹㈠彉閲�
+ reResult.ReceiptData = reResult.listReceiptData[0];
+ reResult.listReceiptData = null;
+ }
+ }
+
+ return reResult;
+ }
+
+
+ #endregion
+
+ #region 鈻� 閰嶇疆闈㈡澘鍔熻兘_______________________
+
+ ///<summary >
+ ///閰嶇疆闈㈡澘鍔熻兘
+ ///<para>value:缁欓潰鏉块厤缃殑妯″紡</para>
+ /// </summary>
+ public CommonDevice.SetWritableValueResponAllData ConfigureHdlKeyValueAsync(CommonDevice device, Panel.KeyMode value, int clusterID = 6)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, null);
+ }
+ //鑾峰彇鍙戦�佹暟鎹�
+ var sendData = this.GetConfigureHdlKeyCommandText(device.DeviceAddr, device.DeviceEpoint, value, clusterID);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, result.JsonData[0]);
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
+ return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
+ }
+
/// <summary>
/// 璇诲彇闈㈡澘鐨勯厤缃俊鎭�
/// </summary>
- public Panel.PanelConfigureInfoResponAllData ReadPanelConfigureInfoAsync(CommonDevice device)
- {
- //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
- if (Common.Config.Instance.Home.IsVirtually == true)
- {
- return ModelData.DeviceModelDataLogic.Current.ReadPanelConfigureKeyModel(device);
- }
-
- var JObject = new JObject {{ "DeviceAddr",device.DeviceAddr },{ "Epoint", device.DeviceEpoint },
- { "Cluster_ID", (int)Cluster_ID.HdlKey },{ "Command", 108 }};
- var attriBute = new JArray { new JObject { { "AttriButeId", (int)AttriButeId.HdlKey } } };
- var data = new JObject { { "AttriBute", attriBute } };
- JObject.Add("Data", data);
-
- //鍙戦�佹暟鎹�
- var sendData = JObject.ToString();
- string receiptTopic = "DeviceStatusReport/" + device.DeviceAddr + "/" + device.DeviceEpoint + "/" + (int)Cluster_ID.HdlKey + "/" + (int)AttriButeId.HdlKey;
- var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetDeviceStatus", sendData, receiptTopic);
- if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
- {
- return null;
- }
-
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(result.ReceiptData);
- return new Panel.PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
- }
-
- /// <summary>
- /// 鑾峰彇閰嶇疆闈㈡澘鍔熻兘鐨勫懡浠ゅ瓧绗�
- /// </summary>
+ public Panel.PanelConfigureInfoResponAllData ReadPanelConfigureInfoAsync(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true || Common.Config.Instance.Home.IsShowTemplate == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.ReadPanelConfigureKeyModel(device);
+ }
+
+ var JObject = new JObject {{ "DeviceAddr",device.DeviceAddr },{ "Epoint", device.DeviceEpoint },
+ { "Cluster_ID", (int)Cluster_ID.HdlKey },{ "Command", 108 }};
+ var attriBute = new JArray { new JObject { { "AttriButeId", (int)AttriButeId.HdlKey } } };
+ var data = new JObject { { "AttriBute", attriBute } };
+ JObject.Add("Data", data);
+
+ //鍙戦�佹暟鎹�
+ var sendData = JObject.ToString();
+ string receiptTopic = "DeviceStatusReport/" + device.DeviceAddr + "/" + device.DeviceEpoint + "/" + (int)Cluster_ID.HdlKey + "/" + (int)AttriButeId.HdlKey;
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetDeviceStatus", sendData, receiptTopic);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+
+ var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(result.ReceiptData);
+ return new Panel.PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
+ }
+
+ /// <summary>
+ /// 鑾峰彇閰嶇疆闈㈡澘鍔熻兘鐨勫懡浠ゅ瓧绗�
+ /// </summary>
/// <param name="device">璁惧瀵硅薄</param>
/// <param name="value">閿��</param>
/// <param name="clusterID">闀濱D</param>
- /// <returns></returns>
+ /// <returns></returns>
public string GetConfigureHdlKeyCommandText(string DeviceAddr, int DeviceEpoint, Panel.KeyMode value, int clusterID = 6)
- {
+ {
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } };
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 6533 }, { "AttributeDataType", 33 }, { "AttributeData", (int)value } };
jObject.Add("Data", data);
return jObject.ToString();
- }
-
- #endregion
-
- #region 鈻� 涓�鑸柟娉昣__________________________
-
- /// <summary>
- /// 鏄剧ず閿欒淇℃伅绐楀彛
- /// </summary>
- /// <param name="msg"></param>
- private void ShowErrorMsg(string msg)
- {
- Application.RunOnMainThread(() =>
- {
- var contr = new ShowMsgControl(ShowMsgType.Error, msg);
- contr.Show();
- });
- }
-
- /// <summary>
- /// 鏄剧ずTip淇℃伅绐楀彛
- /// </summary>
- /// <param name="msg"></param>
- private void ShowTipMsg(string msg)
- {
- Application.RunOnMainThread(() =>
- {
- var contr = new UserCenter.ShowMsgControl(ShowMsgType.Tip, msg);
- contr.Show();
- });
- }
-
- #endregion
- }
-}
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 鏄剧ず閿欒淇℃伅绐楀彛
+ /// </summary>
+ /// <param name="msg"></param>
+ private void ShowErrorMsg(string msg)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+ contr.Show();
+ });
+ }
+
+ /// <summary>
+ /// 鏄剧ずTip淇℃伅绐楀彛
+ /// </summary>
+ /// <param name="msg"></param>
+ private void ShowTipMsg(string msg)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var contr = new UserCenter.ShowMsgControl(ShowMsgType.Tip, msg);
+ contr.Show();
+ });
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0