gxc
2019-10-29 081ea8d273048fd03756718ac6fb48a3c09218e9
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);
            //获取网关的信息
@@ -538,8 +548,104 @@
            HdlAutoBackupLogic.AddOrEditorFile(zbGateway.FilePath);
            return true;
        }
        }
        #endregion
        #region ■ 网关切换___________________________
        /// <summary>
        /// 执行切换网关操作
        /// </summary>
        /// <param name="gatewayId"></param>
        public async Task<bool> DoSwitchGateway(string gatewayId)
        {
            var zbGateway = this.GetLocalGateway(gatewayId);
            if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
            {
                //重新获取在线网关的信息
                var result = await this.GetOnlineGatewayInfo(gatewayId);
                if (result == false)
                {
                    return false;
                }
            }
            //切换网关,保存缓存
            this.SaveGatewayIdToLocation(gatewayId);
            return true;
        }
        /// <summary>
        /// 获取在线网关信息
        /// </summary>
        /// <param name="gatewayId"></param>
        /// <returns></returns>
        private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
        {
            //显示进度条
            ProgressBar.Show();
            //检测广播到的这个网关是否拥有住宅ID
            ZbGateway realWay = null;
            bool getGatewayInfo = true;
            if (this.GetRealGateway(ref realWay, gatewayId) == true)
            {
                //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
                if (this.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
                {
                    int result2 = await this.ReBindNewGateway(realWay);
                    if (result2 == 0)
                    {
                        //出现未知错误,请稍后再试
                        this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
                        //关闭进度条
                        ProgressBar.Close();
                    }
                    else if (result2 == -1)
                    {
                        //关闭进度条
                        ProgressBar.Close();
                        return false;
                    }
                    //重新绑定网关里面已经重新获取了网关信息
                    getGatewayInfo = false;
                }
            }
            if (getGatewayInfo == true)
            {
                //获取网关信息
                var info = await this.GetGatewayNewInfoAsync(realWay);
                if (info == null)
                {
                    //关闭进度条
                    ProgressBar.Close();
                    return false;
                }
            }
            //获取全部设备
            bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
            //关闭进度条
            ProgressBar.Close();
            if (result == false)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 保存选择的网关ID到本地
        /// </summary>
        /// <param name="gatewayId"></param>
        public void SaveGatewayIdToLocation(string gatewayId)
        {
            GatewayResourse.AppOldSelectGatewayId = gatewayId;
            byte[] data = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
            Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
        }
        #endregion
        #region ■ 删除网关___________________________
@@ -678,8 +784,8 @@
            if (waitTime == true)
            {
                //这是第一道坎,强制检查WIFI:等待3秒(因为wifi的时候,它会自动去刷新flage)
                System.Threading.Thread.Sleep(3000);
                //这是第一道坎,强制检查WIFI:等待2秒(因为wifi的时候,它会自动去刷新flage)
                System.Threading.Thread.Sleep(2000);
                //检查是否拥有网关存在于WIFi下
                if (this.CheckHadGatewayInWifi(listRealWay) == false)
                {
@@ -1053,38 +1159,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
@@ -1314,7 +1442,7 @@
        #region ■ 主网关判定_________________________
        /// <summary>
        /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
        /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <returns></returns>
@@ -1325,7 +1453,7 @@
        }
        /// <summary>
        /// 判断是否主网关(1:主网关 0:不在线 -1:远程模式,不存在啥主网关的说法)
        /// 判断是否主网关(1:主网关 0:不在线 2:子网关)
        /// </summary>
        /// <param name="waiID">网关id</param>
        /// <returns></returns>
@@ -1336,7 +1464,7 @@
            {
                return 0;
            }
            return zbGateway.IsMainGateWay == true ? 1 : 0;
            return zbGateway.IsMainGateWay == true ? 1 : 2;
        }
        #endregion
@@ -1344,7 +1472,7 @@
        #region ■ 设置网关图片_______________________
        /// <summary>
        /// 设置真实网关的图片,规格:915X492
        /// 设置真实网关的图片
        /// </summary>
        /// <param name="button"></param>
        /// <param name="zbGateway"></param>
@@ -1354,30 +1482,35 @@
            var localWay = this.GetLocalGateway(gwID);
            if (localWay == null || localWay.getGwInfo == null)
            {
                //给一个线程去获取它的镜像类型
                HdlThreadLogic.Current.RunThread(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";
                            }
                        });
                    }
                });
                            });
                        }
                    });
                }
            }
            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>
@@ -1387,28 +1520,30 @@
            var localWay = this.GetLocalGateway(gwID);
            if (localWay == null || localWay.getGwInfo == null)
            {
                //给一个线程去获取它的镜像类型
                HdlThreadLogic.Current.RunThread(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";
                            }
                        });
                    }
                });
                            });
                        }
                    });
                }
            }
            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";
            }
        }
@@ -1443,13 +1578,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)
@@ -2112,19 +2247,19 @@
            else if (backType == GatewayBackupEnum.APir灯光配置)
            {
                var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData));
                result = await HdlPirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
                result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
            }
            else if (backType == GatewayBackupEnum.A干接点颜色调节)
            {
                var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.KeyColorData>(System.Text.Encoding.UTF8.GetString(byteData));
                result = await HdlPanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
                result = await HdlDevicePanelLogic.Current.SetPanelEpointColorInfo((Panel)device, recoverData);
            }
            else if (backType == GatewayBackupEnum.A干接点亮度调节)
            {
                var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(System.Text.Encoding.UTF8.GetString(byteData));
                int directionsLevel = Convert.ToInt32(recoverData["directionsLevel"]);
                int backlightLevel = Convert.ToInt32(recoverData["backlightLevel"]);
                result = await HdlPanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
                result = await HdlDevicePanelLogic.Current.SetDeviceLightSettion((Panel)device, directionsLevel, backlightLevel);
            }
            else if (backType == GatewayBackupEnum.A干接点节能模式)
            {
@@ -2132,12 +2267,21 @@
                bool modeEnable = Convert.ToBoolean(recoverData["modeEnable"]);
                int modeTime = Convert.ToInt32(recoverData["modeTime"]);
                int level = Convert.ToInt32(recoverData["level"]);
                result = await HdlPanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
                result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
            }
            else if (backType == GatewayBackupEnum.A干接点私有属性)
            {
                var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
                result = await HdlPanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
                result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
            }
            else if (backType == GatewayBackupEnum.A窗帘方向)
            {
            }
            else if (backType == GatewayBackupEnum.A窗帘手拉控制)
            {
            }
            else if (backType == GatewayBackupEnum.A窗帘上下限位)
            {
            }
            return result == true ? 1 : -1;
        }