| | |
| | | [System.Serializable] |
| | | public class UserConfig |
| | | { |
| | | static string configFile = "UserConfig"; |
| | | public static string configFile = "UserConfig"; |
| | | |
| | | static UserConfig instance; |
| | | public static UserConfig Instance { |
| | |
| | | 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); |
| | | //instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.UniversalDevice); |
| | | } else { |
| | | instance = temp; |
| | | } |
| | | } catch{} |
| | | } catch{ |
| | | 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); |
| | | } |
| | | } |
| | | return instance; |
| | | } |
| | |
| | | } |
| | | |
| | | public string VersionNumber { |
| | | get { return MainPage.CodeIDString; } |
| | | get { return MainPage.RequestVersion; } |
| | | } |
| | | |
| | | public string TipVersionBackup = string.Empty; |
| | |
| | | public Dictionary<string, string> RemoteDoorLockPasswordList = new Dictionary<string, string> (); |
| | | |
| | | //public string CountryCode = "CN"; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public int SkinCode = 1; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 住宅列表 |
| | | /// </summary> |
| | | public List<RegionInfoRes> HomeLists = new List<RegionInfoRes> (); |
| | | |
| | | public RegionInfoRes CurrentRegion = new RegionInfoRes (); |
| | | |
| | | public List<GatewayRes> GatewayList = new List<GatewayRes> (); |
| | | |
| | | public List<string> GatewayMACList { |
| | | /// <summary> |
| | | /// 当前住宅 |
| | | /// </summary> |
| | | RegionInfoRes currentRegion = new RegionInfoRes (); |
| | | public RegionInfoRes CurrentRegion { |
| | | set { |
| | | currentRegion = value; |
| | | //CheckIfNeedGetMasterAccountToken (); |
| | | //切换住宅 设置本地加密Key |
| | | SetLocalEncryptKey (); |
| | | //清空之前网关的信息,重新获取 |
| | | HomeGateway = null; |
| | | GetHomeGatewayList (); |
| | | } |
| | | get { |
| | | List<string> macList = new List<string> (); |
| | | foreach (var mac in GatewayList) { |
| | | macList.Add (mac.MAC); |
| | | if (currentRegion == null) { |
| | | currentRegion = new RegionInfoRes (); |
| | | } |
| | | return macList; |
| | | return currentRegion; |
| | | } |
| | | } |
| | | public string GatewayMAC = ""; |
| | | |
| | | public List<string> RometoUserInfoKeys = new List<string> (); |
| | | |
| | | #region HomeGateway |
| | | /// <summary> |
| | | /// 是否获取中 |
| | | /// 2020-01-11 |
| | | /// </summary> |
| | | bool bGettingMac = false; |
| | | //public static List<string> LocalFiles = IO.FileUtils.ReadFiles (); |
| | | /// <summary> |
| | | /// 检查是否需要获取控制分享项目(住宅)请求信息 |
| | | /// </summary> |
| | | /// <param name="mMainAccountId"></param> |
| | | /// <param name="mSharedHid"></param> |
| | | public void GetHomeGatewayList () |
| | | { |
| | | //System.Threading.Tasks.Task.Run (() => { |
| | | //if (bGettingMac) return; |
| | | HttpServerRequest.Current.GetHomeGatewayList (); |
| | | //}); |
| | | } |
| | | /// <summary> |
| | | /// 网关详细信息 |
| | | /// </summary> |
| | | public HomeGatewayInfo HomeGateway; |
| | | /// <summary> |
| | | /// 是否允许远程控制 |
| | | /// </summary> |
| | | public bool AllowRemoteControl { |
| | | get { |
| | | if (HomeIsOtherShare) { |
| | | //等于0是允许远程控制 |
| | | return UserConfig.Instance.CurrentRegion.isRemoteControl; |
| | | } else { |
| | | //住宅是自己本人的允许控制 |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token) |
| | | /// </summary> |
| | | public bool HomeIsOtherShare { |
| | | get { |
| | | if (UserConfig.Instance == null || UserConfig.Instance.CurrentRegion == null) { |
| | | return false; |
| | | } else { |
| | | return UserConfig.Instance.CurrentRegion.IsOthreShare; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测住宅是否绑定了网关 |
| | | /// gatewayId 判空 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public bool CheckWhetherGatewayIdNotNull () |
| | | { |
| | | if (HomeGateway != null && !string.IsNullOrEmpty (HomeGateway.gatewayId)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测住宅是否绑定了网关 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public bool CheckHomeGatewaysNotEmpty () |
| | | { |
| | | if (HomeGateway != null && !string.IsNullOrEmpty (HomeGateway.mac)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string GatewayMAC { |
| | | get { |
| | | if (CheckHomeGatewaysNotEmpty ()) { |
| | | return HomeGateway.mac; |
| | | } else { |
| | | return ""; |
| | | } |
| | | } |
| | | set { |
| | | if (CheckHomeGatewaysNotEmpty()) { |
| | | HomeGateway.mac = value; |
| | | } else { |
| | | //2020-01-11 |
| | | if (HomeGateway != null) { |
| | | HomeGateway.mac = value; |
| | | } else { |
| | | HomeGateway = new HomeGatewayInfo () { mac = value}; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | ///// <summary> |
| | | ///// 更新设置当前住宅网关 |
| | | ///// 2020-01-11 |
| | | ///// </summary> |
| | | ///// <param name="mGatewayDataList"></param> |
| | | //public void SetNowHomeGateways (List<GatewayRes> mGatewayDataList) { |
| | | // try { |
| | | // if (currentRegion != null) { |
| | | // if (mGatewayDataList != null && mGatewayDataList.Count > 0) { |
| | | // var mMacList = new List<HomeGateways> (); |
| | | // foreach (var mGatewayRes in mGatewayDataList) { |
| | | // var mac = new HomeGateways (); |
| | | // mac.GatewayUniqueId = mGatewayRes.GatewayUniqueId; |
| | | // mMacList.Add (mac); |
| | | // } |
| | | // //HomeGateways = mMacList; |
| | | // } |
| | | // } |
| | | // } catch { |
| | | |
| | | // } |
| | | //} |
| | | |
| | | //public List<string> RometoUserInfoKeys = new List<string> (); |
| | | |
| | | /// <summary> |
| | | /// 本地通信加密Key |
| | | /// </summary> |
| | | public string LocalEncryptKey = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 是否加密密码验证通过 |
| | | /// </summary> |
| | | public bool EncryptedPasswordCorrect = true; |
| | | /// <summary> |
| | | /// 是否加密 |
| | | /// </summary> |
| | | public bool IsLocalEncrypt = false; |
| | | /// <summary> |
| | | /// 设置为默认加密,并计算加密Key |
| | | /// </summary> |
| | | private void SetLocalEncryptKey () |
| | | { |
| | | if (currentRegion != null) { |
| | | IsLocalEncrypt = true; |
| | | GenerateLocalEncryptionKey (); |
| | | //LocalEncryptKey = CommonPage.MyEncodingUTF8.GetString (GenerateLocalEncryptionKey ()); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取16位的key byte [] |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public byte [] GenerateLocalEncryptionKey () |
| | | { |
| | | byte [] aseKey = new byte [16]; |
| | | try { |
| | | //生成加密Key |
| | | byte [] homeId = System.Text.Encoding.ASCII.GetBytes (currentRegion.Id); |
| | | Array.Copy (homeId, 0, aseKey, 0, 16 < homeId.Length ? 16 : homeId.Length); |
| | | LocalEncryptKey = System.Text.Encoding.ASCII.GetString (aseKey); |
| | | return aseKey; |
| | | |
| | | } catch { |
| | | return aseKey; |
| | | } |
| | | |
| | | } |
| | | |
| | | public string MasterAccountToken = ""; |
| | | public string MasterAccountRequestBaseUrl = ""; |
| | | /// <summary> |
| | | /// 是否获取中 |
| | | /// 2020-01-11 |
| | | /// </summary> |
| | | bool bGetting = false; |
| | | //public static List<string> LocalFiles = IO.FileUtils.ReadFiles (); |
| | | /// <summary> |
| | | /// 获取控制分享项目(住宅)请求信息 |
| | | /// </summary> |
| | | /// <param name="mMainAccountId"></param> |
| | | /// <param name="mSharedHid"></param> |
| | | public void CheckIfNeedGetMasterAccountToken () |
| | | { |
| | | if (bGetting) return; |
| | | |
| | | ////2020-01-08 判断是否分享过来的住宅 |
| | | //if (currentRegion != null && currentRegion.IsOthreShare) { |
| | | // //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare; |
| | | // //请求主账号token |
| | | // System.Threading.Tasks.Task.Run (() => { |
| | | // try { |
| | | // bGetting = true; |
| | | // var requestObj = new GetSharedHomeApiControlObj () { |
| | | // LoginAccessToken = MainPage.LoginUser.LoginTokenString, |
| | | // MainAccountId = currentRegion.MainUserDistributedMark, |
| | | // SharedHid = currentRegion.Id, |
| | | |
| | | // }; |
| | | // var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); |
| | | // var revertObj = MainPage.RequestHttps (API.GetSharedHomeApiControl, requestJson); |
| | | // if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) { |
| | | // var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberAdministratorResult> (revertObj.ResponseData.ToString ()); |
| | | // if (responseDataObj != null) { |
| | | // MasterAccountToken = responseDataObj.RequestToken; |
| | | // MasterAccountRequestBaseUrl = responseDataObj.RequestBaseUrl; |
| | | // } |
| | | // } |
| | | // } catch { |
| | | |
| | | // } finally { |
| | | // bGetting = false; |
| | | // } |
| | | // }); |
| | | //} |
| | | } |
| | | |
| | | } |
| | | } |