| | |
| | | /// <summary> |
| | | /// 解除绑定 |
| | | /// </summary> |
| | | //public async System.Threading.Tasks.Task<DelDeviceBindResponseAllData> DelDeviceBindAsync(DelDeviceBindData delDeviceBindData) |
| | | //{ |
| | | // return await System.Threading.Tasks.Task.Run(async () => |
| | | // { |
| | | // DelDeviceBindResponseAllData responseData = null; |
| | | // var mainGateway = ZbGateway.MainGateWay; |
| | | // if (mainGateway == null) |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { errorMessageBase = "当前没有主网关" }; |
| | | // } |
| | | |
| | | // Action<string, string> action = (topic, message) => |
| | | // { |
| | | // var gatewayID = topic.Split('/')[0]; |
| | | // var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | // if (topic == gatewayID + "/" + "Error_Respon") |
| | | // { |
| | | // var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; |
| | | // var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | // if (temp == null) |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | // } |
| | | // else |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | // } |
| | | // } |
| | | // //场景移除 |
| | | // if (topic == gatewayID + "/" + "Bind/RemoveBind_Respon") |
| | | // { |
| | | // var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | // var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelDeviceBindResponseData>(jobject["Data"].ToString()); |
| | | |
| | | // if (tempData == null) |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | // } |
| | | // else |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { delDeviceBindResponseData = tempData }; |
| | | // System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | // } |
| | | // } |
| | | // //设备移除 |
| | | // if (topic == gatewayID + "/" + "Bind/RemoveBindResult") |
| | | // { |
| | | // var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID }; |
| | | // var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveBindResultResponseData>(jobject["Data"].ToString()); |
| | | |
| | | // if (tempData != null) |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { removeBindResultResponseData = tempData }; |
| | | // System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | // } |
| | | // } |
| | | // }; |
| | | // mainGateway.Actions += action; |
| | | // System.Console.WriteLine("DeviceBind/DelBind_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | // try |
| | | // { |
| | | // if (delDeviceBindData != null) |
| | | // { |
| | | // 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); |
| | | // mainGateway.Send("Bind/RemoveBind", jObject.ToString()); |
| | | // } |
| | | // } |
| | | // catch { } |
| | | |
| | | // var dateTime = DateTime.Now; |
| | | // while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | // { |
| | | // await System.Threading.Tasks.Task.Delay(10); |
| | | // if (responseData != null) |
| | | // { |
| | | // break; |
| | | // } |
| | | // } |
| | | // if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | // { |
| | | // responseData = new DelDeviceBindResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | // } |
| | | // mainGateway.Actions -= action; |
| | | // System.Console.WriteLine("DeviceBind/DelBind_Actions 退出" + System.DateTime.Now.ToString()); |
| | | // return responseData; |
| | | // }); |
| | | //} |
| | | |
| | | //之前2种方式反馈结果 |
| | | public async System.Threading.Tasks.Task<DelDeviceBindResponseAllData> DelDeviceBindAsync(DelDeviceBindData delDeviceBindData) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | |
| | | break; |
| | | } |
| | | } |
| | | else if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 4).Count) |
| | | else if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count) |
| | | { |
| | | if (responseData.removeBindResultResponseData != null) |
| | | { |
| | |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | //一键清除目标,会因为目标数量多而加长时间,目前暂定10秒 |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 10 * 1000) |
| | | { |
| | | d = new ClearBindInfoResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |