gxc
2019-10-29 ed2f4a97aa48cdb4a013d2a389877f52eb3eccdf
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -47,7 +47,7 @@
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            //检测是否存在错误信息
            return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError);
            return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
        }
        /// <summary>
@@ -114,7 +114,7 @@
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            //检测错误
            bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError);
            bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
            if (notError == false)
            {
                return null;
@@ -165,7 +165,7 @@
                    var data = JsonConvert.DeserializeObject<ResponsePack>(data2);
                    if (data != null && string.IsNullOrEmpty(data.StateCode) == false)
                    {
                        bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError);
                        bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError, obj);
                        if (notError == false)
                        {
                            return null;
@@ -256,7 +256,8 @@
        /// <param name="revertObj">从接口接收到的数据</param>
        /// <param name="RequestName">请求接口</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别)</param>
        public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null)
        /// <param name="pra">请求的参数</param>
        public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null, object pra = null)
        {
            if (revertObj == null)
            {
@@ -284,14 +285,17 @@
                        //如果用户已经退出了登陆,则不处理
                        return;
                    }
                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode);
                    var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                    control.Show();
                    //无效登录Token
                    if (revertObj.StateCode == "NoLogin")
                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
                    if (msg != null)
                    {
                        UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
                        var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                        control.Show();
                        //无效登录Token
                        if (revertObj.StateCode == "NoLogin")
                        {
                            UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
                        }
                    }
                });
@@ -395,8 +399,26 @@
                            UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                            if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                            {
                                //触发界面再次激活的事件
                                UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID]?.FormActionAgainEvent();
                                try
                                {
                                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                    //触发界面再次激活的事件
                                    int value = Myform.FormActionAgainEvent();
                                    if (value == 1)
                                    {
                                        //Log出力
                                        HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    //出现未知错误,数据丢失
                                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
                                    alert.Show();
                                    //Log出力
                                    HdlLogLogic.Current.WriteLog(ex);
                                }
                            }
                        }
                        else if (actionForm != null && actionForm is UserView.UserPage)
@@ -408,8 +430,26 @@
                                UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                                if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                                {
                                    //触发界面再次激活的事件
                                    UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID]?.FormActionAgainEvent();
                                    try
                                    {
                                        var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                        //触发界面再次激活的事件
                                        int value = Myform.FormActionAgainEvent();
                                        if (value == 1)
                                        {
                                            //Log出力
                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        //出现未知错误,数据丢失
                                        var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
                                        alert.Show();
                                        //Log出力
                                        HdlLogLogic.Current.WriteLog(ex);
                                    }
                                }
                            }
                        }
@@ -563,7 +603,7 @@
            FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
            FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //检测APP是否能够退出
                while (UserCenterResourse.AppCanSignout == false)
@@ -589,7 +629,7 @@
                    //通知云端,已经退出登陆
                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
                }
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //关闭所有打开了的界面
                    CloseAllOpenForm();
@@ -599,8 +639,7 @@
                    Shared.Common.CommonPage.Instance.AddChidren(formLogin);
                    formLogin.Show(account);
                });
            })
            { IsBackground = true }.Start();
            });
        }
        /// <summary>
@@ -926,12 +965,12 @@
        private static UserInformation GetUserInformationFromLocation()
        {
            string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            if (System.IO.File.Exists(fileName) == false)
            var value = LoadFileContent(fileName);
            if (value == null)
            {
                return new UserInformation();
            }
            var varByte = Shared.IO.FileUtils.ReadFile(fileName);
            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(System.Text.Encoding.UTF8.GetString(varByte));
            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
            return info;
        }
@@ -940,12 +979,9 @@
        /// </summary>
        private static void SaveUserInformationToLocation()
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(UserCenterResourse.UserInfo);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
            SaveFileContent(fullName, UserCenterResourse.UserInfo);
            //搞一下主人的默认头像
            string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png");
@@ -1114,6 +1150,10 @@
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
            Global.CreateEmptyDirectory(directory);
            //LOG出力【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
            Global.CreateEmptyDirectory(directory);
            //用户图片目录路径【文件夹】
            if (!System.IO.Directory.Exists(UserCenterResourse.UserPictruePath))
            {
@@ -1242,5 +1282,37 @@
            return System.Text.Encoding.Default.GetString(ms.ToArray());
        }
        #endregion
        #region ■ 文件保存和读取_____________________
        /// <summary>
        /// 文件保存(整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <param name="obj">需要序列化的东西</param>
        public static void SaveFileContent(string fullName, object obj)
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
        }
        /// <summary>
        /// 读取文件(文件不存在返回null,整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <returns></returns>
        public static string LoadFileContent(string fullName)
        {
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
            }
            var varByte = Shared.IO.FileUtils.ReadFile(fullName);
            return System.Text.Encoding.UTF8.GetString(varByte);
        }
        #endregion
    }
}