JLChen
2021-01-08 281f7d0b8a363a3ed4d6f83bb5fa22bb6d0340f3
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -284,6 +284,8 @@
                };
                EventHandler<MouseEventArgs> eHandler = (sender, e) => {
                    //跳转之前先绑定APP
                    MainPage.Loading.Start ("Please wait...");
                    bool needHide = true;
                    new System.Threading.Thread (() => {
@@ -300,8 +302,14 @@
                    bool goNext = false;
                    System.Threading.Tasks.Task.Run (() => {
                        try {
                            //
                            goNext = CheckIfGoNext (common);
                            if (goNext) {
                                //先重置
                                goNext = false;
                                //网关版本符合要求,判断是否绑定网关成功,绑定成功了才能进行下一步
                                goNext = CheckIfBindGatewaySuccess (common);
                            }
                         
                        } catch (Exception ex) {
                            Utlis.WriteLine (ex.Message);
@@ -342,7 +350,46 @@
            }
        }
        /// <summary>
        /// 检测是否绑定网关成功
        /// </summary>
        /// <returns></returns>
        static bool CheckIfBindGatewaySuccess (GatewayBase gatewayBase)
        {
            try {
                if (UserConfig.Instance.CheckHomeGatewaysNotEmpty ()) {
                    //之前绑定过网关,并且和当前搜索到到网关一致
                    if (UserConfig.Instance.HomeGateway.mac.ToUpper () == gatewayBase.MAC.Replace (".", "").ToUpper ()) {
                        return true;
                    }
                }
                var gatewayMAC = gatewayBase.MAC.Replace (".", "");
                //重新绑定
                var bindGatewayObj = new BindGatewayObj () {
                    homeId = UserConfig.Instance.CurrentRegion.Id,
                    subnetId = gatewayBase.sceneID,
                    deviceId = gatewayBase.DeviceID,
                    gatewayType = GatewayType.BUSUDPGATEWAY.ToString (),
                    mac = gatewayMAC
                };
                var revertObj = HttpServerRequest.Current.BindGateway (bindGatewayObj);
                if (revertObj.Code == StateCode.SUCCESS) {
                    var homeGatewayInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<HomeGatewayInfo> (revertObj.Data.ToString ());
                    if (homeGatewayInfo != null && !string.IsNullOrEmpty (homeGatewayInfo.gatewayId)) {
                        //绑定网关成功,并且成功获取到新绑定的gatewayId
                        UserConfig.Instance.HomeGateway = homeGatewayInfo;
                        UserConfig.Instance.SaveUserConfig ();
                        return true;
                    }
                } else {
                    IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                }
            } catch {
            }
            return false;
        }
        static bool inThisView = false;