using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl;
|
|
namespace Shared
|
{
|
[System.Serializable]
|
public class UserConfig
|
{
|
static string configFile = "UserConfig";
|
|
static UserConfig instance;
|
public static UserConfig Instance {
|
get {
|
if (instance == null) {
|
try {
|
var userConfigBytes = IO.FileUtils.ReadFile (configFile);
|
var userConfigString = CommonPage.MyEncodingUTF8.GetString (userConfigBytes);
|
UserConfig temp = null;
|
if (userConfigString != null) {
|
temp = Newtonsoft.Json.JsonConvert.DeserializeObject<UserConfig> (userConfigString);
|
}
|
if (temp == null) {
|
instance = new UserConfig { };
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Projector);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.DoorLock);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.FreshAir);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Sensor);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Environmental);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.MusicModel);
|
instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.UniversalDevice);
|
} else {
|
instance = temp;
|
}
|
} catch{}
|
}
|
return instance;
|
}
|
}
|
|
public int internetStatus = 2;
|
|
byte [] GetUserConfigBytes ()
|
{
|
return CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this));
|
}
|
|
public void RefreshUserConfig ()
|
{
|
instance = null;
|
}
|
|
public void SaveUserConfig ()
|
{
|
IO.FileUtils.WriteFileByBytes (configFile, GetUserConfigBytes ());
|
}
|
|
//public void RefeshUserConfig()
|
//{
|
//}
|
|
/// <summary>
|
/// 存放不用调光功能的调光设备
|
/// </summary>
|
public List<string> UnEnableDimmingLight = new List<string> ();
|
|
/// <summary>
|
/// 插座开关列表
|
/// </summary>
|
public List<string> SocketList = new List<string> ();
|
|
/// <summary>
|
/// 手机appID
|
/// </summary>
|
public string tokenID = string.Empty;
|
|
/// <summary>
|
/// 手机别名
|
/// </summary>
|
public string phoneName = string.Empty;
|
|
/// <summary>
|
/// 用户界面进入时是否显示的是全局场景界面
|
/// </summary>
|
public bool SceneOfGloba = false;
|
|
/// <summary>
|
/// 保存远程连接的网络设备文件名
|
/// </summary>
|
public string RemoteModeFile = string.Empty;
|
|
/// <summary>
|
/// 是否展开房间灯光列表
|
/// </summary>
|
public bool ShowRoomLightList = true;
|
|
/// <summary>
|
/// 是否展开房间窗帘列表
|
/// </summary>
|
public bool ShowRoomCurtainList = true;
|
|
/// <summary>
|
/// 隐藏没有场景的房间
|
/// </summary>
|
public bool HideInvalidRoomScene = false;
|
|
public List<int> HideDeviceTypes = new List<int> ();
|
|
public Dictionary<string, int> SkinVision = new Dictionary<string, int> ();
|
public Dictionary<string, int> DowlaodSkinVision = new Dictionary<string, int> ();
|
/// <summary>
|
/// 当前使用的皮肤
|
/// </summary>
|
public string CurrentSkinName {
|
get {
|
string skinPath = "Phone";
|
if (SkinCode == 0) {
|
skinPath = "Phone";
|
} else if (SkinCode == 1) {
|
skinPath = "Phone2";
|
}
|
return skinPath;
|
}
|
}
|
|
public string VersionNumber {
|
get { return MainPage.RequestVersion; }
|
}
|
|
public string TipVersionBackup = string.Empty;
|
|
/// <summary>
|
/// 安防密码
|
/// </summary>
|
public string ArmPW = "85521566";
|
|
|
/// <summary>
|
/// 是否显示场景列表
|
/// </summary>
|
public bool ShowAlternativeScene = true;
|
|
//门锁密码保存
|
public Dictionary<string, string> RemoteDoorLockPasswordList = new Dictionary<string, string> ();
|
|
//public string CountryCode = "CN";
|
public int SkinCode = 1;
|
|
|
public List<RegionInfoRes> HomeLists = new List<RegionInfoRes> ();
|
|
RegionInfoRes currentRegion = new RegionInfoRes ();
|
public RegionInfoRes CurrentRegion {
|
set {
|
currentRegion = value;
|
CheckIfNeedGetMasterAccountToken ();
|
}
|
get {
|
return currentRegion;
|
}
|
|
}
|
|
public bool CheckHomeGateways ()
|
{
|
if (CurrentRegion != null && CurrentRegion.HomeGateways != null && CurrentRegion.HomeGateways.Count > 0) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
public bool CheckHomeGatewaysNotEmpty ()
|
{
|
if (CheckHomeGateways () && !string.IsNullOrEmpty (currentRegion.HomeGateways [0].GatewayUniqueId)) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
//public List<GatewayRes> GatewayList = new List<GatewayRes> ();
|
|
//public List<string> GatewayMACList {
|
// get {
|
// List<string> macList = new List<string> ();
|
// foreach (var mac in GatewayList) {
|
// macList.Add (mac.GatewayUniqueId);
|
// }
|
// return macList;
|
// }
|
//}
|
//public string GatewayMAC = "";
|
|
public string GatewayMAC {
|
get {
|
if (CheckHomeGatewaysNotEmpty ()) {
|
return currentRegion.HomeGateways [0].GatewayUniqueId;
|
} else {
|
return "";
|
}
|
}
|
set {
|
if (CheckHomeGateways ()) {
|
currentRegion.HomeGateways [0].GatewayUniqueId = value;
|
} else {
|
if (currentRegion != null && currentRegion.HomeGateways == null) {
|
var mHomeGateways = new HomeGateways () { GatewayUniqueId = value };
|
List<HomeGateways> HomeGateways = new List<HomeGateways> ();
|
HomeGateways.Add (mHomeGateways);
|
currentRegion.HomeGateways = HomeGateways;
|
}
|
}
|
}
|
|
}
|
|
|
public List<string> RometoUserInfoKeys = new List<string> ();
|
|
public string MasterAccountToken = "";
|
public string MasterAccountRequestBaseUrl = "";
|
|
//public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
|
/// <summary>
|
/// 获取控制分享项目(住宅)请求信息
|
/// </summary>
|
/// <param name="mMainAccountId"></param>
|
/// <param name="mSharedHid"></param>
|
public void CheckIfNeedGetMasterAccountToken ()
|
{
|
//2020-01-08 判断是否分享过来的住宅
|
if (CurrentRegion != null && CurrentRegion.IsOthreShare) {
|
//MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare;
|
//请求主账号token
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
//var mMainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark;
|
//var mSharedHid = UserConfig.Instance.CurrentRegion.Id;
|
var requestObj = new GetSharedHomeApiControlObj () {
|
LoginAccessToken = MainPage.LoginUser.LoginTokenString,
|
MainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark,
|
SharedHid = UserConfig.Instance.CurrentRegion.Id,
|
|
};
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps (API.GetSharedHomeApiControl, requestJson);
|
if (revertObj.StateCode.ToUpper () == "SUCCESS") {
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberAdministratorResult> (revertObj.ResponseData.ToString ());
|
if (responseDataObj != null) {
|
MasterAccountToken = responseDataObj.RequestToken;
|
MasterAccountRequestBaseUrl = responseDataObj.RequestBaseUrl;
|
}
|
}
|
} catch {
|
|
}
|
});
|
}
|
}
|
|
}
|
}
|