New file |
| | |
| | | using System; |
| | | using Shared.Common; |
| | | using Newtonsoft.Json; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | |
| | | namespace Shared.Phone |
| | | { |
| | | /// <summary> |
| | | /// 个人中心逻辑类 |
| | | /// </summary> |
| | | public class HdlUserCenterLogic |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 个人中心逻辑类 |
| | | /// </summary> |
| | | private static HdlUserCenterLogic m_Current = null; |
| | | /// <summary> |
| | | /// 个人中心逻辑类 |
| | | /// </summary> |
| | | public static HdlUserCenterLogic Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new HdlUserCenterLogic(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 刷新本地缓存_______________________ |
| | | |
| | | /// <summary> |
| | | /// 刷新本地所有缓存(目前此方法只提供给恢复备份数据使用) |
| | | /// </summary> |
| | | public void RefreshAllMemory() |
| | | { |
| | | //刷新住宅对象 |
| | | RefreshHomeObject(); |
| | | //根据模板文件,恢复数据 |
| | | HdlTemplateCommonLogic.Current.RecoverDataByTemplateBinFile(); |
| | | //强制生成设备和网关文件 |
| | | HdlTemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce(); |
| | | //刷新本地网关文件 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //刷新本地设备 |
| | | HdlDeviceCommonLogic.Current.ReFreshByLocal(); |
| | | //需优先于刷新房间,同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除 |
| | | HdlGatewayLogic.Current.SynchronizeDbGateway(); |
| | | //从本地重新加载全部的房间 |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | //断开远程Mqtt连接,重新连接 |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true); |
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce(); |
| | | }, ShowErrorMode.NO); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新住宅对象 |
| | | /// </summary> |
| | | public void RefreshHomeObject() |
| | | { |
| | | var home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id); |
| | | |
| | | //刷新楼层 |
| | | Config.Instance.Home.FloorDics = home.FloorDics; |
| | | Config.Instance.Home.CurrentFloorId = string.Empty; |
| | | if (Config.Instance.Home.TemplateMode == -1) |
| | | { |
| | | Config.Instance.Home.TemplateMode = home.TemplateMode; |
| | | if (Config.Instance.Home.TemplateMode == -1) |
| | | { |
| | | //默认初始值 |
| | | Config.Instance.Home.TemplateMode = 1; |
| | | } |
| | | } |
| | | |
| | | Config.Instance.Home.Save(false); |
| | | |
| | | //主页需要重新刷新 |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 刷新个人中心的内存及线程___________ |
| | | |
| | | /// <summary> |
| | | /// 刷新个人中心的内存及线程(仅限切换住宅时调用) |
| | | /// </summary> |
| | | /// <param name="i_isLogin">是否是登陆操作</param> |
| | | /// <returns></returns> |
| | | public bool InitUserCenterMenmoryAndThread(bool i_isLogin) |
| | | { |
| | | //调用这个方法,都需要重新刷新主页 |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | |
| | | //添加网络状态监听 |
| | | HdlWifiLogic.Current.StartListenNetWork(); |
| | | |
| | | //如果是虚拟住宅 |
| | | if (Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | //初始化虚拟住宅的个人中心的数据(切换住宅使用) |
| | | InitUserCenterMenmoryByVirtualHome(); |
| | | return true; |
| | | } |
| | | |
| | | //APP缓存加载开始 |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = false; |
| | | |
| | | //是否有网络,初始值为:有 |
| | | int hadNet = 1; |
| | | if (i_isLogin == true) |
| | | { |
| | | //登陆的时候,获取云端住宅列表(0:当前没有网络的情况下加载本地住宅 1:通过联网加载及校验本地住宅) |
| | | hadNet = HdlResidenceLogic.Current.GetHomeListsFromDbOnLogin(); |
| | | } |
| | | |
| | | //清空所有成员缓存 |
| | | this.ClearAllMemberMemory(); |
| | | |
| | | //加载住宅配置信息 |
| | | HdlUserCenterResourse.ResidenceOption = HdlUserCenterResourse.ResidenceOption.Load(); |
| | | |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | |
| | | //检测当前账号的权限的合法性 |
| | | this.CheckNowAuthority(); |
| | | |
| | | //如果有网络的话 |
| | | if (hadNet == 1) |
| | | { |
| | | //初始化主人的Token(管理员专用,不用管失败还是成功,出问题,底层接口会踢到登陆界面) |
| | | HdlAccountLogic.Current.InitMasterToken(); |
| | | |
| | | //重新发送命令去绑定断网情况下备份的网关 |
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway(); |
| | | //读取隐匿配置 |
| | | HdlBackupLogic.Current.LoadHideOption(); |
| | | //调试:强制开启后台调试App功能 |
| | | if (HdlUserCenterResourse.HideOption.StartDebugApp == 1) |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | var form = new UserCenter.HideOption.HideOptionMainForm(); |
| | | form.AddForm(); |
| | | }); |
| | | ProgressBar.Close(true); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //关闭所有接收 |
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent(); |
| | | //刷新安防上报信息 |
| | | HdlAlarmsLogic.Current.RefreshAlarmInfo(); |
| | | |
| | | //同步数据(二次调用没关系) |
| | | int result = -1; |
| | | if (hadNet == 1) |
| | | { |
| | | result = HdlBackupLogic.Current.SynchronizeDbAutoBackupData(); |
| | | } |
| | | |
| | | //初始化本地的网关信息 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //初始化本地的设备信息 |
| | | HdlDeviceCommonLogic.Current.ReFreshByLocal(); |
| | | |
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步) |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | |
| | | if (hadNet == 1) |
| | | { |
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除 |
| | | //HdlGatewayLogic.Current.SynchronizeDbGateway(); |
| | | } |
| | | |
| | | //断开远程Mqtt连接,重新连接 |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true); |
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce(); |
| | | }, ShowErrorMode.NO); |
| | | |
| | | //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用) |
| | | HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId(); |
| | | |
| | | //0:已经同步过,不需要同步,这个时候需要提示备份 |
| | | if (result == 0 && i_isLogin == true) |
| | | { |
| | | //开启自动备份 |
| | | HdlBackupLogic.Current.ShowAutoBackupPromptedForm(); |
| | | } |
| | | //显示引导界面 |
| | | HdlFormLogic.Current.ShowGuideForm(result); |
| | | |
| | | //APP缓存加载完成 |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = true; |
| | | |
| | | if (Shared.Phone.Device.Logic.Send.If_Exist == "1") |
| | | { |
| | | //以本地状态为主打开GPS服务 |
| | | Application.StartGPSLocationService(); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化虚拟住宅的个人中心的数据(切换住宅使用) |
| | | /// </summary> |
| | | private void InitUserCenterMenmoryByVirtualHome() |
| | | { |
| | | //清空所有成员缓存 |
| | | ClearAllMemberMemory(); |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | //关闭所有接收 |
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent(); |
| | | //初始化本地的网关信息 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //初始化本地的设备信息 |
| | | HdlDeviceCommonLogic.Current.ReFreshByLocal(); |
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步) |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | //刷新左边刷新房间视图列表 |
| | | HdlRoomLogic.Current.RefreshRoomListView(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空所有成员缓存 |
| | | /// </summary> |
| | | private void ClearAllMemberMemory() |
| | | { |
| | | //消息记录重新读取及检测 |
| | | HdlControlResourse.ReadMessageAgain = true; |
| | | HdlControlResourse.HadNewMessage = false; |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | for (int i = 0; i < HdlControlResourse.listMessageManaContr.Count; i++) |
| | | { |
| | | //显示角标特效 |
| | | HdlControlResourse.listMessageManaContr[i].IsSelected = false; |
| | | } |
| | | }); |
| | | |
| | | //切换住宅清除之前逻辑缓存数据; |
| | | Common.Logic.LogicList.Clear(); |
| | | Common.Logic.LockLogicList.Clear(); |
| | | Common.Logic.SoneLogicList.Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测当前账号的权限的合法性 |
| | | /// </summary> |
| | | private void CheckNowAuthority() |
| | | { |
| | | var result = HdlAccountLogic.Current.RefreshAccountAuthority(); |
| | | if (result == AccountStatu.AuthorityChangd) |
| | | { |
| | | //如果登陆的账号的权限和上一次的不一样,则删除本地这个住宅全部的文件,从头再来 |
| | | string dirPath = Config.Instance.FullPath; |
| | | if (System.IO.Directory.Exists(dirPath) == true) |
| | | { |
| | | //同步数据的判断文件(以防万一删除整个文件夹失败的时候,这个文件被删的话,应该没什么大问题) |
| | | HdlFileLogic.Current.DeleteFile(HdlFileNameResourse.AutoDownLoadBackupCheckFile); |
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原 |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | //创建住宅文件夹 |
| | | Global.CreateHomeDirectory(Config.Instance.HomeId); |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |