using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using Shared.SimpleControl;
|
|
namespace Shared
|
{
|
[System.Serializable]
|
public class CommonConfig
|
{
|
public static readonly string ConfigFile = "CommonConfig";
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
public List<Function> FunctionList = new List<Function> ();
|
/// <summary>
|
/// 场景列表
|
/// </summary>
|
public List<HDLLinkSceneBase> SceneList = new List<HDLLinkSceneBase> ();
|
/// <summary>
|
///
|
/// </summary>
|
public HomeGatewayInfo HomeGatewayInfo = null;
|
/// <summary>
|
///
|
/// </summary>
|
public MqttInfo mMqttInfo = null;
|
|
/// <summary>
|
/// 是否获取MQTT参数成功
|
/// </summary>
|
public bool IfGetMqttInfoSuccess = false;
|
|
/// <summary>
|
/// 接口类的返回信息
|
/// </summary>
|
static CommonConfig m_Current = null;
|
|
/// <summary>
|
/// 接口类的返回信息
|
/// </summary>
|
public static CommonConfig Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
try
|
{
|
var APIInfoConfigBytes = IO.FileUtils.ReadFile(ConfigFile);
|
var APIInfoConfigString = CommonPage.MyEncodingUTF8.GetString(APIInfoConfigBytes);
|
CommonConfig temp = null;
|
if (APIInfoConfigString != null)
|
{
|
temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonConfig> (APIInfoConfigString);
|
}
|
if (temp == null)
|
{
|
m_Current = new CommonConfig { };
|
}
|
else
|
{
|
m_Current = temp;
|
}
|
}
|
catch
|
{
|
m_Current = new CommonConfig { };
|
}
|
}
|
return m_Current;
|
}
|
}
|
|
byte[] GetAPIInfoConfigBytes()
|
{
|
return CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
|
}
|
|
//public void Refresh()
|
//{
|
// m_Current = null;
|
// Save();
|
//}
|
|
public void Save()
|
{
|
IO.FileUtils.WriteFileByBytes(ConfigFile, GetAPIInfoConfigBytes());
|
}
|
|
|
//#region 密码锁定操作方法
|
///// <summary>
|
///// 判断当前账号是否锁定
|
///// </summary>
|
///// <param name="account"></param>
|
//public bool CheckIfLock (string account)
|
//{
|
// var lockAccount = lockList.Where (obj => obj.Account == account).FirstOrDefault ();
|
// //var lockAccount =lockList.Find ((obj) => obj.Account == account);
|
// if (lockAccount == null) {
|
// LockAccount lockAccountNew = new LockAccount () { Account = account, errorCount = 0, lockTime = DateTime.MinValue, ifLock = false };
|
// lockList.Add (lockAccountNew);
|
// return false;
|
// } else {
|
|
// //判断是否小于5分钟
|
// if (lockAccount.lockTime.AddMinutes (LOCK_TIME) > DateTime.Now) {
|
// //是,判断是否锁定
|
// if (lockAccount.ifLock) {
|
// int unlocktime = LOCK_TIME - (DateTime.Now.Minute - lockAccount.lockTime.Minute);
|
// new Alert ("", $"The current login account has been locked. Please try again in {unlocktime} minutes.", Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show ();
|
// return true;
|
// } else {
|
// return false;
|
// }
|
|
// } else {
|
// //否,解锁,重置参数
|
// lockAccount.errorCount = 0;
|
// lockAccount.lockTime = DateTime.Now;
|
// lockAccount.ifLock = false;
|
// Save ();
|
// return false;
|
// }
|
// }
|
//}
|
|
///// <summary>
|
///// 错误锁定
|
///// </summary>
|
///// <param name="account"></param>
|
//public bool ErrorLockListUpdate (string account)
|
//{
|
// var lockAccount = lockList.Where (obj => obj.Account == account).FirstOrDefault ();
|
// if (lockAccount == null) {
|
// LockAccount lockAccountNew = new LockAccount () { Account = account, errorCount = 1, lockTime = DateTime.MinValue, ifLock = false };
|
// lockList.Add (lockAccountNew);
|
// } else {
|
// if (lockAccount.errorCount < 5) {
|
// //错误次数少于5,提示密码错误并且错误次数加一
|
// int count = lockAccount.errorCount + 1;
|
// lockAccount.errorCount = count;
|
// //lockAccount.lockTime = DateTime.Now;
|
// lockAccount.ifLock = false;
|
// Save ();
|
// } else {
|
// //错误次数大于5,设备修改成锁定,设置锁定时间,重置错误次数
|
// lockAccount.errorCount = 0;
|
// lockAccount.lockTime = DateTime.Now;
|
// lockAccount.ifLock = true;
|
// Save ();
|
// MainPage.ShowAlertOnMainThread ($"The current login account has been locked. Please try again in {LOCK_TIME} minutes.");
|
// return true;
|
// }
|
// }
|
|
// return false;
|
//}
|
//#endregion
|
|
}
|
|
|
///// <summary>
|
///// 锁定的账号信息
|
///// </summary>
|
///// [Serializable]
|
//[Serializable]
|
//public class LockAccount
|
//{
|
// /// <summary>
|
// /// 账号
|
// /// </summary>
|
// public string Account { get; set; }
|
// /// <summary>
|
// /// 锁定次数
|
// /// </summary>
|
// public int errorCount { get; set; }
|
// /// <summary>
|
// /// 锁定时间
|
// /// </summary>
|
// public DateTime lockTime { get; set; }
|
// /// <summary>
|
// /// ifLock
|
// /// </summary>
|
// public bool ifLock { get; set; }
|
|
//}
|
|
}
|