黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -15,7 +15,7 @@
        /// <summary>
        /// 新上报的设备
        /// </summary>
        private Dictionary<string, List<CommonDevice>> dicNewDevice = new Dictionary<string, List<CommonDevice>>();
        private List<CommonDevice> listNewDevice = new List<CommonDevice>();
        /// <summary>
        /// 显示设备线程是否已经开启
        /// </summary>
@@ -72,7 +72,7 @@
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddDevice));
            this.gatewayId = GatewayResourse.NowSelectGatewayId;
            this.gatewayId = HdlGatewayResourse.NowSelectGatewayId;
            HdlGatewayLogic.Current.GetRealGateway(ref this.realGateway, this.gatewayId);
            //初始化中部控件
@@ -106,6 +106,7 @@
            //进度条
            this.btnProgressBar = new ProgressRowBar(559, 29);
            btnProgressBar.ProgressBarGoback = false;
            btnProgressBar.Gravity = Gravity.CenterHorizontal;
            btnProgressBar.Y = Application.GetRealHeight(861);
            bodyFrameLayout.AddChidren(btnProgressBar);
@@ -140,7 +141,7 @@
                //停止接收
                this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.CloseForm();
                });
@@ -154,50 +155,39 @@
                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)
            {
                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 = this.realGateway.GwId;
                //将DeviceInfo的属性设置到主属性中
                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();
                //不需要虚拟设备
                return;
            }
            //根据设备Type创建对应的设备对象
            var device = HdlDeviceCommonLogic.Current.NewDeviceObjectByDeviceId((DeviceType)jobject.Value<int>("Device_ID"), jobject.Value<int>("Epoint"));
            if (device == null)
            {
                return;
            }
            device.DeviceInfo = info;
            //给新设备设置主键属性
            HdlDeviceCommonLogic.Current.SetNewDeviceMainKeys(device, jobject);
            device.CurrentGateWayId = this.realGateway.GwId;
            //将DeviceInfo的属性设置到主属性中
            HdlDeviceCommonLogic.Current.SetDeviceInfoToMain(device, device);
            //添加设备的缓存
            device.IsOnline = 1;
            HdlDeviceCommonLogic.Current.AddDeviceToMemory(ref device);
            //刷新超时时间
            this.waitDeviceTimeOut = 20;
            //不需要200端点的那个设备  2020.01.13 变更:ota也加进来
            this.listNewDevice.Add(device);
            //有新设备,开启显示设备信息界面的线程(里面会等待三秒这样)
            this.StartShowDeviceAddSuccessFormThread();
        }
        #endregion
@@ -228,25 +218,41 @@
                this.realGateway.GwResDataAction -= this.AdjustGatewayResultData;
                System.Threading.Thread.Sleep(200);
                //目前就弄一个
                Application.RunOnMainThread(() =>
                var listDevice = new List<CommonDevice>();
                for (int i = 0; i < this.listNewDevice.Count; i++)
                {
                    foreach (var listDevice in this.dicNewDevice.Values)
                    var device = this.listNewDevice[i];
                    if (device.DeviceAddr != this.listNewDevice[0].DeviceAddr)
                    {
                        //重新变更UI
                        foreach (var device in listDevice)
                        {
                            if (device is OTADevice)
                            {
                                continue;
                            }
                            device.IconPath = string.Empty;
                            device.ReSave();
                        }
                        //显示设备信息画面
                        this.ShowDeviceAddSuccessForm(listDevice);
                        break;
                        continue;
                    }
                    listDevice.Add(device);
                    //重新变更UI
                    if (device is OTADevice)
                    {
                        continue;
                    }
                    device.IconPath = string.Empty;
                    device.ReSave();
                    //设置设备功能类型 (不能在接收回路的地方写入,不然网关可能会超负荷)
                    HdlDeviceCommonLogic.Current.RefreshDeviceFunctionType(device, device, true);
                    System.Threading.Thread.Sleep(200);
                    //获取设备的固定属性
                    if (HdlDeviceAttributeLogic.Current.ReadDeviceAllFixedAttribute(device) == true)
                    {
                        System.Threading.Thread.Sleep(200);
                    }
                }
                //读取设备的其他信息
                this.ReadDeviceOtherInfo(listDevice);
                //目前就弄一个
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //显示设备信息画面
                    this.ShowDeviceAddSuccessForm(listDevice);
                });
            });
        }
@@ -266,7 +272,7 @@
            if (this.targetFormId != string.Empty)
            {
                //再关闭设备入网指导界面
                this.CloseFormByFormName(this.targetFormId);
                HdlFormLogic.Current.CloseFormByFormName(this.targetFormId);
            }
            //添加设备
@@ -319,7 +325,7 @@
                            timeCount = 0;
                        }
                    }
                    Application.RunOnMainThread(() =>
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        if (btnRound != null)
                        {
@@ -443,6 +449,15 @@
            else if (topic == gatewayId + "/DeviceInComingRespon")
            {
                this.topTimeOut = topMaxTime;
                //设备入网时,有时候网关会上报虚拟设备
                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 0;
                }
                //网关最终上报节点设备信息
                this.btnProgressBar.SetValue(6, 6);
                return 1;
@@ -472,7 +487,7 @@
                {
                    //响应超时,请重新入网
                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork));
                    Application.RunOnMainThread(() =>
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //关闭界面
                        this.CloseForm();
@@ -534,6 +549,35 @@
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 读取设备的其他信息
        /// </summary>
        /// <param name="listDevice"></param>
        private void ReadDeviceOtherInfo(List<CommonDevice> listDevice)
        {
            var myTypeInfo = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(listDevice);
            if (myTypeInfo.BeloneType == DeviceBeloneType.A窗帘 && listDevice[0] is Rollershade)
            {
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    for (int i = 1; i <= 3; i++)
                    {
                        //重置窗帘
                        var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain((Rollershade)listDevice[0], i != 3 ? ShowErrorMode.NO : ShowErrorMode.YES);
                        if (result == true)
                        {
                            return;
                        }
                        await System.Threading.Tasks.Task.Delay(1000);
                    }
                });
            }
        }
        #endregion
        #region ■ 结构体_____________________________
        /// <summary>