using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Drawing; using HDL_ON.DAL; using HDL_ON.DAL.Server; using Shared; namespace HDL_ON { [System.Serializable] public class UserInfo { /// /// 通用方法 /// private static UserInfo m_Current = null; /// /// 通用方法 /// public static UserInfo Current { get { //Dome模式 if (MainPage.NoLoginMode) { if (Language.CurrentLanguage == "Chinese") { m_Current = new UserInfo() { ID = "1234567890", userName = "体验账号", AccountString = "体验账号", userMobileInfo = "体验账号", userEmailInfo = "体验账号", language = "Chinese", areaCode = "86", headImagePagePath = "LoginIcon/2.png", }; } else if(Language.CurrentLanguage == "russian") { m_Current = new UserInfo() { ID = "1234567890", userName = "Пробный аккаунт", AccountString = "Пробный аккаунт", userMobileInfo = "Пробный аккаунт", userEmailInfo = "Пробный аккаунт", language = "russian", areaCode = "86", headImagePagePath = "LoginIcon/2.png", }; } else { m_Current = new UserInfo() { ID = "1234567890", userName = "Trial account", AccountString = "Trial account", userMobileInfo = "Trial account", userEmailInfo = "Trial account", language = "English", areaCode = "86", headImagePagePath = "LoginIcon/2.png", }; } return m_Current; } if (m_Current == null) { try { UserInfo temp = Newtonsoft.Json.JsonConvert.DeserializeObject( Encoding.UTF8.GetString(ReadUserInfo())); if (temp == null) { m_Current = new UserInfo() { }; Utlis.WriteLine("UserInfo null"); } else { m_Current = temp; Utlis.WriteLine("UserInfo Current"); } } catch { m_Current = new UserInfo() { }; Utlis.WriteLine("UserInfo null"); } } return m_Current; } } /// /// 清除缓存数据 /// public void ClearUserInfo() { m_Current = null; } #region 用户数据 /// /// 用户ID /// public string ID; /// /// 用户名称 /// public string userName = ""; /// /// 用户 /// public string AccountString = ""; /// /// 用户手机号码 /// public string userMobileInfo = ""; /// /// 用户邮箱信息 /// public string userEmailInfo = ""; /// /// 用户选择显示的语言 /// public string language = "Chinese"; /// /// 用户区域 /// public string areaCode = "86"; /// /// 用户头像图片 /// public string headImagePagePath = "LoginIcon/2.png"; ///// ///// 用户头像byte数据 ///// //public byte[] headImagePageBytes = null; /// /// 云端访问Token 有前缀 /// public string LoginTokenString; /// /// 云端访问Token 没有前缀 /// public string AccessToken; /// /// /// public string RefreshToken; /// /// UserType B端账号 C端账号 /// public string userType = "USER_C"; /// /// 用户住宅列表 /// public List regionList = new List(); /// /// 上一次登录时间 /// public DateTime LastTime = DateTime.MinValue; /// /// 是否是登录状态 /// public bool IsLogin { get { return (DateTime.Now - LastTime).TotalDays < 7; } } [Newtonsoft.Json.JsonIgnore] public DateTime LastTimeOpenDoor = DateTime.MinValue; public bool VerOpenDoorPw { get { return (DateTime.Now - LastTimeOpenDoor).TotalMinutes > 5; } } [Newtonsoft.Json.JsonIgnore] public string doorPasswordString; /// /// 记录自动化筛选的房间的条件 /// [Newtonsoft.Json.JsonIgnore] public Entity.Room logicselectedRoom = new Entity.Room { roomId = "6688",roomName = Language.StringByID(StringId.allAreas) }; /// /// 记录自动化筛选的功能的条件 /// [Newtonsoft.Json.JsonIgnore] public string logicselectedFunction = Language.StringByID(StringId.allFun); #endregion /// /// 保存用户数据 /// public void SaveUserInfo() { WirteUserinfo(Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); } /// /// 软件解锁界面 /// 1:启动时 /// 2:布防撤防时 /// 3:远程开锁时 /// public List appUnlockPage = new List(); /// /// 软件解锁方式 /// 1:数字密码 /// 2:手势密码 /// 3:指纹密码 /// 4:面容ID /// public List appUnlockType = new List(); /// /// 软件解锁密码 /// public string appUnlockPasswrod = ""; /// /// 解锁时间 /// public DateTime unlockTime = DateTime.MinValue; /// /// 根目录 /// static string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/"; /// /// 读取userInfo文件 /// /// static byte[] ReadUserInfo() { var fileName = "UserInfo_File"; FileStream fs = null; try { var temp = CreateUserFloder(OnAppConfig.Instance.LastLoginUserId); if (File.Exists(Path.Combine(temp, fileName))) { fs = new FileStream(Path.Combine(temp, fileName), FileMode.Open, FileAccess.Read); } else if (File.Exists(fileName)) { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); } else { return new byte[0]; } byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); return bytes; } catch { return new byte[0]; } finally { try { if (fs != null) { fs.Close(); } } catch { } } } /// /// 保存userInfo /// /// /// static bool WirteUserinfo(byte[] bytes) { var fileName = "UserInfo_File"; FileStream fs = null; try { var temp = CreateUserFloder(OnAppConfig.Instance.LastLoginUserId); fs = new FileStream(Path.Combine(temp, fileName), FileMode.Create, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Flush(); MainPage.Log("SaveFile:" + fileName); return true; } catch (Exception ex) { MainPage.Log("FileUtiles Code 113:" + ex.ToString()); return false; } finally { try { if (fs != null) { fs.Close(); } } catch (Exception ex) { MainPage.Log("FileUtils Code 121 :" + ex.ToString()); } } } /// /// 创建一个住宅的账号文件夹 /// public static string CreateUserFloder(string userId) { var path = Path.Combine(RootPath, userId); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return path + "/"; } /// /// 推送消息记录 /// public JPushMessageInfo pushMessageInfo = new JPushMessageInfo(); /// /// 是否已经加载呼叫弹窗 /// public bool alreadyShowCallInDialog = false; [Newtonsoft.Json.JsonIgnore] public bool inVideo = false; [Newtonsoft.Json.JsonIgnore] public DateTime inCall = DateTime.MinValue; } }