| | |
| | | return false;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 变更网络时的事件
|
| | | /// </summary>
|
| | | private string changedNetworkTime = string.Empty;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | {
|
| | | //允许联网
|
| | | this.CanAccessHttp = true;
|
| | | this.changedNetworkTime = DateTime.Now.ToString("yyyyMMdd HH.mm.ss");
|
| | | //当前执行此线程的时间
|
| | | string thisThreadTime = this.changedNetworkTime;
|
| | |
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false
|
| | | && Common.Config.Instance.HomeId != string.Empty)
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | //不管如何,都要显示转圈
|
| | | ProgressBar.Show();
|
| | |
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false
|
| | | && Common.Config.Instance.HomeId != string.Empty)
|
| | | {
|
| | | ProgressBar.Show();
|
| | | //重新初始化账号信息
|
| | | UserCenterLogic.ReInitUserAccoutInfo();
|
| | | ProgressBar.Close();
|
| | | //因为上面这个东西耗时蛮久的,所以处理完之后进行判断
|
| | | if (thisThreadTime != this.changedNetworkTime)
|
| | | {
|
| | | //在处理的过程中,切换了网络,把下面的处理交给另外的线程
|
| | | return;
|
| | | }
|
| | | }
|
| | | //重新初始化Socket
|
| | | ZigBee.Common.Application.FindGateWaySocket.Stop();
|
| | | //断掉本地连接
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | //断掉远程
|
| | | ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | |
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | | //重新初始化Socket
|
| | | ZigBee.Common.Application.FindGateWaySocket.Stop();
|
| | | if (value == 2)
|
| | | {
|
| | | ZigBee.Common.Application.FindGateWaySocket.Start();
|
| | | }
|
| | | //断掉本地连接
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | if (value == 2)
|
| | | {
|
| | | ZigBee.Common.Application.FindGateWaySocket.Start();
|
| | | //借用一下这个变量(检测能否广播到网关)
|
| | | UserCenterResourse.DicReceiveGatewayTest = new Dictionary<string, ZigBee.Device.ZbGateway>();
|
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 1;
|
| | | //固定等个3秒吧
|
| | | System.Threading.Thread.Sleep(2500);
|
| | | if (thisThreadTime != this.changedNetworkTime)
|
| | | {
|
| | | //变更了网络,交由其他线程处理
|
| | | return;
|
| | | }
|
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 0;
|
| | | System.Threading.Thread.Sleep(500);
|
| | |
|
| | | bool canReceiveGw = false;
|
| | | foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values)
|
| | | {
|
| | | if (gateway.HomeId == Common.Config.Instance.Home.Id)
|
| | | {
|
| | | //能够搜索得到网关
|
| | | canReceiveGw = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | UserCenterResourse.DicReceiveGatewayTest = null;
|
| | | //设置远程连接的初始值
|
| | | ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false;
|
| | | if (canReceiveGw == false)
|
| | | {
|
| | | //如果是远程的话,追加等待时间(总共5秒)
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | }
|
| | | }
|
| | | else if (value == 1)
|
| | | {
|
| | | //如果是4G的话,直接等待
|
| | | System.Threading.Thread.Sleep(4500);
|
| | | }
|
| | | ProgressBar.Close();
|
| | |
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | | }
|
| | |
|