黄学彪
2020-07-06 f23ad1b3f9f6193f35f72104d690b21dc67d5c1f
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -2,8 +2,6 @@
using Shared.Common;
using Newtonsoft.Json;
using Shared.Common.ResponseEntity;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
@@ -23,30 +21,35 @@
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【false】</pra>
        /// </param>
        public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        /// <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)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return false;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                await ReInitUserAccoutInfo();
                ReInitUserAccoutInfo(listNotShowError);
                return false;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            var byteData = GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null && setAgain == true)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                if (setAgain == false)
                {
                    //不指定重发
                    return false;
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return false;
@@ -64,37 +67,47 @@
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【Success】</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【ErrorEx】</pra>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        /// </param>
        public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return "Error";
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                await ReInitUserAccoutInfo();
                ReInitUserAccoutInfo(listNotShowError);
                return "Error";
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            var byteData = GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                if (setAgain == false)
                {
                    return "ErrorEx";
                    //不指定重发
                    return "Error";
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return "Error";
                }
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            if (revertObj == null)
            {
                return "Error";
            }
            return revertObj.StateCode;
        }
@@ -105,30 +118,36 @@
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回空字符串</pra>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
        /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
        /// </param>
        public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return null;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                await ReInitUserAccoutInfo();
                ReInitUserAccoutInfo(listNotShowError);
                return null;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            var byteData = GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                if (setAgain == false)
                {
                    return string.Empty;
                    //不指定重发
                    return null;
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return null;
@@ -143,7 +162,7 @@
            }
            if (revertObj == null || revertObj.ResponseData == null)
            {
                return string.Empty;
                return null;
            }
            return revertObj.ResponseData.ToString();
        }
@@ -155,32 +174,36 @@
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回null</pra>
        /// </param>
        public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        /// <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)
        {
            if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
            {
                //当前无法访问网络(当需要重新发送时,跳过这个判断)
                ShowNotNetMsg(listNotShowError);
                return null;
            }
            //检测是否已经完成账号信息初始化
            if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
            {
                //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
                await ReInitUserAccoutInfo();
                ReInitUserAccoutInfo(listNotShowError);
                return null;
            }
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var revertObj = await GettByteResponsePack(RequestName, connectMode, obj);
            var revertObj = GettByteResponsePack(RequestName, connectMode, obj);
            if (revertObj == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                if (setAgain == false)
                {
                    //不指定重发
                    return null;
                }
                //重新发送
                revertObj = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (revertObj == null)
                {
                    return null;
@@ -212,7 +235,7 @@
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <returns></returns>
        private static async Task<byte[]> ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
        private static byte[] ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
@@ -221,9 +244,9 @@
            int count = 0;
            while (true)
            {
                await Task.Delay(1000);
                System.Threading.Thread.Sleep(1000);
                //调用接口
                responsePack = await GettByteResponsePack(RequestName, connectMode, obj);
                responsePack = GettByteResponsePack(RequestName, connectMode, obj);
                if (responsePack != null)
                {
                    break;
@@ -231,13 +254,8 @@
                count++;
                if (count == 3)
                {
                    Application.RunOnMainThread(() =>
                    {
                        //网络不稳定,请稍后再试
                        string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
                        var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                        control.Show();
                    });
                    //显示没有网络的Msg
                    ShowNotNetMsg(null);
                    break;
                }
            }
@@ -251,7 +269,7 @@
        /// <param name="RequestName">访问地址</param>
        /// <param name="connectMode">接口的连接模式</param>
        /// <param name="obj">一个类</param>
        private static async Task<byte[]> GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
        private static byte[] GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
        {
            try
            {
@@ -262,12 +280,12 @@
                if (connectMode == HttpConnectMode.Normal)
                {
                    //普通访问
                    result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
                    result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
                }
                else if (connectMode == HttpConnectMode.Admin)
                {
                    //以管理员的身份访问,自身是成员
                    result = await CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
                    result = CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
                }
                return result;
            }
@@ -295,13 +313,13 @@
            }
            if (revertObj == null)
            {
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //网络不稳定,请稍后再试
                    string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
                    var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                    control.Show();
                });
                }, ShowErrorMode.NO);
                return false;
            }
@@ -312,7 +330,7 @@
                    //不显示错误,然后返回true
                    return true;
                }
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
                    {
@@ -328,10 +346,10 @@
                        //无效登录Token
                        if (revertObj.StateCode == "NoLogin")
                        {
                            UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
                            ReLoginAgain(Config.Instance.Account, false);
                        }
                    }
                });
                }, ShowErrorMode.NO);
                return false;
            }
@@ -356,6 +374,25 @@
            return HttpConnectMode.Normal;
        }
        /// <summary>
        /// 显示没有网络的Msg
        /// </summary>
        private static void ShowNotNetMsg(List<string> listNotShowError)
        {
            if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
            {
                //不检测
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                // 当前无网络连接,请确认网络
                string msg = Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork);
                var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                control.Show();
            }, ShowErrorMode.NO);
        }
        #endregion
        #region ■ 添加界面相关_______________________
@@ -368,17 +405,17 @@
        public static bool CheckCanAddForm(CommonFormBase form)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
            string formId = GetFormID(form);
            //二重追加不可
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
            if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
            {
                return true;
            }
            //暂时这样弄看看,如果重复,则关闭掉原来的界面
            var formTemp = UserCenterResourse.DicActionForm[formName];
            var formTemp = UserCenterResourse.DicActionForm[formId];
            formTemp.CloseForm();
            UserCenterResourse.DicActionForm.Remove(formName);
            UserCenterResourse.DicActionForm.Remove(formId);
            return true;
        }
@@ -390,14 +427,14 @@
        public static void AddActionForm(CommonFormBase form)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
            string formId = GetFormID(form);
            //二重追加不可
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
            if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
            {
                form.FormID = formName;
                form.FormID = formId;
                //内存添加
                UserCenterResourse.DicActionForm[formName] = form;
                UserCenterResourse.DicActionForm[formId] = form;
                //添加画面时,它自身就是激活的界面
                UserCenterResourse.NowActionFormID = form.FormID;
@@ -408,71 +445,43 @@
        /// <summary>
        /// 从列表中移除画面
        /// </summary>
        /// <param name="form">Form</param>
        public static void RemoveActionForm(CommonFormBase form)
        /// <param name="i_closeForm">关闭的界面</param>
        public static void RemoveActionForm(CommonFormBase i_closeForm)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
            //获取画面ID
            string formId = GetFormID(i_closeForm);
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == true)
            if (UserCenterResourse.DicActionForm.ContainsKey(formId) == true)
            {
                //刷新当前正在操作的画面ID
                if (UserCenterResourse.NowActionFormID == UserCenterResourse.DicActionForm[formName].FormID)
                {
                    //向前推一位即为下一个激活的界面
                    int index = UserCenterResourse.listActionFormId.IndexOf(UserCenterResourse.NowActionFormID) - 1;
                    //初始值
                    UserCenterResourse.NowActionFormID = string.Empty;
                    if (index >= 0)
                    {
                        var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
                        if (actionForm != null && actionForm is CommonFormBase)
                        {
                            string formId = ((CommonFormBase)actionForm).FormID;
                            //对应徐梅继承了底层,但是不初始化数据的问题
                            if (UserCenterResourse.listActionFormId.Contains(formId) == true)
                            {
                                //调用界面重新激活的函数
                                CallFormActionAgainEvent(form, index);
                            }
                        }
                        else if (actionForm != null && actionForm is UserView.UserPage)
                        {
                            //这里它已经退到主页了
                            if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == true//个人中心
                                || UserCenterResourse.listActionFormId.Contains("HomeMainPageForm") == true)//
                            {
                                //调用界面重新激活的函数
                                CallFormActionAgainEvent(form, index);
                            }
                        }
                    }
                }
                //移除ID
                UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
                UserCenterResourse.listActionFormId.Remove(formId);
                //移除画面
                UserCenterResourse.DicActionForm.Remove(formName);
            }
        }
                UserCenterResourse.DicActionForm.Remove(formId);
                //清空
                UserCenterResourse.NowActionFormID = string.Empty;
        /// <summary>
        /// 调用界面重新激活的函数
        /// </summary>
        /// <param name="form">关闭的界面对象</param>
        /// <param name="index">当前需要重新激活界面的索引</param>
        private static void CallFormActionAgainEvent(CommonFormBase form, int index)
        {
            //设置当前激活的画面ID
            UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
            //追加条件一:关闭的界面为EditorCommonForm的时候才处理
            if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
            {
                try
                var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
                if (actionForm == null)
                {
                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID] as EditorCommonForm;
                    //点击很快时,这个东西会是null,但是DicActionForm里面不是null,不知道为什么
                    if (Myform != null)
                    return;
                }
                //如果关闭的界面是DialogCommonForm类型,则不需要触发激活函数
                if (i_closeForm is DialogCommonForm)
                {
                    if (actionForm is EditorCommonForm)
                    {
                        UserCenterResourse.NowActionFormID = GetFormID((EditorCommonForm)actionForm);
                    }
                    return;
                }
                //关闭的界面为EditorCommonForm的时候
                else if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm))
                {
                    //接下来激活的界面id
                    UserCenterResourse.NowActionFormID = GetFormID((CommonFormBase)actionForm);
                    try
                    {
                        var Myform = actionForm as EditorCommonForm;
                        //重置左滑使能
                        Myform.ScrollEnabled = Myform.ScrollEnabled;
                        //触发界面再次激活的事件
@@ -483,25 +492,34 @@
                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                        }
                    }
                    catch (Exception ex)
                    {
                        //Log出力
                        HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + UserCenterResourse.NowActionFormID);
                    }
                }
                catch (Exception ex)
                else if (actionForm is UserView.UserPage)
                {
                    //出现未知错误,数据丢失
                    //var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                    //alert.Show();
                    //Log出力
                    HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + UserCenterResourse.NowActionFormID);
                    //清空
                    UserCenterResourse.NowActionFormID = string.Empty;
                    //这里它已经退到主页了
                    var nowForm = UserView.UserPage.Instance.GetNowActionForm();
                    nowForm?.FormActionAgainEvent();
                }
                else
                {
                    //清空
                    UserCenterResourse.NowActionFormID = string.Empty;
                }
            }
        }
        /// <summary>
        /// 获取画面英文名字
        /// 获取画面ID
        /// </summary>
        /// <returns>The form name.</returns>
        /// <param name="form">Form.</param>
        public static string GetFormName(CommonFormBase form)
        private static string GetFormID(CommonFormBase form)
        {
            if (form.FormID != string.Empty)
            {
@@ -559,7 +577,7 @@
            double Longitude = Config.Instance.Home.Longitude;
            double Latitude = Config.Instance.Home.Latitude;
            //还原住宅对象
            Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
            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;
@@ -642,6 +660,8 @@
                {
                    //设定一个时间
                    Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
                    //清空当前住宅id
                    Config.Instance.HomeId = string.Empty;
                    Config.Instance.Save();
                    //收起左菜单
                    CommonPage.Instance.CloseLeftMenu();
@@ -661,26 +681,26 @@
            //清除升级列表
            FirmwareUpdateResourse.dicUpdateList.Clear();
            HdlThreadLogic.Current.RunThread(async () =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //检测APP是否能够退出
                while (UserCenterResourse.AccountOption.AppCanSignout == false)
                {
                    await Task.Delay(500);
                    System.Threading.Thread.Sleep(500);
                }
                //设定一个时间
                Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
                Config.Instance.Save();
                //清空当前住宅id
                Shared.Common.Config.Instance.HomeId = string.Empty;
                Config.Instance.HomeId = string.Empty;
                HdlGatewayLogic.Current.ClearAllRealGateway();
                try
                //断开远程Mqtt连接
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    //断开远程Mqtt连接
                    ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }
                catch { }
                    await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }, ShowErrorMode.NO);
                HdlThreadLogic.Current.RunMain(() =>
                {
@@ -698,7 +718,7 @@
                if (noticeDb == true)
                {
                    //通知云端,已经退出登陆
                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
                    var result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
                }
            });
        }
@@ -801,13 +821,24 @@
            string errorMsgBase = strResultData;
            if (errorMsgBase == null)
            {
                Type myType = resultData.GetType();
                object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null);
                if (errorObj == null)
                if (resultData is ReceiptGatewayResult)
                {
                    return errorMsg;
                    errorMsgBase = string.Empty;
                    if (((ReceiptGatewayResult)resultData).ErrorMsgDiv == 0)
                    {
                        errorMsgBase = "回复超时";
                    }
                }
                errorMsgBase = errorObj.ToString();
                else
                {
                    Type myType = resultData.GetType();
                    object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null);
                    if (errorObj == null)
                    {
                        return errorMsg;
                    }
                    errorMsgBase = errorObj.ToString();
                }
            }
            if (errorMsgBase.Contains("回复超时") == false)
@@ -837,10 +868,13 @@
        /// </summary>
        /// <param name="ShowPrompted">新追加变量:是否显示提示自动备份的界面</param>
        /// <returns></returns>
        public async static Task<bool> InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
        public static bool InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
        {
            //调用这个方法,都需要重新刷新主页
            UserView.UserPage.Instance.RefreshForm = true;
            //添加网络状态监听
            HdlWifiLogic.Current.StartListenNetWork();
            //如果是虚拟住宅
            if (Config.Instance.Home.IsVirtually == true)
@@ -859,12 +893,11 @@
            if (Common.Config.Instance.HomeId != UserCenterResourse.AccountOption.OldHomeStringId
                || Common.Config.Instance.Account != UserCenterResourse.AccountOption.OldAccountId)
            {
                try
                //断开远程Mqtt连接
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    //断开远程Mqtt连接
                    await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }
                catch { }
                }, ShowErrorMode.NO);
                //清空所有成员缓存
                ClearAllMemberMemory();
@@ -879,18 +912,15 @@
                UserCenterResourse.ResidenceOption = UserCenterResourse.ResidenceOption.Load();
                //初始化登陆账号的信息
                var hadNet = await InitUserAccoutInfo(true);
                var hadNet = InitUserAccoutInfo(true);
                //如果有网络的话
                if (hadNet == true)
                if (hadNet == 1)
                {
                    //重新发送命令去绑定断网情况下备份的网关
                    HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
                    //读取隐匿配置
                    await HdlBackupLogic.Current.LoadHideOption();
                    HdlBackupLogic.Current.LoadHideOption();
                }
                //初始化缓存成员的信息
                InitLocalMemberListInfo();
                //预创建个人中心全部的文件夹
                CreatAllUserCenterDirectory();
@@ -908,20 +938,20 @@
                //同步数据(二次调用没关系)
                int result = -1;
                if (hadNet == true)
                if (hadNet == 1)
                {
                    result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
                    result = HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
                }
                //初始化本地的网关信息
                HdlGatewayLogic.Current.ReFreshByLocal();
                //初始化本地的设备信息
                Common.LocalDevice.Current.ReFreshByLocal();
                LocalDevice.Current.ReFreshByLocal();
                //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
                HdlRoomLogic.Current.RefreshAllRoomByLocation();
                if (hadNet == true)
                if (hadNet == 1)
                {
                    //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
                    HdlGatewayLogic.Current.SynchronizeDbGateway();
@@ -984,11 +1014,6 @@
                }
            });
            //当前主页,场景和功能所选择的分支 1:场景 2:功能
            UserCenterResourse.ResidenceOption.HomeMainPageSwitchIndex = 1;
            //当前分类,场景和功能所选择的分支 0:场景 1:功能 2:自动化
            UserCenterResourse.ResidenceOption.CategoryPageSwitchIndex = 0;
            //切换住宅清除之前逻辑缓存数据;
            Common.Logic.LogicList.Clear();
            Common.Logic.LockLogicList.Clear();
@@ -1000,11 +1025,11 @@
        #region ■ 初始化登陆账号的信息_______________
        /// <summary>
        /// 初始化登陆账号的信息
        /// 初始化登陆账号的信息 -1:无网 1:正常 2:其他错误
        /// </summary>
        /// <param name="reLoad">是否从新从本地加载(重新初始化登陆账号的信息,不需要重新加载)</param>
        /// <returns></returns>
        private async static Task<bool> InitUserAccoutInfo(bool reLoad)
        private static int InitUserAccoutInfo(bool reLoad)
        {
            //初始化个人信息的标识
            UserCenterResourse.UserInfo.InitUserInfoSuccess = false;
@@ -1014,22 +1039,27 @@
                UserCenterResourse.UserInfo = GetUserInformationFromLocation();
                UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png");
            }
            if (HdlWifiLogic.Current.CanAccessHttp == false)
            {
                //无法连接外网
                return -1;
            }
            //获取登录账号的信息
            var pra = new AccountInfoPra();
            //序列化对象
            var requestJson = JsonConvert.SerializeObject(pra);
            //访问接口
            byte[] byteData = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson));
            byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson));
            if (byteData == null)
            {
                return false;
                return -1;
            }
            //检测错误
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            if (revertObj.StateCode.ToUpper() != "SUCCESS")
            {
                return false;
                return 2;
            }
            var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(revertObj.ResponseData.ToString());
@@ -1106,9 +1136,9 @@
            UserCenterResourse.UserInfo.StringPwd = null;
            //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
            bool flage = await InitAdminConnectMainInfo();
            var flage = InitAdminConnectMainInfo();
            //初始化个人信息的标识
            UserCenterResourse.UserInfo.InitUserInfoSuccess = flage;
            UserCenterResourse.UserInfo.InitUserInfoSuccess = flage == 1;
            return flage;
        }
@@ -1133,20 +1163,35 @@
        /// 重新初始化登陆账号的信息(旨在对应那一瞬间,网络不好,导致误判的情况)
        /// </summary>
        /// <returns></returns>
        private async static Task<bool> ReInitUserAccoutInfo()
        private static bool ReInitUserAccoutInfo(List<string> listNotShowError)
        {
            //重新初始化账号信息
            var result = await InitUserAccoutInfo(false);
            if (result == false)
            var result = InitUserAccoutInfo(false);
            //连接不了外网的时候
            if (result == -1)
            {
                return result;
                if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
                {
                    //有这个标识时,不提示错误
                    return false;
                }
                Application.RunOnMainThread(() =>
                {
                    //当前无网络连接,请确认网络
                    var alert = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork));
                    alert.Show();
                });
            }
            //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
            HdlGatewayLogic.Current.SynchronizeDbGateway();
            //初始化个人信息的标识
            UserCenterResourse.UserInfo.InitUserInfoSuccess = true;
            if (result == 1)
            {
                //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
                HdlGatewayLogic.Current.SynchronizeDbGateway();
                //初始化个人信息的标识
                UserCenterResourse.UserInfo.InitUserInfoSuccess = true;
            return true;
                return true;
            }
            return false;
        }
        /// <summary>
@@ -1177,15 +1222,15 @@
        #region ■ 初始化管理员权限远程连接___________
        /// <summary>
        /// 初始化管理员权限远程连接主人的信息
        /// 初始化管理员权限远程连接主人的信息 -1:无网 1:正常 2:其他错误
        /// </summary>
        /// <returns></returns>
        private static async Task<bool> InitAdminConnectMainInfo()
        private static int InitAdminConnectMainInfo()
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //时代变了,这里管理员和成员都能调用
                return true;
                return 1;
            }
            var pra = new
            {
@@ -1198,16 +1243,16 @@
            //序列化对象
            var requestJson = JsonConvert.SerializeObject(pra);
            //访问接口
            byte[] byteData = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson));
            byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson));
            if (byteData == null)
            {
                return false;
                return -1;
            }
            //检测错误
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            if (revertObj.StateCode.ToUpper() != "SUCCESS")
            {
                return false;
                return 2;
            }
            //分享链接
@@ -1215,40 +1260,7 @@
            Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
            Config.Instance.AdminRequestToken = info.RequestToken;
            return true;
        }
        #endregion
        #region ■ 初始化缓存成员的信息_______________
        /// <summary>
        /// 初始化缓存成员的信息
        /// </summary>
        private static void InitLocalMemberListInfo()
        {
            //先清空
            UserCenterResourse.ListMemberInfo.Clear();
            string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
            if (System.IO.File.Exists(fileName) == false)
            {
                return;
            }
            var varByte = Shared.IO.FileUtils.ReadFile(fileName);
            UserCenterResourse.ListMemberInfo = JsonConvert.DeserializeObject<List<MemberInfoRes>>(System.Text.Encoding.UTF8.GetString(varByte));
        }
        /// <summary>
        /// 保存缓存成员的信息
        /// </summary>
        public static void SaveLocalMemberListInfo()
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(UserCenterResourse.ListMemberInfo);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
            return 1;
        }
        #endregion
@@ -1477,14 +1489,24 @@
        #region ■ 文件保存和读取_____________________
        /// <summary>
        /// 文件保存,仅限当前住宅(整天忘记,所以建一个函数来玩玩)
        /// 文件保存(整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <param name="obj">需要序列化的东西</param>
        public static void SaveFileContent(string fullName, object obj)
        {
            var data = JsonConvert.SerializeObject(obj);
            var byteData = Encoding.UTF8.GetBytes(data);
            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