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
|
{
|
/// <summary>
|
/// 通用方法
|
/// </summary>
|
private static UserInfo m_Current = null;
|
/// <summary>
|
/// 通用方法
|
/// </summary>
|
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
|
{
|
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<UserInfo>(
|
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;
|
}
|
}
|
/// <summary>
|
/// 清除缓存数据
|
/// </summary>
|
public void ClearUserInfo()
|
{
|
m_Current = null;
|
}
|
|
|
#region 用户数据
|
/// <summary>
|
/// 用户ID
|
/// </summary>
|
public string ID;
|
/// <summary>
|
/// 用户名称
|
/// </summary>
|
public string userName = "";
|
/// <summary>
|
/// 用户
|
/// </summary>
|
public string AccountString = "";
|
/// <summary>
|
/// 用户手机号码
|
/// </summary>
|
public string userMobileInfo = "";
|
/// <summary>
|
/// 用户邮箱信息
|
/// </summary>
|
public string userEmailInfo = "";
|
/// <summary>
|
/// 用户选择显示的语言
|
/// </summary>
|
public string language = "Chinese";
|
/// <summary>
|
/// 用户区域
|
/// </summary>
|
public string areaCode = "86";
|
/// <summary>
|
/// 用户头像图片
|
/// </summary>
|
public string headImagePagePath = "LoginIcon/2.png";
|
///// <summary>
|
///// 用户头像byte数据
|
///// </summary>
|
//public byte[] headImagePageBytes = null;
|
/// <summary>
|
///
|
/// </summary>
|
public string LoginTokenString;
|
/// <summary>
|
///
|
/// </summary>
|
public string RefreshToken;
|
/// <summary>
|
/// UserType B端账号 C端账号
|
/// </summary>
|
public string userType = "USER_C";
|
/// <summary>
|
/// 用户住宅列表
|
/// </summary>
|
public List<RegionInfoRes> regionList = new List<RegionInfoRes>();
|
/// <summary>
|
/// 上一次登录时间
|
/// </summary>
|
public DateTime LastTime = DateTime.MinValue;
|
/// <summary>
|
/// 是否是登录状态
|
/// </summary>
|
public bool IsLogin
|
{
|
get
|
{
|
return (DateTime.Now - LastTime).TotalDays < 7;
|
}
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 保存用户数据
|
/// </summary>
|
public void SaveUserInfo()
|
{
|
WirteUserinfo(Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
|
}
|
|
/// <summary>
|
/// 软件解锁界面
|
/// 1:启动时
|
/// 2:布防撤防时
|
/// 3:远程开锁时
|
/// </summary>
|
public List<string> appUnlockPage = new List<string>();
|
/// <summary>
|
/// 软件解锁方式
|
/// 1:数字密码
|
/// 2:手势密码
|
/// 3:指纹密码
|
/// 4:面容ID
|
/// </summary>
|
public List<string> appUnlockType = new List<string>();
|
/// <summary>
|
/// 软件解锁密码
|
/// </summary>
|
public string appUnlockPasswrod = "";
|
/// <summary>
|
/// 解锁时间
|
/// </summary>
|
public DateTime unlockTime = DateTime.MinValue;
|
|
|
/// <summary>
|
/// 根目录
|
/// </summary>
|
static string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/";
|
/// <summary>
|
/// 读取userInfo文件
|
/// </summary>
|
/// <returns></returns>
|
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
|
{
|
|
}
|
}
|
|
}
|
/// <summary>
|
/// 保存userInfo
|
/// </summary>
|
/// <param name="bytes"></param>
|
/// <returns></returns>
|
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());
|
}
|
}
|
}
|
/// <summary>
|
/// 创建一个住宅的账号文件夹
|
/// </summary>
|
public static string CreateUserFloder(string userId)
|
{
|
var path = Path.Combine(RootPath, userId);
|
if (!Directory.Exists(path))
|
{
|
Directory.CreateDirectory(path);
|
}
|
return path + "/";
|
}
|
|
}
|
}
|