| | |
| | | }
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | //检测是否存在错误信息
|
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError);
|
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | }
|
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | /// <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)
|
| | | {
|
| | |
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | if (UserCenterLogic.IsAccountLoginOut() == true)
|
| | | if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
|
| | | {
|
| | | //如果用户已经退出了登陆,则不处理
|
| | | 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);
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | |
| | | 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)
|
| | |
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// <param name="all">true:全部删除(用于住宅删除) false:重要的文件不删除</param>
|
| | | public static void DeleteAllLocationFile(bool all = true)
|
| | | {
|
| | | string dPath = UserCenterResourse.LocalRootPath;
|
| | | string dPath = Config.Instance.FullPath;
|
| | | if (System.IO.Directory.Exists(dPath) == false)
|
| | | {
|
| | | return;
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 各种正确检测_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含大写字母
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain upper was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainUpper(string value)
|
| | | {
|
| | | Regex reg = new Regex("[A-Z]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含小写字母
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainLower(string value)
|
| | | {
|
| | | Regex reg = new Regex("[a-z]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含数字
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainNum(string value)
|
| | | {
|
| | | Regex reg = new Regex("[0-9]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含符号
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainSymbol(string value)
|
| | | {
|
| | | Regex reg = new Regex("([^a-z0-9A-Z])+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测邮箱是否合法
|
| | | /// </summary>
|
| | | /// <param name="email"></param>
|
| | | /// <returns></returns>
|
| | | public static bool CheckEmail(string email)
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.EmailRegexStr);
|
| | | return reg.IsMatch(email);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测手机号是否合法
|
| | | /// </summary>
|
| | | /// <param name="phoneNumber">手机号</param>
|
| | | /// <param name="areaCode">地区代码</param>
|
| | | /// <returns></returns>
|
| | | public static bool CheckPhoneNumber(string phoneNumber, string areaCode)
|
| | | {
|
| | | //校验外国手机号
|
| | | if (areaCode != "86")
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.PhoneForForeignRegexStr);
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | |
|
| | | //校验国内手机号
|
| | | if (phoneNumber.Length > 11)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | else if (phoneNumber.Length == 11)
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.PhoneRegexStr);
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | | else
|
| | | {
|
| | | //正则表达式判断是否数字
|
| | | Regex reg = new Regex("^[0-9]*$");
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 重新登录___________________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="noticeDb">是否通知云端</param>
|
| | | public static void ReLoginAgain(string account = "", bool noticeDb = true)
|
| | | {
|
| | | UserCenterResourse.oldAccountId = string.Empty;
|
| | | UserCenterResourse.Option.OldAccountId = string.Empty;
|
| | | //关闭所有接收
|
| | | HdlDeviceAttributeLogic.Current.RemoveAllEvent();
|
| | | //清除升级列表
|
| | | FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
|
| | | FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
|
| | |
|
| | | new System.Threading.Thread(async () =>
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | //在APP的缓存还没有加载和读取完成之前,最好别让它下线
|
| | | while (UserCenterResourse.AppLoadMenmoryFinish == false)
|
| | | //检测APP是否能够退出
|
| | | while (UserCenterResourse.Option.AppCanSignout == false)
|
| | | {
|
| | | await Task.Delay(500);
|
| | | }
|
| | |
| | | try
|
| | | {
|
| | | ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
|
| | | ZigBee.Device.ZbGateway.RemoteMqttClient = null;
|
| | | }
|
| | | catch { }
|
| | |
|
| | |
| | | //通知云端,已经退出登陆
|
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //关闭所有打开了的界面
|
| | | CloseAllOpenForm();
|
| | |
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin);
|
| | | formLogin.Show(account);
|
| | | });
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public static int GetControlChidrenYaxis(int fatherCtrHeight, int ctrHeight, UViewAlignment alignment, int Space = 0)
|
| | | {
|
| | | if (Space == 0)
|
| | | {
|
| | | //获取行控件的间距
|
| | | if (fatherCtrHeight == ControlCommonResourse.ListViewRowHeight)
|
| | | {
|
| | | Space = ControlCommonResourse.ListViewRowSpace;
|
| | | }
|
| | | }
|
| | |
|
| | | if (Space < 0)
|
| | | {
|
| | | //不计算间距值
|
| | |
| | | /// <returns></returns>
|
| | | public static string CombinePath(params object[] listNames)
|
| | | {
|
| | | string rootPath = UserCenterResourse.LocalRootPath;
|
| | | string rootPath = Config.Instance.FullPath;
|
| | | if (listNames == null || listNames.Length == 0)
|
| | | {
|
| | | return rootPath;
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 检测网关共通错误状态码_____________
|
| | |
|
| | | /// <summary>
|
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para>
|
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary>
|
| | | /// <param name="resultData">网关返回的resultData,里面有【errorResponData】这个东西的那种对象</param>
|
| | | /// <returns></returns>
|
| | | public static string CheckCommonErrorCode(object resultData)
|
| | | {
|
| | | if (resultData == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Type myType = resultData.GetType();
|
| | | object errorObj = myType.InvokeMember("errorResponData", System.Reflection.BindingFlags.GetField, null, resultData, null);
|
| | | if (errorObj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Type type = errorObj.GetType();
|
| | | var code = type.InvokeMember("Error", System.Reflection.BindingFlags.GetField, null, errorObj, null);
|
| | | int errorCode = Convert.ToInt32(code);
|
| | |
|
| | | return CheckCommonErrorCode(errorCode);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para>
|
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary>
|
| | | /// <param name="errorCode">错误代码</param>
|
| | | /// <returns></returns>
|
| | | public static string CheckCommonErrorCode(int errorCode)
|
| | | {
|
| | | if (errorCode == 1)
|
| | | {
|
| | | //网关无法解析命令数据
|
| | | return Language.StringByID(R.MyInternationalizationString.uGatewayCannotResolveCommand);
|
| | | }
|
| | | else if (errorCode == 2)
|
| | | {
|
| | | //协调器正在升级或备份或恢复数据中
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uCoordinatorIsUpOrBackupOrRecovering);
|
| | | }
|
| | | else if (errorCode == 3)
|
| | | {
|
| | | //目标设备不存在
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uTargetDeviceIsNotExsit);
|
| | | }
|
| | | else if (errorCode == 4)
|
| | | {
|
| | | //出现未知错误,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain);
|
| | | }
|
| | | else if (errorCode == 5)
|
| | | {
|
| | | //数据传输错误,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDataTransmissionFailAndResetAgain);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 刷新个人中心的内存及线程___________
|
| | |
|
| | | /// <summary>
|
| | |
| | | public async static Task<bool> InitUserCenterMenmoryAndThread()
|
| | | {
|
| | | //APP缓存加载开始
|
| | | UserCenterResourse.AppLoadMenmoryFinish = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | |
|
| | | //强制指定不关闭进度条
|
| | | ProgressBar.SetCloseBarFlag(true);
|
| | |
|
| | | //只有在住宅ID不一样的时候才做这个操作
|
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.oldHomeStringId
|
| | | || Common.Config.Instance.Account != UserCenterResourse.oldAccountId)
|
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
|
| | | || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
|
| | | {
|
| | | //变更根目录路径
|
| | | UserCenterResourse.LocalRootPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, Config.Instance.Home.Id);
|
| | | UserCenterResourse.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
|
| | | //加载账号配置信息
|
| | | var optionInfo = UserCenterResourse.Option.Load();
|
| | | UserCenterResourse.Option = optionInfo;
|
| | | //变更根用户图片目录路径
|
| | | UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
|
| | |
|
| | | //初始化登陆账号的信息
|
| | | await InitUserAccoutInfo();
|
| | |
| | | //保存用户的登陆信息到本地
|
| | | SaveUserInformationToLocation();
|
| | |
|
| | | UserCenterResourse.oldHomeStringId = Common.Config.Instance.HomeId;
|
| | | UserCenterResourse.oldAccountId = Common.Config.Instance.Account;
|
| | | UserCenterResourse.Option.OldHomeStringId = Common.Config.Instance.HomeId;
|
| | | UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
|
| | |
|
| | | //同步数据(二次调用没关系)
|
| | | var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
|
| | |
| | | ProgressBar.SetAppendText(string.Empty);
|
| | |
|
| | | //0:已经同步过,不需要同步,这个时候需要提示备份
|
| | | if (result == 0)
|
| | | {
|
| | | //开启自动备份提示
|
| | | //HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | }
|
| | | //if (result == 0)
|
| | | //{
|
| | | // //开启自动备份提示
|
| | | // HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | //}
|
| | | }
|
| | |
|
| | | //恢复可关闭进度条
|
| | | ProgressBar.SetCloseBarFlag(false);
|
| | | //APP缓存加载完成
|
| | | UserCenterResourse.AppLoadMenmoryFinish = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | {
|
| | | //获取本地记录的用户信息
|
| | | UserCenterResourse.UserInfo = GetUserInformationFromLocation();
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
|
| | |
|
| | | //获取登录账号的信息
|
| | | var pra = new AccountInfoPra();
|
| | |
| | | }
|
| | |
|
| | | UserCenterResourse.UserInfo = userInfo;
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
|
| | |
|
| | | //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
|
| | | await InitAdminConnectMainInfo();
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | /// </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");
|
| | |
| | | {
|
| | | return;
|
| | | }
|
| | | string nowFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | string nowFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
|
| | | if (System.IO.File.Exists(nowFile) == true)
|
| | | {
|
| | | return;
|
| | |
| | | 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)) |
| | | if (UserCenterResourse.Option.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.Option.UserPictruePath)) |
| | | { |
| | | System.IO.Directory.CreateDirectory(UserCenterResourse.UserPictruePath); |
| | | System.IO.Directory.CreateDirectory(UserCenterResourse.Option.UserPictruePath); |
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 检测账号是否已经退出_______________
|
| | | #region ■ 加密和解密_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 检测账号是否已经退出 true:已经退出 false:没有退出
|
| | | /// 加密密码
|
| | | /// </summary>
|
| | | /// <param name="keys"></param>
|
| | | /// <param name="strPsw"></param>
|
| | | /// <returns></returns>
|
| | | public static bool IsAccountLoginOut()
|
| | | public static string EncryptPassword(string keys, string strPsw)
|
| | | {
|
| | | return Config.Instance.HomeId == string.Empty;
|
| | | if (strPsw == string.Empty)
|
| | | {
|
| | | return strPsw;
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | | byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | | StringBuilder ret = new StringBuilder();
|
| | | foreach (byte b in ms.ToArray())
|
| | | {
|
| | | ret.AppendFormat("{0:X2}", b);
|
| | | }
|
| | | return ret.ToString();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 解密密码
|
| | | /// </summary>
|
| | | /// <param name="strPsw"></param>
|
| | | /// <returns></returns>
|
| | | public static string DecryptPassword(string keys, string strPsw)
|
| | | {
|
| | | if (strPsw == string.Empty)
|
| | | {
|
| | | return strPsw;
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | |
|
| | | byte[] inputByteArray = new byte[strPsw.Length / 2];
|
| | | for (int x = 0; x < strPsw.Length / 2; x++)
|
| | | {
|
| | | int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
|
| | | inputByteArray[x] = (byte)i;
|
| | | }
|
| | |
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | |
|
| | | StringBuilder ret = new StringBuilder();
|
| | |
|
| | | 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
|