From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期一, 11 一月 2021 16:11:20 +0800 Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善 --- Crabtree/SmartHome/HDL/Operation/UserConfig.cs | 246 ++++++++++++++++++++++++++++++------------------- 1 files changed, 151 insertions(+), 95 deletions(-) diff --git a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs index a052da0..a51d781 100644 --- a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs +++ b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs @@ -7,7 +7,7 @@ [System.Serializable] public class UserConfig { - static string configFile = "UserConfig"; + public static string configFile = "UserConfig"; static UserConfig instance; public static UserConfig Instance { @@ -28,11 +28,19 @@ 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; } @@ -144,128 +152,176 @@ 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> (); - + /// <summary> + /// 褰撳墠浣忓畢 + /// </summary> RegionInfoRes currentRegion = new RegionInfoRes (); public RegionInfoRes CurrentRegion { set { currentRegion = value; - CheckIfNeedGetMasterAccountToken (); + //CheckIfNeedGetMasterAccountToken (); //鍒囨崲浣忓畢 璁剧疆鏈湴鍔犲瘑Key SetLocalEncryptKey (); - - + //娓呯┖涔嬪墠缃戝叧鐨勪俊鎭紝閲嶆柊鑾峰彇 + HomeGateway = null; + GetHomeGatewayList (); } get { if (currentRegion == null) { currentRegion = new RegionInfoRes (); } return currentRegion; - } - } - public bool CheckHomeGateways () + #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 () { - if (CurrentRegion != null && CurrentRegion.HomeGateways != null && CurrentRegion.HomeGateways.Count > 0) { + //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銆備负浠�涔堜細澹版槑杩欐牱鍙橀噺,鍥犱负鏈変簺鎺ュ彛蹇呴』浣跨敤鍘熸潵鐨凾oken) + /// </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 (CheckHomeGateways () && !string.IsNullOrEmpty (currentRegion.HomeGateways [0].GatewayUniqueId)) { + if (HomeGateway != null && !string.IsNullOrEmpty (HomeGateway.mac)) { return true; } else { return false; } } - public bool CheckThisHomeGatewaysNotEmpty (RegionInfoRes mRegionInfoRes) - { - if (mRegionInfoRes != null && mRegionInfoRes.HomeGateways != null && mRegionInfoRes.HomeGateways.Count > 0 && !string.IsNullOrEmpty (mRegionInfoRes.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 = ""; - + /// <summary> + /// + /// </summary> public string GatewayMAC { get { if (CheckHomeGatewaysNotEmpty ()) { - return currentRegion.HomeGateways [0].GatewayUniqueId; + return HomeGateway.mac; } else { return ""; } } set { - if (CheckHomeGateways ()) { - currentRegion.HomeGateways [0].GatewayUniqueId = value; + if (CheckHomeGatewaysNotEmpty()) { + HomeGateway.mac = value; } else { //2020-01-11 - if (currentRegion != null) { - var mHomeGateways = new HomeGateways () { GatewayUniqueId = value }; - var mList = new List<HomeGateways> (); - mList.Add (mHomeGateways); - currentRegion.HomeGateways = mList; + if (HomeGateway != null) { + HomeGateway.mac = value; + } else { + HomeGateway = new HomeGatewayInfo () { mac = value}; } } } } - /// <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); - } - currentRegion.HomeGateways = mMacList; - } - } - } catch { + #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> (); - + //public List<string> RometoUserInfoKeys = new List<string> (); /// <summary> /// 鏈湴閫氫俊鍔犲瘑Key /// </summary> public string LocalEncryptKey = string.Empty; + /// <summary> + /// 鏄惁鍔犲瘑瀵嗙爜楠岃瘉閫氳繃 + /// </summary> + public bool EncryptedPasswordCorrect = true; /// <summary> /// 鏄惁鍔犲瘑 /// </summary> @@ -319,35 +375,35 @@ { if (bGetting) return; - //2020-01-08 鍒ゆ柇鏄惁鍒嗕韩杩囨潵鐨勪綇瀹� - if (currentRegion != null && currentRegion.IsOthreShare) { - //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare; - //璇锋眰涓昏处鍙穞oken - System.Threading.Tasks.Task.Run (() => { - try { - bGetting = true; - var requestObj = new GetSharedHomeApiControlObj () { - LoginAccessToken = MainPage.LoginUser.LoginTokenString, - MainAccountId = currentRegion.MainUserDistributedMark, - SharedHid = currentRegion.Id, + ////2020-01-08 鍒ゆ柇鏄惁鍒嗕韩杩囨潵鐨勪綇瀹� + //if (currentRegion != null && currentRegion.IsOthreShare) { + // //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare; + // //璇锋眰涓昏处鍙穞oken + // 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 () == "SUCCESS") { - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberAdministratorResult> (revertObj.ResponseData.ToString ()); - if (responseDataObj != null) { - MasterAccountToken = responseDataObj.RequestToken; - MasterAccountRequestBaseUrl = responseDataObj.RequestBaseUrl; - } - } - } catch { + // }; + // 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; - } - }); - } + // } finally { + // bGetting = false; + // } + // }); + //} } } -- Gitblit v1.8.0