黄学彪
2019-12-12 7e863a33397f317ffc3ffd9288496d0e4f16aa66
ZigbeeApp/Shared/Phone/ZigBee/Device/BindObj.cs
@@ -15,11 +15,11 @@
        {
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                var result = new AddedDeviceBindResponseAllData();
                AddedDeviceBindResponseAllData result = null;
                var mainGateway = ZbGateway.MainGateWay;
                if (mainGateway == null)
                {
                    result.errorMessageBase = "当前没有主网关";
                    result = new AddedDeviceBindResponseAllData { errorMessageBase = "当前没有主网关" };
                    return result;
                }
                Action<string, string> action = (topic, message) =>
@@ -47,7 +47,7 @@
                        var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString());
                        if (tempBindList == null)
                        {
                            result.errorMessageBase = "网关返回的数据为空";
                            result = new AddedDeviceBindResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
@@ -59,22 +59,22 @@
                            }
                            if (dataBindRes != null)
                            {
                                result.addedDeviceBindResponseData = dataBindRes;
                                result = new AddedDeviceBindResponseAllData { addedDeviceBindResponseData = dataBindRes };
                                DebugPrintLog($"UI收到通知后的主题_{topic}");
                            }
                        }
                    }
                    else if (topic == gatewayID + "/" + "Bind/BindResult")
                    {
                        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 = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindResultResponseData>(jobject["Data"].ToString());
                    //else if (topic == gatewayID + "/" + "Bind/BindResult")
                    //{
                    //    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 = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID };
                    //    var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindResultResponseData>(jobject["Data"].ToString());
                        if (tempData != null)
                        {
                            result.addBindResultResponseData = tempData;
                        }
                        DebugPrintLog($"UI收到通知后的主题_{topic}");
                    }
                    //    if (tempData != null)
                    //    {
                    //        result = new AddedDeviceBindResponseAllData { addBindResultResponseData = tempData };
                    //    }
                    //    DebugPrintLog($"UI收到通知后的主题_{topic}");
                    //}
                };
                mainGateway.Actions += action;
                DebugPrintLog("Bind/SetBind_Actions 启动" + "_" + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
@@ -111,7 +111,6 @@
                             { "BindList", bindList }
                    };
                        jObject.Add("Data", data);
                        //ZbGateway.MainGateWay.CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo?.gwID;
                        mainGateway.Send("Bind/SetBind", jObject.ToString());
                    }
                }
@@ -120,42 +119,54 @@
                }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                while ((DateTime.Now - dateTime).TotalMilliseconds < 20 * 1000)
                {
                    await System.Threading.Tasks.Task.Delay(100);
                    if (result == null || result.addedDeviceBindResponseData == null)
                    {
                        continue;
                    }
                    if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
                    {
                        if (result.addBindResultResponseData != null)
                        {
                            break;
                        }
                    }
                    else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
                    {
                        if (result.addBindResultResponseData != null)
                        {
                            break;
                        }
                    }
                    else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
                    {
                        if (result.addBindResultResponseData != null)
                        {
                            break;
                        }
                    }
                    else
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result.errorMessageBase = " 回复超时,请重新操作";
                    result = new AddedDeviceBindResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                //while ((DateTime.Now - dateTime).TotalMilliseconds < 20*1000)
                //{
                //await System.Threading.Tasks.Task.Delay(100);
                //if (result == null || result.addedDeviceBindResponseData == null)
                //{
                //    continue;
                //}
                //if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
                //{
                //    if (result.addBindResultResponseData != null)
                //    {
                //        break;
                //    }
                //}
                //else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
                //{
                //    if (result.addBindResultResponseData != null)
                //    {
                //        break;
                //    }
                //}
                //else if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
                //{
                //    if (result.addBindResultResponseData != null)
                //    {
                //        break;
                //    }
                //}
                //else
                //{
                //    break;
                //}
                //}
                if ((DateTime.Now - dateTime).TotalMilliseconds > 20 * 1000)
                {
                    result = new AddedDeviceBindResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                mainGateway.Actions -= action;
                System.Console.WriteLine($"Bind/SetBind_Actions 退出 { System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond}");
@@ -203,7 +214,12 @@
            /// <summary>
            ///绑定列表 ,当Status=0时存在
            /// </summary>
            public List<AddBindListResponseObj> BindList = new List<AddBindListResponseObj>();
            public List<BindListResponseObj> BindList = new List<BindListResponseObj>();
            /// <summary>
            /// 0:绑定所有目标成功
            ///<para>1:绑定目标失败,绑定设备目标有漏掉</para>
            /// </summary>
            public int Result;
        }
        /// <summary>
@@ -1115,7 +1131,7 @@
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                while ((DateTime.Now - dateTime).TotalMilliseconds < 25 * 1000)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (d != null)
@@ -1123,8 +1139,8 @@
                        break;
                    }
                }
                //一键清除目标,会因为目标数量多而加长时间,目前暂定10秒
                if ((DateTime.Now - dateTime).TotalMilliseconds > 10 * 1000)
                //一键清除目标,会因为目标数量多而加长时间,目前暂定20秒
                if ((DateTime.Now - dateTime).TotalMilliseconds > 25 * 1000)
                {
                    d = new ClearBindInfoResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }