黄学彪
2019-10-18 97e259d966cb5cb5d73c105d5dbaadcc1f920614
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs
@@ -391,7 +391,7 @@
        /// 重新绑定网关(1:正常  -1:异常  0:当前的网关绑定在了当前账号下的不同住宅里面)
        /// </summary>
        /// <param name="zbGateway">网关</param>
        public async Task<int> ReBindNewGateway(ZbGateway zbGateway)
        public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null)
        {
            if (zbGateway == null)
            {
@@ -424,9 +424,19 @@
                HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
            }
            //网关内部数据变更中,请稍后
            ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
            if (btnMsg == null)
            {
                //网关内部数据变更中,请稍后
                ProgressBar.SetValue(Language.StringByID(R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait));
            }
            else
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //网关内部数据变更中,请稍后
                    btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
                });
            }
            await System.Threading.Tasks.Task.Delay(8000);
            //获取网关的信息
@@ -1053,38 +1063,60 @@
        }
        /// <summary>
        /// 获取网关镜像类型的翻译名字
        /// 设置网关镜像类型的翻译名字
        /// </summary>
        /// <param name="button"></param>
        /// <param name="zbGateway"></param>
        /// <returns></returns>
        public string GetGatewayImageText(ZbGateway zbGateway)
        public void SetGatewayImageText(Button button, ZbGateway zbGateway)
        {
            //初始值:无法识别的网关设备
            button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
            string gwId = this.GetGatewayId(zbGateway);
            int imageType = -1;
            if (this.dicGateway.ContainsKey(gwId) == false || this.dicGateway[gwId].getGwInfo == null)
            {
                //如果这个网关没有信息,则从新获取
                var result = this.GetGatewayNewInfo(zbGateway, ShowErrorMode.NO);
                if (result == null)
                if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
                {
                    //无法识别的网关设备
                    return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
                    string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
                    if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
                    {
                        //使用R文件里面设置的东西
                        button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
                    }
                }
                imageType = result.LinuxImageType;
                else
                {
                    //给一个线程去获取它的镜像类型
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
                        if (result != null)
                        {
                            zbGateway.getGwInfo = result;
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
                                if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
                                {
                                    //使用R文件里面设置的东西
                                    button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
                                }
                            });
                        }
                    });
                }
            }
            else
            {
                imageType = Convert.ToInt32(this.GetGwInfoAttribute(this.dicGateway[gwId], "LinuxImageType"));
                string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
                if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
                {
                    //使用R文件里面设置的东西
                    button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName];
                }
            }
            string keyName = Common.LocalDevice.deviceModelIdName + imageType;
            if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
            {
                //使用R文件里面设置的东西
                return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]);
            }
            //无法识别的网关设备
            return Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
        }
        #endregion
@@ -1160,12 +1192,11 @@
        {
            bool bolBreak = false;
            ZbGatewayData.GetGwData result = null;
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                result = await this.GetGatewayNewInfoAsync(zbGateway, mode);
                bolBreak = true;
            })
            { IsBackground = true }.Start();
            });
            while (bolBreak == false)
            {
@@ -1315,7 +1346,7 @@
        #region ■ 主网关判定_________________________
        /// <summary>
        /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
        /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <returns></returns>
@@ -1326,7 +1357,7 @@
        }
        /// <summary>
        /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
        /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
        /// </summary>
        /// <param name="waiID">网关id</param>
        /// <returns></returns>
@@ -1337,7 +1368,7 @@
            {
                return 0;
            }
            return zbGateway.IsMainGateWay == true ? 1 : 0;
            return zbGateway.IsMainGateWay == true ? 1 : 2;
        }
        #endregion
@@ -1345,7 +1376,7 @@
        #region ■ 设置网关图片_______________________
        /// <summary>
        /// 设置真实网关的图片,规格:915X492
        /// 设置真实网关的图片
        /// </summary>
        /// <param name="button"></param>
        /// <param name="zbGateway"></param>
@@ -1355,31 +1386,35 @@
            var localWay = this.GetLocalGateway(gwID);
            if (localWay == null || localWay.getGwInfo == null)
            {
                //给一个线程去获取它的镜像类型
                new System.Threading.Thread(async () =>
                if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
                {
                    var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
                    if (result != null)
                    button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.getGwInfo.LinuxImageType + ".png";
                }
                else
                {
                    //给一个线程去获取它的镜像类型
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        Application.RunOnMainThread(() =>
                        var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
                        if (result != null)
                        {
                            if (button != null)
                            zbGateway.getGwInfo = result;
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
                            }
                        });
                    }
                })
                { IsBackground = true }.Start();
                            });
                        }
                    });
                }
            }
            else
            {
                button.UnSelectedImagePath = "Gateway/RealGateway" + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString() + ".png";
                button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.getGwInfo.LinuxImageType + ".png";
            }
        }
        /// <summary>
        /// 设置网关图标,规格:110X110
        /// 设置网关图标
        /// </summary>
        /// <param name="button"></param>
        /// <param name="zbGateway"></param>
@@ -1389,29 +1424,30 @@
            var localWay = this.GetLocalGateway(gwID);
            if (localWay == null || localWay.getGwInfo == null)
            {
                //给一个线程去获取它的镜像类型
                new System.Threading.Thread(async () =>
                if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
                {
                    var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
                    if (result != null)
                    button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.getGwInfo.LinuxImageType + ".png";
                }
                else
                {
                    //给一个线程去获取它的镜像类型
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        Application.RunOnMainThread(() =>
                        var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
                        if (result != null)
                        {
                            if (button != null)
                            zbGateway.getGwInfo = result;
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
                                button.SelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + "Selected.png";
                            }
                        });
                    }
                })
                { IsBackground = true }.Start();
                            });
                        }
                    });
                }
            }
            else
            {
                string linType = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
                button.UnSelectedImagePath = "Gateway/GatewayIcon" + linType + ".png";
                button.SelectedImagePath = "Gateway/GatewayIcon" + linType + "Selected.png";
                button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.getGwInfo.LinuxImageType + ".png";
            }
        }
@@ -1446,13 +1482,13 @@
        #endregion
        #region ■ 测试网关___________________________
        #region ■ 网关定位___________________________
        /// <summary>
        /// 发送测试指令到设备(网关LED闪烁识别)
        /// 发送指令到网关进行定位(网关LED闪烁识别)
        /// </summary>
        /// <param name="zbGateway"></param>
        public void SetTestCommand(ZbGateway zbGateway)
        public void SetFixedPositionCommand(ZbGateway zbGateway)
        {
            ZbGateway realWay = null;
            if (this.GetRealGateway(ref realWay, zbGateway) == false)
@@ -1575,7 +1611,7 @@
                return;
            }
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dicStatu = this.GetNowOnlineStatuBeforeCheck();
                //等个3秒,准备一下
@@ -1604,8 +1640,7 @@
                }
                //将变化的网关推送到界面上
                this.PushGatewayOnlineStatuToForm(dicStatu);
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
@@ -1623,7 +1658,7 @@
                return;
            }
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //先获取现在全部的网关,初期値设置为不在线
                var dicStatu = this.GetNowOnlineStatuBeforeCheck();
@@ -1665,8 +1700,7 @@
                    string msg = Language.StringByID(R.MyInternationalizationString.uRemoteTimeOutAndNotGatewaiOnline);
                    //this.ShowTipMsg(msg);
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
@@ -1791,7 +1825,7 @@
            }
            bool canBreak = false;
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                List<string> list = new List<string>() { "NotSetAgain" };
@@ -1817,8 +1851,7 @@
                }
                dicDbGateway = dic;
                canBreak = true;
            })
            { IsBackground = true }.Start();
            });
            int count = 0;
            while (canBreak == false)
@@ -1887,7 +1920,7 @@
        /// </summary>
        public void ResetComandToBindBackupGateway()
        {
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
                if (fileData == null)
@@ -1936,8 +1969,7 @@
                    var byteData = System.Text.Encoding.UTF8.GetBytes(strData);
                    Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile, byteData);
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion