黄学彪
2020-11-19 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -22,31 +22,19 @@
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
        public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return false;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                ReInitUserAccoutInfo(listNotShowError);
                return false;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null && setAgain == true)
            if (byteData == null)
            {
                if (setAgain == false)
                {
                    //不指定重发
                    //当前无法访问网络
                    ShowNotNetMsg(RequestName, listNotShowError);
                    return false;
                }
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -68,24 +56,10 @@
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
        /// </param>
        public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return "Error";
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                ReInitUserAccoutInfo(listNotShowError);
                return "Error";
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
@@ -94,7 +68,8 @@
            {
                if (setAgain == false)
                {
                    //不指定重发
                    //当前无法访问网络
                    ShowNotNetMsg(RequestName, listNotShowError);
                    return "Error";
                }
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -119,23 +94,10 @@
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
        /// </param>
        public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return null;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                ReInitUserAccoutInfo(listNotShowError);
                return null;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
@@ -144,7 +106,8 @@
            {
                if (setAgain == false)
                {
                    //不指定重发
                    //当前无法访问网络
                    ShowNotNetMsg(RequestName, listNotShowError);
                    return null;
                }
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -175,22 +138,9 @@
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
        public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return null;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                ReInitUserAccoutInfo(listNotShowError);
                return null;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
@@ -200,7 +150,8 @@
            {
                if (setAgain == false)
                {
                    //不指定重发
                    //当前无法访问网络
                    ShowNotNetMsg(RequestName, listNotShowError);
                    return null;
                }
                revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj);
@@ -255,7 +206,7 @@
                if (count == 3)
                {
                    //显示没有网络的Msg
                    ShowNotNetMsg(null);
                    ShowNotNetMsg(RequestName, null);
                    break;
                }
            }
@@ -377,13 +328,15 @@
        /// <summary>
        /// 显示没有网络的Msg
        /// </summary>
        private static void ShowNotNetMsg(List<string> listNotShowError)
        private static void ShowNotNetMsg(string RequestName, List<string> listNotShowError)
        {
            if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
            {
                //不检测
                return;
            }
            //HdlLogLogic.Current.WriteLog(-1, "当前无网络连接:" + RequestName);
            HdlThreadLogic.Current.RunMain(() =>
            {
                // 当前无网络连接,请确认网络
@@ -547,13 +500,18 @@
        #endregion
        #region ■ 刷新本地缓存_______________________
        /// <summary>
        /// 刷新本地所有缓存
        /// 刷新本地所有缓存(目前此方法只提供给恢复备份数据使用)
        /// </summary>
        public static void RefreshAllMemory()
        {
            //刷新住宅对象
            RefreshHomeObject();
            //根据模板文件,恢复数据
            TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile();
            //强制生成设备和网关文件
            TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce();
            //刷新本地网关文件
            HdlGatewayLogic.Current.ReFreshByLocal();
            //刷新本地设备
@@ -562,6 +520,12 @@
            HdlGatewayLogic.Current.SynchronizeDbGateway();
            //从本地重新加载全部的房间
            HdlRoomLogic.Current.RefreshAllRoomByLocation();
            //断开远程Mqtt连接,重新连接
            HdlThreadLogic.Current.RunThread(async () =>
            {
                HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
                await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
            }, ShowErrorMode.NO);
        }
        /// <summary>
@@ -569,77 +533,25 @@
        /// </summary>
        public static void RefreshHomeObject()
        {
            //备份的数据,有可能是主人自己上传的,如果管理员登陆时,他获取的备份数据有点特殊
            //比如下面这三个东西在主账号那里是不需要的
            bool isOthreShare = Config.Instance.Home.IsOthreShare;
            int accountType = Config.Instance.Home.AccountType;
            string mainMark = Config.Instance.Home.MainUserDistributedMark;
            double Longitude = Config.Instance.Home.Longitude;
            double Latitude = Config.Instance.Home.Latitude;
            //还原住宅对象
            Config.Instance.Home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id);
            Config.Instance.Home.IsOthreShare = isOthreShare;
            Config.Instance.Home.AccountType = accountType;
            Config.Instance.Home.MainUserDistributedMark = mainMark;
            Config.Instance.Home.Longitude = Longitude;
            Config.Instance.Home.Latitude = Latitude;
            Config.Instance.Home.Save(false);
        }
            var home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id);
        #endregion
        #region ■ 删除本地文件_______________________
        /// <summary>
        /// 删除本地所有文件
        /// </summary>
        /// <param name="all">true:全部删除(用于住宅删除) false:重要的文件不删除</param>
        public static void DeleteAllLocationFile(bool all = true)
        {
            string dPath = Config.Instance.FullPath;
            if (System.IO.Directory.Exists(dPath) == false)
            //刷新楼层
            Config.Instance.Home.FloorDics = home.FloorDics;
            Config.Instance.Home.CurrentFloorId = string.Empty;
            if (Config.Instance.Home.TemplateMode == -1)
            {
                return;
            }
            //然后获取全部的文件
            List<string> listFile = Global.FileListByHomeId();
            foreach (string file in listFile)
            {
                if (all == false && IsNotDeleteFile(file) == true)
                Config.Instance.Home.TemplateMode = home.TemplateMode;
                if (Config.Instance.Home.TemplateMode == -1)
                {
                    //这是不能删除的文件
                    continue;
                    //默认初始值
                    Config.Instance.Home.TemplateMode = 1;
                }
                //删除文件
                Global.DeleteFilebyHomeId(file);
            }
            //如果是把文件全部删除的话,那么文件夹也一起删除掉
            if (all == true)
            {
                //删除文件夹
                System.IO.Directory.Delete(dPath, true);
            }
        }
        /// <summary>
        /// 判断是不是不应该删除的文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool IsNotDeleteFile(string fileName)
        {
            if (fileName == "Config.json")
            {
                //不能删除Config文件
                return true;
            }
            else if (fileName.StartsWith("House_") == true)
            {
                //不能删除住宅文件
                return true;
            }
            return false;
            Config.Instance.Home.Save(false);
            //主页需要重新刷新
            UserView.UserPage.Instance.RefreshAllForm = true;
        }
        #endregion
@@ -660,13 +572,15 @@
                {
                    //设定一个时间
                    Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
                    Config.Instance.Save();
                    //清空当前住宅id
                    Config.Instance.HomeId = string.Empty;
                    Config.Instance.Save();
                    //收起左菜单
                    CommonPage.Instance.CloseLeftMenu();
                    //关闭全部弹窗
                    ShowMsgControl.CloseAllMsgDialog();
                    //关闭所有打开了的界面
                    CloseAllOpenForm();
                    CloseAllOpenForm(null, false);
                    //显示登陆画面
                    var formLogin = new Login.AccountLoginForm();
@@ -694,12 +608,12 @@
                //清空当前住宅id
                Config.Instance.HomeId = string.Empty;
                HdlGatewayLogic.Current.ClearAllRealGateway();
                HdlGatewayLogic.Current.ClearAllRealGatewayConection(false);
                //断开远程Mqtt连接
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                    await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
                }, ShowErrorMode.NO);
                HdlThreadLogic.Current.RunMain(() =>
@@ -707,7 +621,7 @@
                    //收起左菜单
                    CommonPage.Instance.CloseLeftMenu();
                    //关闭所有打开了的界面
                    CloseAllOpenForm();
                    CloseAllOpenForm(null, false);
                    //显示登陆画面
                    var formLogin = new Login.AccountLoginForm();
@@ -727,7 +641,8 @@
        /// 关闭所有打开了的界面
        /// </summary>
        /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param>
        public static void CloseAllOpenForm(string tagetFrom = null)
        /// <param name="refreshMainPage">当关闭的界面达到主页时,是否刷新主页</param>
        public static void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true)
        {
            while (UserView.HomePage.Instance.ChildrenCount > 0)
            {
@@ -750,6 +665,11 @@
                }
                else if (view is UserView.UserPage)
                {
                    //刷新主页
                    if (refreshMainPage == true)
                    {
                        UserView.UserPage.Instance.ReFreshControl();
                    }
                    return;
                }
                else
@@ -779,29 +699,6 @@
        #endregion
        #region ■ 拼接信息___________________________
        /// <summary>
        /// 拼接路径(全路径),以住宅ID的文件夹为起点,当没有指定参数时,则返回【住宅ID的文件夹】的全路径
        /// </summary>
        /// <param name="listNames">要拼接的路径</param>
        /// <returns></returns>
        public static string CombinePath(params object[] listNames)
        {
            string rootPath = Config.Instance.FullPath;
            if (listNames == null || listNames.Length == 0)
            {
                return rootPath;
            }
            foreach (var file in listNames)
            {
                if (file == null)
                {
                    continue;
                }
                rootPath = System.IO.Path.Combine(rootPath, file.ToString());
            }
            return rootPath;
        }
        /// <summary>
        /// 拼接网关回复超时的信息
@@ -871,7 +768,7 @@
        public static bool InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
        {
            //调用这个方法,都需要重新刷新主页
            UserView.UserPage.Instance.RefreshForm = true;
            UserView.UserPage.Instance.RefreshAllForm = true;
            //添加网络状态监听
            HdlWifiLogic.Current.StartListenNetWork();
@@ -893,11 +790,9 @@
            if (Common.Config.Instance.HomeId != UserCenterResourse.AccountOption.OldHomeStringId
                || Common.Config.Instance.Account != UserCenterResourse.AccountOption.OldAccountId)
            {
                //断开远程Mqtt连接
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }, ShowErrorMode.NO);
                //借用一下这个变量(检测能否广播到网关)
                UserCenterResourse.DicReceiveGatewayTest = new Dictionary<string, ZigBee.Device.ZbGateway>();
                UserCenterResourse.HideOption.CheckCanReceiveGateway = 1;
                //清空所有成员缓存
                ClearAllMemberMemory();
@@ -906,10 +801,13 @@
                var optionInfo = UserCenterResourse.AccountOption.Load();
                UserCenterResourse.AccountOption = optionInfo;
                //变更根用户图片目录路径
                UserCenterResourse.AccountOption.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
                UserCenterResourse.AccountOption.UserPictruePath = DirNameResourse.UserPictrueDirectory;
                //加载住宅配置信息
                UserCenterResourse.ResidenceOption = UserCenterResourse.ResidenceOption.Load();
                //预创建个人中心全部的文件夹
                HdlFileLogic.Current.CreatAllUserCenterDirectory();
                //初始化登陆账号的信息
                var hadNet = InitUserAccoutInfo(true);
@@ -920,10 +818,18 @@
                    HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
                    //读取隐匿配置
                    HdlBackupLogic.Current.LoadHideOption();
                    //调试:强制开启后台调试App功能
                    if (UserCenterResourse.HideOption.StartDebugApp == 1)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            var form = new HideOption.HideOptionMainForm();
                            form.AddForm();
                        });
                        ProgressBar.Close(true);
                        return false;
                    }
                }
                //预创建个人中心全部的文件夹
                CreatAllUserCenterDirectory();
                //关闭所有接收
                HdlGatewayReceiveLogic.Current.RemoveAllEvent();
@@ -957,8 +863,18 @@
                    HdlGatewayLogic.Current.SynchronizeDbGateway();
                }
                //断开远程Mqtt连接,重新连接
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
                    await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
                }, ShowErrorMode.NO);
                //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
                HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
                //加载模板缓存
                //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
                //0:已经同步过,不需要同步,这个时候需要提示备份
                if (result == 0 && ShowPrompted == true)
@@ -968,9 +884,25 @@
                }
                //显示引导界面
                ShowGuideForm(result);
                //关闭debug广播
                UserCenterResourse.HideOption.CheckCanReceiveGateway = 0;
                System.Threading.Thread.Sleep(30);
                if (hadNet == 1)
                {
                    //住宅切换时,检测网关连接情况
                    CheckGatewayConnection();
                }
                UserCenterResourse.DicReceiveGatewayTest = null;
            }
            //APP缓存加载完成
            UserCenterResourse.AccountOption.AppCanSignout = true;
            if (Shared.Phone.Device.Logic.Send.If_Exist == "1")
            {
                //以本地状态为主打开GPS服务
                Application.StartGPSLocationService();
            }
            return true;
        }
@@ -984,7 +916,7 @@
            //清空所有成员缓存
            ClearAllMemberMemory();
            //预创建个人中心全部的文件夹
            CreatAllUserCenterDirectory();
            HdlFileLogic.Current.CreatAllUserCenterDirectory();
            //关闭所有接收
            HdlGatewayReceiveLogic.Current.RemoveAllEvent();
            //初始化本地的网关信息
@@ -995,6 +927,8 @@
            HdlRoomLogic.Current.RefreshAllRoomByLocation();
            //刷新左边刷新房间视图列表
            HdlRoomLogic.Current.RefreshRoomListView();
            //加载模板缓存
            //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
        }
        /// <summary>
@@ -1018,6 +952,35 @@
            Common.Logic.LogicList.Clear();
            Common.Logic.LockLogicList.Clear();
            Common.Logic.SoneLogicList.Clear();
        }
        /// <summary>
        /// 住宅切换时,检测网关连接情况
        /// </summary>
        private static void CheckGatewayConnection()
        {
            try
            {
                bool canReceiveGw = false;
                foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values)
                {
                    if (gateway.HomeId == Config.Instance.Home.Id)
                    {
                        //能够搜索得到网关
                        canReceiveGw = true;
                        break;
                    }
                }
                UserCenterResourse.DicReceiveGatewayTest = null;
                //设置远程连接的初始值
                ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false;
                if (canReceiveGw == false)
                {
                    //如果是远程的话,追加等待时间
                    System.Threading.Thread.Sleep(1500);
                }
            }
            catch { }
        }
        #endregion
@@ -1050,7 +1013,7 @@
            //序列化对象
            var requestJson = JsonConvert.SerializeObject(pra);
            //访问接口
            byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson));
            byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson), "POST", 4);
            if (byteData == null)
            {
                return -1;
@@ -1089,29 +1052,27 @@
                userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMember);
            }
            if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo)
            //UserInfo.AuthorityNo==0代表本地还没有生成文件,这个时候不需要处理
            if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo
                && UserCenterResourse.UserInfo.AuthorityNo != 0)
            {
                //如果登陆的账号的权限和上一次的不一样,则删除本地这个住宅全部的文件,从头再来
                string dirPath = CombinePath();
                string dirPath = Config.Instance.FullPath;
                if (System.IO.Directory.Exists(dirPath) == true)
                {
                    try
                    {
                        //同步数据的判断文件(以防万一删除整个文件夹失败的时候,这个文件被删的话,应该没什么大问题)
                        string SynchronizeFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
                        string SynchronizeFile = DirNameResourse.AutoDownLoadBackupCheckFile;
                        //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
                        if (System.IO.File.Exists(SynchronizeFile) == true)
                        {
                            System.IO.File.Delete(SynchronizeFile);
                        }
                        //删除整个文件夹
                        System.IO.Directory.Delete(dirPath, true);
                        HdlFileLogic.Current.DeleteFile(SynchronizeFile);
                        HdlFileLogic.Current.DeleteDirectory(dirPath);
                    }
                    catch { }
                    //创建住宅文件夹
                    Global.CreateHomeDirectory(Config.Instance.HomeId);
                    //预创建个人中心全部的文件夹
                    CreatAllUserCenterDirectory();
                    HdlFileLogic.Current.CreatAllUserCenterDirectory();
                }
            }
            if (string.IsNullOrEmpty(userInfo.UserName) == true)
@@ -1125,7 +1086,7 @@
            if (UserCenterResourse.UserInfo.HeadImage != null)
            {
                //写入头像内容
                Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
                HdlFileLogic.Current.SaveByteToFile(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
            }
            UserCenterResourse.UserInfo.HeadImage = null;
            //手势密码
@@ -1134,6 +1095,8 @@
            //密码验证
            UserCenterResourse.AccountOption.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
            UserCenterResourse.UserInfo.StringPwd = null;
            //保存缓存
            UserCenterResourse.AccountOption.Save();
            //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
            var flage = InitAdminConnectMainInfo();
@@ -1149,8 +1112,7 @@
        /// <returns></returns>
        private static UserInformation GetUserInformationFromLocation()
        {
            string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            var value = LoadFileContent(fileName);
            var value = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.UserInfoFile);
            if (value == null)
            {
                return new UserInformation();
@@ -1163,25 +1125,10 @@
        /// 重新初始化登陆账号的信息(旨在对应那一瞬间,网络不好,导致误判的情况)
        /// </summary>
        /// <returns></returns>
        private static bool ReInitUserAccoutInfo(List<string> listNotShowError)
        public static bool ReInitUserAccoutInfo()
        {
            //重新初始化账号信息
            var result = InitUserAccoutInfo(false);
            //连接不了外网的时候
            if (result == -1)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
                {
                    //有这个标识时,不提示错误
                    return false;
                }
                Application.RunOnMainThread(() =>
                {
                    //当前无网络连接,请确认网络
                    var alert = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork));
                    alert.Show();
                });
            }
            if (result == 1)
            {
                //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
@@ -1199,9 +1146,8 @@
        /// </summary>
        private static void SaveUserInformationToLocation()
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            //写入内容
            SaveFileContent(fullName, UserCenterResourse.UserInfo);
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.UserInfoFile, UserCenterResourse.UserInfo);
            //搞一下主人的默认头像
            string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png");
@@ -1265,54 +1211,6 @@
        #endregion
        #region ■ 预创建个人中心全部的文件夹_________
        /// <summary>
        /// 预创建个人中心全部的文件夹
        /// </summary>
        public static void CreatAllUserCenterDirectory()
        {
            //本地缓存的根目录
            string LocalDirectory = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory);
            Global.CreateEmptyDirectory(LocalDirectory);
            //自动备份【文件夹】(编辑,追加)
            string directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupDirectory);
            Global.CreateEmptyDirectory(directory);
            //自动备份【文件夹】(删除)
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupdeleteDirectory);
            Global.CreateEmptyDirectory(directory);
            //下载备份的时候所使用的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadBackupTempDirectory);
            Global.CreateEmptyDirectory(directory);
            //保存安防记录的【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.SafeguardAlarmDirectory);
            Global.CreateEmptyDirectory(directory);
            //上传网关备份文件到云端的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.GatewayBackupDirectory);
            Global.CreateEmptyDirectory(directory);
            //下载分享文件的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
            Global.CreateEmptyDirectory(directory);
            //LOG出力【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
            Global.CreateEmptyDirectory(directory);
            //用户图片目录路径【文件夹】
            if (UserCenterResourse.AccountOption.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.AccountOption.UserPictruePath))
            {
                System.IO.Directory.CreateDirectory(UserCenterResourse.AccountOption.UserPictruePath);
            }
        }
        #endregion
        #region ■ 获取控制主人账号的Token____________
        /// <summary>
@@ -1339,7 +1237,7 @@
        /// <param name="result">同步结果 -1:异常   0:已经同步过,不需要同步  1:正常同步  2:没有自动备份数据</param>
        private static void ShowGuideForm(int result)
        {
            var checkFile = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, DirNameResourse.GuideFile);
            var checkFile = DirNameResourse.GuideFile;
            if (System.IO.File.Exists(checkFile) == true)
            {
                //不需要显示
@@ -1412,7 +1310,7 @@
        {
            try
            {
                if (strPsw == string.Empty)
                if (string.IsNullOrEmpty(strPsw) == true)
                {
                    return strPsw;
                }
@@ -1482,89 +1380,6 @@
        {
            var utcTime = Convert.ToDateTime(timeText);
            return TimeZoneInfo.ConvertTimeFromUtc(utcTime, TimeZoneInfo.Local);
        }
        #endregion
        #region ■ 文件保存和读取_____________________
        /// <summary>
        /// 文件保存(整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <param name="obj">需要序列化的东西</param>
        public static void SaveFileContent(string fullName, object obj)
        {
            var data = JsonConvert.SerializeObject(obj);
            SaveTexToFile(fullName, data);
        }
        /// <summary>
        /// 文件保存(整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <param name="obj">需要序列化的东西</param>
        public static void SaveTexToFile(string fullName, string textValue)
        {
            var byteData = Encoding.UTF8.GetBytes(textValue);
            //写入内容
            System.IO.FileStream fileStream = null;
            try
            {
                fileStream = new System.IO.FileStream(fullName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                fileStream.Write(byteData, 0, byteData.Length);
                fileStream.Flush();
            }
            catch { }
            finally
            {
                fileStream?.Close();
            }
        }
        /// <summary>
        /// 读取文件,不限制住宅(文件不存在返回null,整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <returns></returns>
        public static string LoadFileContent(string fullName)
        {
            //读取文件
            var varByte = ReadFileContent(fullName);
            if (varByte == null)
            {
                return null;
            }
            return Encoding.UTF8.GetString(varByte);
        }
        /// <summary>
        /// 读取文件,不限制住宅,文件不存在返回null
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <returns></returns>
        public static byte[] ReadFileContent(string fullName)
        {
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
            }
            System.IO.FileStream fileStream = null;
            try
            {
                fileStream = new System.IO.FileStream(fullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] array = new byte[fileStream.Length];
                fileStream.Read(array, 0, array.Length);
                return array;
            }
            catch
            {
                return null;
            }
            finally
            {
                fileStream?.Close();
            }
        }
        #endregion