From dc0309e64f02227d8e1468b7326c07955f804612 Mon Sep 17 00:00:00 2001 From: chenqiyang <1406175257@qq.com> Date: 星期三, 22 六月 2022 11:22:18 +0800 Subject: [PATCH] 修改引用路径 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs | 1392 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 706 insertions(+), 686 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs old mode 100755 new mode 100644 index da123a1..459e2bd --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs @@ -1,686 +1,706 @@ -锘縰sing Shared.Common; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Shared.Phone.UserCenter -{ - /// <summary> - /// 浣忓畢瀵硅薄鐨勯�昏緫 - /// </summary> - public class HdlResidenceLogic - { - #region 鈻� 鍙橀噺澹版槑___________________________ - - /// <summary> - /// 浣忓畢瀵硅薄鐨勯�昏緫 - /// </summary> - private static HdlResidenceLogic m_Current = null; - /// <summary> - /// 浣忓畢瀵硅薄鐨勯�昏緫 - /// </summary> - public static HdlResidenceLogic Current - { - get - { - if (m_Current == null) - { - m_Current = new HdlResidenceLogic(); - } - return m_Current; - } - } - - #endregion - - #region 鈻� 鍒涘缓鏂颁綇瀹卂________________________ - - /// <summary> - /// 鍒涘缓鏂扮殑浣忓畢(杩斿洖浣忓畢id,null浠h〃澶辫触) - /// </summary> - /// <param name="residenceName">浣忓畢鍚嶇О</param> - public string CreatNewResidence(string residenceName) - { - var Pra = new AddResidencePra(); - Pra.Name = residenceName; - //娣诲姞浣忓畢 - string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra); - if (string.IsNullOrEmpty(resultData) == true) - { - return null; - } - var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData); - - //娣诲姞浣忓畢鍒扮紦瀛� - this.AddHouseToMemmory(newInfo[0].Id, residenceName); - - return newInfo[0].Id; - } - - /// <summary> - /// 娣诲姞浣忓畢鍒扮紦瀛� - /// </summary> - /// <param name="houseId">浣忓畢id</param> - /// <param name="houseName">浣忓畢鍚嶇О.</param> - /// <param name="isOthreShare">鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�</param> - /// <param name="accountType">浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺</param> - public void AddHouseToMemmory(string houseId, string houseName, - bool isOthreShare = false, int accountType = 0) - { - var home = new Common.House(); - home.Id = houseId; - home.Name = houseName; - home.IsOthreShare = isOthreShare; - home.AccountType = accountType; - - //鍒涘缓鏂囦欢澶� - Common.Global.CreateHomeDirectory(houseId); - home.Save(); - Common.Config.Instance.HomeFilePathList.Add(home.FileName); - Common.Config.Instance.Save(); - //濡傛灉褰撳墠娌℃湁浣忓畢鐨勮瘽 - if (Common.Config.Instance.Home.Id == string.Empty) - { - Common.Config.Instance.Home = this.GetHouseByFilePath(home.FileName); - Common.Config.Instance.HomeId = home.Id; - } - } - - - #endregion - - #region 鈻� 鍒囨崲浣忓畢___________________________ - - /// <summary> - /// 鍒囨崲浣忓畢(娉�:瀹冨彧鍒囨崲鍐呭瓨,鐣岄潰骞舵湭澶勭悊) - /// </summary> - /// <param name="residenceId"></param> - /// <returns></returns> - public bool SwitchResidence(string residenceId) - { - //鎵撳紑杩涘害鏉� - ProgressBar.Show(); - - Config.Instance.HomeId = residenceId; - //閲嶆柊鍒濆鍖栦綇瀹呭璞� - Config.Instance.Home = this.GetHouseByHouseId(residenceId); - Config.Instance.Save(); - //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼ - bool result = UserCenterLogic.InitUserCenterMenmoryAndThread(false); - - //鍏抽棴杩涘害鏉� - ProgressBar.Close(); - - return result; - } - - #endregion - - #region 鈻� 缂栬緫浣忓畢___________________________ - - /// <summary> - /// 缂栬緫浣忓畢 - /// </summary> - /// <param name="residenceId">浣忓畢id</param> - /// <param name="residenceName">浣忓畢鍚嶇О</param> - /// <returns></returns> - public bool EditorResidenceName(string residenceId, string residenceName) - { - var Pra = new EditorResidencePra(); - Pra.HomeId = residenceId; - Pra.Name = residenceName; - Pra.IsOtherAccountCtrl = false; - Pra.LoginAccessToken = Config.Instance.Token; - - //缂栬緫浣忓畢 - bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra); - if (flage == true) - { - //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕 - this.EditorHouseByHouseId(residenceId, residenceName); - } - return flage; - } - - /// <summary> - /// 缂栬緫缂撳瓨浣忓畢 - /// </summary> - /// <param name="residenceId">浣忓畢id</param> - /// <param name="residenceName">浣忓畢鍚嶇О</param> - public void EditorHouseByHouseId(string residenceId, string residenceName) - { - if (Config.Instance.Home.Id == residenceId) - { - Config.Instance.Home.Name = residenceName; - } - - var home = GetHouseByHouseId(residenceId); - if (home == null) - { - return; - } - home.Name = residenceName; - home.Save(); - //浣忓畢淇敼鍚嶇О鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� - UserView.UserPage.Instance.RefreshAllForm = true; - } - - - #endregion - - #region 鈻� 鑾峰彇浣忓畢___________________________ - - /// <summary> - /// 閫氳繃銆恑d銆戣幏鍙栦綇瀹� - /// </summary> - /// <returns>The house by house identifier.</returns> - /// <param name="houseId">浣忓畢id</param> - public House GetHouseByHouseId(string houseId) - { - var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json"); - var file = HdlFileLogic.Current.ReadFileByteContent(path); - if (file == null) - { - return null; - } - return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file)); - } - - /// <summary> - /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹� - /// </summary> - /// <returns>The house by file path.</returns> - /// <param name="filePath">鏂囦欢璺緞</param> - public House GetHouseByFilePath(string filePath) - { - var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath); - var file = HdlFileLogic.Current.ReadFileByteContent(path); - if (file == null) - { - return null; - } - return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file)); - } - - #endregion - - #region 鈻� 鑾峰彇浜戠浣忓畢鍒楄〃___________________ - /// <summary> - /// 鑾峰彇浜戠浣忓畢鍒楄〃 - /// </summary> - /// <param name="checkNetwork">鏄惁妫�娴嬬綉缁�,濡傛灉璁剧疆妫�娴嬬殑璇�,褰撲笉鑳借仈缃戞椂,鐩存帴杩斿洖鏈湴浣忓畢</param> - /// <returns></returns> - public List<string> GetHomeListsFromDb(bool checkNetwork) - { - if (checkNetwork == true && HdlWifiLogic.Current.CanAccessHttp == false) - { - //褰撳墠鏃犳硶鑱旂綉 - return Config.Instance.HomeFilePathList; - } - var requestObj = new SendDataToServer.ResidenceListReqDto() - { - RequestVersion = CommonPage.RequestVersion, - ReqDto = new SendDataToServer.ResidenceListObj() - { - LoginAccessToken = Config.Instance.Token, - PageSetting = new SendDataToServer.ResidenceListPageSettingObj { PageSize = 999 } - } - }; - try - { - var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); - var revertObj = CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson), 5); - if (revertObj == null) - { - return null; - } - if (revertObj.StateCode.ToUpper() == "SUCCESS") - { - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResidenceRes>(revertObj.ResponseData.ToString()); - if (responseDataObj.TotalCount > 0) - { - //娓呯┖褰撳墠浣忓畢鍒楄〃 - Config.Instance.HomeFilePathList.Clear(); - var listHouse = new List<House>(); - foreach (var residence in responseDataObj.PageData) - { - Config.Instance.HomeFilePathList.Add($"House_{residence.Id}.json"); - var house = GetHouseByHouseId(residence.Id); - if (house == null) - { - house = new House - { - Id = residence.Id, - Name = residence.Name, - IsOthreShare = residence.IsOthreShare, - AccountType = residence.AccountType, - MainUserDistributedMark = residence.MainUserDistributedMark, - Longitude = residence.Longitude, - Latitude = residence.Latitude - }; - } - else - { - house.Id = residence.Id; - house.Name = residence.Name; - house.IsOthreShare = residence.IsOthreShare; - house.AccountType = residence.AccountType; - house.MainUserDistributedMark = residence.MainUserDistributedMark; - house.Longitude = residence.Longitude; - house.Latitude = residence.Latitude; - } - Global.CreateHomeDirectory(residence.Id); - house.Save(false); - listHouse.Add(house); - } - //妫�娴嬫湰鍦扮殑浣忓畢鏂囦欢鏄惁鍚堟硶 - var listLocal = this.GetAllLocalResidenceListByDirectory(); - foreach (var myHouse in listLocal) - { - //濡傛灉鏈湴瀛樺湪涓嶅睘浜庝粬鐨勪綇瀹呮枃浠�,鍒欏垹闄� - if (myHouse.HouseDataDiv == 1 && Config.Instance.HomeFilePathList.Contains(myHouse.FileName) == false) - { - string housePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, myHouse.Id); - HdlFileLogic.Current.DeleteDirectory(housePath); - } - } - //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D - if (Config.Instance.TheSameLoginAccount == false || - Config.Instance.HomeFilePathList.Contains($"House_{Config.Instance.HomeId}.json") == false) - { - Config.Instance.HomeId = listHouse[0].Id; - if (listHouse.Count > 0) - { - Config.Instance.HomeId = listHouse[0].Id; - Config.Instance.Home = GetHouseByHouseId(listHouse[0].Id); - } - } - Config.Instance.Save(); - } - } - } - catch (Exception ex) - { - HdlLogLogic.Current.WriteLog(ex); - } - return Config.Instance.HomeFilePathList; - } - - #endregion - - #region 鈻� 鑾峰彇鏈湴浣忓畢鍒楄〃___________________ - - /// <summary> - /// 鑾峰彇鏈湴浣忓畢鍒楄〃 - /// </summary> - /// <returns></returns> - public List<Common.House> GetLocalResidenceList() - { - //濡傛灉鏄櫄鎷熶綇瀹�,鍒欎粠鏍圭洰褰曚腑鑾峰彇 - if (Common.Config.Instance.Home.IsVirtually == true) - { - //浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄 - return this.GetAllLocalResidenceListByDirectory(); - } - - var listHome = new List<Common.House>(); - foreach (var housePath in Common.Config.Instance.HomeFilePathList) - { - var home = this.GetHouseByFilePath(housePath); - if (home == null) - { - continue; - } - listHome.Add(home); - } - return this.SortHouse(listHome); - } - - /// <summary> - /// 浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄 - /// </summary> - /// <returns></returns> - public List<Common.House> GetAllLocalResidenceListByDirectory() - { - var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid); - var listHome = new List<Common.House>(); - //鑾峰彇鍏ㄩ儴鐨勬枃浠跺す - var listDirectory = new List<string>(); - var arryDirs = System.IO.Directory.GetDirectories(strPath); - foreach (var file in arryDirs) - { - string[] arry = file.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); - listDirectory.Add(arry[arry.Length - 1]); - } - foreach (var myDir in listDirectory) - { - //鑾峰彇鍚勪釜鏂囦欢澶归噷闈㈢殑浣忓畢鏂囦欢 - string nowPath = System.IO.Path.Combine(strPath, myDir); - var arryHouse = System.IO.Directory.GetFiles(nowPath, "House_*"); - if (arryHouse.Length > 0) - { - //璇诲彇鏂囦欢鍐呭 - var textValue = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(nowPath, arryHouse[0])); - if (textValue == null) - { - continue; - } - var myHouse = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.House>(textValue); - listHome.Add(myHouse); - } - } - return this.SortHouse(listHome); - } - - #endregion - - #region 鈻� 浣忓畢鎺掑簭___________________________ - - /// <summary> - /// 浣忓畢鎺掑簭 - /// </summary> - /// <param name="i_listHouse"></param> - /// <returns></returns> - public List<House> SortHouse(List<House> i_listHouse) - { - //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� - var listName = new List<string>(); - foreach (var house in i_listHouse) - { - listName.Add(house.Name); - } - int numberLength = this.GetNumberMaxLength(listName); - - var listSort = new List<string[]>(); - var dicHouse = new Dictionary<string, House>(); - foreach (var house in i_listHouse) - { - //涓存椂缂撳瓨 - dicHouse[house.Id] = house; - - var strArry = new string[2]; - strArry[0] = house.Id; - strArry[1] = string.Empty; - - string value = string.Empty; - foreach (var c in house.Name) - { - if (char.IsNumber(c) == true) - { - //鏁板瓧 - value += c.ToString(); - continue; - } - else if (value != string.Empty) - { - //濡傛灉鎴块棿鍚嶅瓧甯︽湁鏁板瓧鐨勮瘽,鍒欏乏杈瑰姞闆�,鍥犱负杩欓噷鏈変釜鎺掑簭鐨勯棶棰� - strArry[1] += value.PadLeft(numberLength, '0'); - value = string.Empty; - } - strArry[1] += c.ToString(); - } - if (value != string.Empty) - { - //浠ユ暟瀛楃粨灏剧殑璇� - strArry[1] += value.PadLeft(numberLength, '0'); - } - listSort.Add(strArry); - } - //鎺掑簭 - listSort.Sort((obj1, obj2) => - { - if (obj1[1].CompareTo(obj2[1]) > 0) - { - return 1; - } - return -1; - }); - var listSortHouse = new List<House>(); - foreach (var strArry in listSort) - { - listSortHouse.Add(dicHouse[strArry[0]]); - } - return listSortHouse; - } - - /// <summary> - /// 浜戠浣忓畢鎺掑簭 - /// </summary> - /// <param name="i_listData"></param> - /// <returns></returns> - public List<Common.ResponseEntity.ResidenceObj> SortHouse(List<Common.ResponseEntity.ResidenceObj> i_listData) - { - //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� - var listName = new List<string>(); - foreach (var house in i_listData) - { - listName.Add(house.Name); - } - int numberLength = this.GetNumberMaxLength(listName); - - var listSort = new List<string[]>(); - var dicHouse = new Dictionary<string, Common.ResponseEntity.ResidenceObj>(); - foreach (var house in i_listData) - { - //涓存椂缂撳瓨 - dicHouse[house.Id] = house; - - var strArry = new string[2]; - strArry[0] = house.Id; - strArry[1] = string.Empty; - - string value = string.Empty; - foreach (var c in house.Name) - { - if (char.IsNumber(c) == true) - { - //鏁板瓧 - value += c.ToString(); - continue; - } - else if (value != string.Empty) - { - //濡傛灉鎴块棿鍚嶅瓧甯︽湁鏁板瓧鐨勮瘽,鍒欏乏杈瑰姞闆�,鍥犱负杩欓噷鏈変釜鎺掑簭鐨勯棶棰� - strArry[1] += value.PadLeft(numberLength, '0'); - value = string.Empty; - } - strArry[1] += c.ToString(); - } - if (value != string.Empty) - { - //浠ユ暟瀛楃粨灏剧殑璇� - strArry[1] += value.PadLeft(numberLength, '0'); - } - listSort.Add(strArry); - } - //鎺掑簭 - listSort.Sort((obj1, obj2) => - { - if (obj1[1].CompareTo(obj2[1]) > 0) - { - return 1; - } - return -1; - }); - var listSortHouse = new List<Common.ResponseEntity.ResidenceObj>(); - foreach (var strArry in listSort) - { - listSortHouse.Add(dicHouse[strArry[0]]); - } - return listSortHouse; - } - - /// <summary> - /// 浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� - /// </summary> - /// <param name="listText"></param> - /// <returns></returns> - private int GetNumberMaxLength(List<string> listText) - { - int maxLength = 0; - foreach (var text in listText) - { - string value = string.Empty; - foreach (var c in text) - { - if (char.IsNumber(c) == true) - { - //鏁板瓧 - value += c.ToString(); - continue; - } - else if (value != string.Empty) - { - //鍒ゆ柇鏁板瓧闀垮害 - if (maxLength <= value.Length) - { - maxLength = value.Length; - } - value = string.Empty; - } - } - //鍒ゆ柇鏁板瓧闀垮害 - if (maxLength <= value.Length) - { - maxLength = value.Length; - } - } - return maxLength; - } - - #endregion - - #region 鈻� 鍒犻櫎浣忓畢___________________________ - - /// <summary> - /// 鍒犻櫎浣忓畢 - /// </summary> - /// <param name="filePath">File path.</param> - public void DeleteHouseMemmory(string houseId) - { - string filePath = this.GetHouseFilePathByHouseId(houseId); - var delPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath)); - if (System.IO.Directory.Exists(delPath) == false) - { - return; - } - var fileList = GetHouseFileListByHomeId(houseId); - foreach (var file in fileList) - { - //鍒犻櫎鏂囦欢 - System.IO.File.Delete(System.IO.Path.Combine(delPath, file)); - } - //鍒犻櫎鏂囦欢澶� - System.IO.Directory.Delete(delPath, true); - //HomeFilePathList涓垹闄よ鍒楄〃 - Common.Config.Instance.HomeFilePathList.RemoveAll((obj) => obj == filePath); - Config.Instance.Save(); - } - - #endregion - - #region 鈻� 鑾峰彇璇ヤ綇瀹呯殑鏂囦欢鍒楄〃_______________ - - /// <summary> - /// 閫氳繃銆恏ouseId銆戣幏鍙栬浣忓畢鐨勬枃浠跺垪琛� - /// </summary> - /// <returns>The house file list by home identifier.</returns> - /// <param name="houseId">House identifier.</param> - public List<string> GetHouseFileListByHomeId(string houseId) - { - var list = new List<string> { }; - var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId); - if (!System.IO.Directory.Exists(path)) - { - return new List<string> { }; - } - var files = System.IO.Directory.GetFiles(path); - foreach (var file in files) - { - var f = file.Substring(path.Length + 1); - System.Console.WriteLine(f); - list.Add(f); - } - return list; - } - - #endregion - - #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// 鑾峰彇妤煎眰鍚嶇О - /// </summary> - /// <param name="i_FloorId">妤煎眰ID</param> - /// <returns></returns> - public string GetFloorNameById(string i_FloorId) - { - if (i_FloorId == null) { return string.Empty; } - if (Config.Instance.Home.FloorDics.ContainsKey(i_FloorId) == false) - { - return string.Empty; - } - return Config.Instance.Home.FloorDics[i_FloorId]; - } - - /// <summary> - /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹卛d - /// </summary> - /// <returns>The house identifier by file path.</returns> - /// <param name="filePath">鏂囦欢璺緞</param> - public string GetHouseIdByFilePath(string filePath) - { - string[] sArray = filePath.Split(new string[] { "House_", ".json" }, StringSplitOptions.RemoveEmptyEntries); - if (sArray.Length >= 1) - { - return sArray[0]; - } - return null; - } - - /// <summary> - /// 閫氳繃銆愪綇瀹卛d銆戣幏鍙栦綇瀹呰矾寰� - /// </summary> - /// <returns>The house identifier by file path.</returns> - /// <param name="houseId">浣忓畢id</param> - public string GetHouseFilePathByHouseId(string houseId) - { - return $"House_{houseId}.json"; - } - - #endregion - - #region 鈻� 缁撴瀯浣揰____________________________ - - /// <summary> - /// 娣诲姞浣忓畢鐨勫惎鍔ㄥ弬鏁� - /// </summary> - private class AddResidencePra : IfacePraCommon - { - /// <summary> - /// RequestVersion - /// </summary> - public string RequestVersion = Common.CommonPage.RequestVersion; - /// <summary> - /// LoginAccessToken - /// </summary> - public string LoginAccessToken = Common.Config.Instance.Token; - /// <summary> - /// Name - /// </summary> - public string Name = string.Empty; - } - - /// <summary> - /// 鏂颁綇瀹呯殑淇℃伅 - /// </summary> - private class NewResidenceInfo - { - /// <summary> - /// ZigbeeHomeGuid - /// </summary> - public string Id = string.Empty; - } - #endregion - } -} +锘縰sing Shared.Common; +using System; +using System.Collections.Generic; +using System.Text; +using Shared.IOS.HDLFVSDK; +namespace Shared.Phone.UserCenter +{ + /// <summary> + /// 浣忓畢瀵硅薄鐨勯�昏緫 + /// </summary> + public class HdlResidenceLogic + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 浣忓畢瀵硅薄鐨勯�昏緫 + /// </summary> + private static HdlResidenceLogic m_Current = null; + /// <summary> + /// 浣忓畢瀵硅薄鐨勯�昏緫 + /// </summary> + public static HdlResidenceLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlResidenceLogic(); + } + return m_Current; + } + } + + #endregion + + #region 鈻� 鍒涘缓鏂颁綇瀹卂________________________ + + /// <summary> + /// 鍒涘缓鏂扮殑浣忓畢(杩斿洖浣忓畢id,null浠h〃澶辫触) + /// </summary> + /// <param name="residenceName">浣忓畢鍚嶇О</param> + public string CreatNewResidence(string residenceName) + { + var Pra = new AddResidencePra(); + Pra.Name = residenceName; + //娣诲姞浣忓畢 + string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra); + if (string.IsNullOrEmpty(resultData) == true) + { + return null; + } + var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData); + + //娣诲姞浣忓畢鍒扮紦瀛� + this.AddHouseToMemmory(newInfo[0].Id, residenceName); + + return newInfo[0].Id; + } + + /// <summary> + /// 娣诲姞浣忓畢鍒扮紦瀛� + /// </summary> + /// <param name="houseId">浣忓畢id</param> + /// <param name="houseName">浣忓畢鍚嶇О.</param> + /// <param name="isOthreShare">鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�</param> + /// <param name="accountType">浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺</param> + public void AddHouseToMemmory(string houseId, string houseName, + bool isOthreShare = false, int accountType = 0) + { + var home = new Common.House(); + home.Id = houseId; + home.Name = houseName; + home.IsOthreShare = isOthreShare; + home.AccountType = accountType; + + //鍒涘缓鏂囦欢澶� + Common.Global.CreateHomeDirectory(houseId); + home.Save(); + Common.Config.Instance.HomeFilePathList.Add(home.FileName); + Common.Config.Instance.Save(); + //濡傛灉褰撳墠娌℃湁浣忓畢鐨勮瘽 + if (Common.Config.Instance.Home.Id == string.Empty) + { + Common.Config.Instance.Home = this.GetHouseByFilePath(home.FileName); + Common.Config.Instance.HomeId = home.Id; + } + } + + + #endregion + + #region 鈻� 鍒囨崲浣忓畢___________________________ + + /// <summary> + /// 鍒囨崲浣忓畢(娉�:瀹冨彧鍒囨崲鍐呭瓨,鐣岄潰骞舵湭澶勭悊) + /// </summary> + /// <param name="residenceId"></param> + /// <returns></returns> + public bool SwitchResidence(string residenceId) + { + //鎵撳紑杩涘害鏉� + ProgressBar.Show(); + + Config.Instance.HomeId = residenceId; + //閲嶆柊鍒濆鍖栦綇瀹呭璞� + Config.Instance.Home = this.GetHouseByHouseId(residenceId); + Config.Instance.Save(); + //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼ + bool result = UserCenterLogic.InitUserCenterMenmoryAndThread(false); + + //鍏抽棴杩涘害鏉� + ProgressBar.Close(); + +#if iOS + //閫�鍑虹櫥褰曞叏瑙嗛�� + Shared.IOS.HDLFVSDK.Video.Logout(); + //閲嶆柊鐧诲綍鍏ㄨ閫� + Shared.IOS.HDLFVSDK.Video.Init("", residenceId); +#endif + + + return result; + } + + #endregion + + #region 鈻� 缂栬緫浣忓畢___________________________ + + /// <summary> + /// 缂栬緫浣忓畢 + /// </summary> + /// <param name="residenceId">浣忓畢id</param> + /// <param name="residenceName">浣忓畢鍚嶇О</param> + /// <returns></returns> + public bool EditorResidenceName(string residenceId, string residenceName) + { + var Pra = new EditorResidencePra(); + Pra.HomeId = residenceId; + Pra.Name = residenceName; + Pra.IsOtherAccountCtrl = false; + Pra.LoginAccessToken = Config.Instance.Token; + + //缂栬緫浣忓畢 + bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra); + if (flage == true) + { + //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕 + this.EditorHouseByHouseId(residenceId, residenceName); + } + return flage; + } + + /// <summary> + /// 缂栬緫缂撳瓨浣忓畢 + /// </summary> + /// <param name="residenceId">浣忓畢id</param> + /// <param name="residenceName">浣忓畢鍚嶇О</param> + public void EditorHouseByHouseId(string residenceId, string residenceName) + { + if (Config.Instance.Home.Id == residenceId) + { + Config.Instance.Home.Name = residenceName; + } + + var home = GetHouseByHouseId(residenceId); + if (home == null) + { + return; + } + home.Name = residenceName; + home.Save(); + //浣忓畢淇敼鍚嶇О鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� + UserView.UserPage.Instance.RefreshAllForm = true; + } + + + #endregion + + #region 鈻� 鑾峰彇浣忓畢___________________________ + + /// <summary> + /// 閫氳繃銆恑d銆戣幏鍙栦綇瀹� + /// </summary> + /// <returns>The house by house identifier.</returns> + /// <param name="houseId">浣忓畢id</param> + public House GetHouseByHouseId(string houseId) + { + var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json"); + var file = HdlFileLogic.Current.ReadFileByteContent(path); + if (file == null) + { + return null; + } + return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file)); + } + + /// <summary> + /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹� + /// </summary> + /// <returns>The house by file path.</returns> + /// <param name="filePath">鏂囦欢璺緞</param> + public House GetHouseByFilePath(string filePath) + { + var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath); + var file = HdlFileLogic.Current.ReadFileByteContent(path); + if (file == null) + { + return null; + } + return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file)); + } + + #endregion + + #region 鈻� 鑾峰彇浜戠浣忓畢鍒楄〃___________________ + /// <summary> + /// 鑾峰彇浜戠浣忓畢鍒楄〃 + /// </summary> + /// <param name="checkNetwork">鏄惁妫�娴嬬綉缁�,濡傛灉璁剧疆妫�娴嬬殑璇�,褰撲笉鑳借仈缃戞椂,鐩存帴杩斿洖鏈湴浣忓畢</param> + /// <returns></returns> + public List<string> GetHomeListsFromDb(bool checkNetwork) + { + if (checkNetwork == true && HdlWifiLogic.Current.CanAccessHttp == false) + { + //褰撳墠鏃犳硶鑱旂綉 + return Config.Instance.HomeFilePathList; + } + var requestObj = new SendDataToServer.ResidenceListReqDto() + { + RequestVersion = CommonPage.RequestVersion, + ReqDto = new SendDataToServer.ResidenceListObj() + { + LoginAccessToken = Config.Instance.Token, + PageSetting = new SendDataToServer.ResidenceListPageSettingObj { PageSize = 999 } + } + }; + try + { + var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); + var revertObj = CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson), 5); + if (revertObj == null) + { + return null; + } + if (revertObj.StateCode.ToUpper() == "SUCCESS") + { + var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResidenceRes>(revertObj.ResponseData.ToString()); + if (responseDataObj.TotalCount > 0) + { + //娓呯┖褰撳墠浣忓畢鍒楄〃 + Config.Instance.HomeFilePathList.Clear(); + var listHouse = new List<House>(); + foreach (var residence in responseDataObj.PageData) + { + Config.Instance.HomeFilePathList.Add($"House_{residence.Id}.json"); + var house = GetHouseByHouseId(residence.Id); + if (house == null) + { + house = new House + { + Id = residence.Id, + Name = residence.Name, + IsOthreShare = residence.IsOthreShare, + AccountType = residence.AccountType, + MainUserDistributedMark = residence.MainUserDistributedMark, + Longitude = residence.Longitude, + Latitude = residence.Latitude + }; + } + else + { + house.Id = residence.Id; + house.Name = residence.Name; + house.IsOthreShare = residence.IsOthreShare; + house.AccountType = residence.AccountType; + house.MainUserDistributedMark = residence.MainUserDistributedMark; + house.Longitude = residence.Longitude; + house.Latitude = residence.Latitude; + } + Global.CreateHomeDirectory(residence.Id); + house.Save(false); + listHouse.Add(house); + } + //妫�娴嬫湰鍦扮殑浣忓畢鏂囦欢鏄惁鍚堟硶 + var listLocal = this.GetAllLocalResidenceListByDirectory(); + foreach (var myHouse in listLocal) + { + //濡傛灉鏈湴瀛樺湪涓嶅睘浜庝粬鐨勪綇瀹呮枃浠�,鍒欏垹闄� + if (myHouse.HouseDataDiv == 1 && Config.Instance.HomeFilePathList.Contains(myHouse.FileName) == false) + { + string housePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, myHouse.Id); + HdlFileLogic.Current.DeleteDirectory(housePath); + } + } + //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D + if (Config.Instance.TheSameLoginAccount == false || + Config.Instance.HomeFilePathList.Contains($"House_{Config.Instance.HomeId}.json") == false) + { + Config.Instance.HomeId = listHouse[0].Id; + if (listHouse.Count > 0) + { + Config.Instance.HomeId = listHouse[0].Id; + Config.Instance.Home = GetHouseByHouseId(listHouse[0].Id); +#if iOS + //鍒濆鍖栧叏瑙嗛�� + + Shared.IOS.HDLFVSDK.Video.Init("", listHouse[0].Id); +#endif + } + } + else { +#if iOS + Console.WriteLine(Config.Instance.HomeId); + //鍒濆鍖栧叏瑙嗛�� + Shared.IOS.HDLFVSDK.Video.Init("", Config.Instance.HomeId); +#endif + } + Config.Instance.Save(); + } + } + } + catch (Exception ex) + { + HdlLogLogic.Current.WriteLog(ex); + } + return Config.Instance.HomeFilePathList; + } + +#endregion + +#region 鈻� 鑾峰彇鏈湴浣忓畢鍒楄〃___________________ + + /// <summary> + /// 鑾峰彇鏈湴浣忓畢鍒楄〃 + /// </summary> + /// <returns></returns> + public List<Common.House> GetLocalResidenceList() + { + //濡傛灉鏄櫄鎷熶綇瀹�,鍒欎粠鏍圭洰褰曚腑鑾峰彇 + if (Common.Config.Instance.Home.IsVirtually == true) + { + //浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄 + return this.GetAllLocalResidenceListByDirectory(); + } + + var listHome = new List<Common.House>(); + foreach (var housePath in Common.Config.Instance.HomeFilePathList) + { + var home = this.GetHouseByFilePath(housePath); + if (home == null) + { + continue; + } + listHome.Add(home); + } + return this.SortHouse(listHome); + } + + /// <summary> + /// 浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄 + /// </summary> + /// <returns></returns> + public List<Common.House> GetAllLocalResidenceListByDirectory() + { + var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid); + var listHome = new List<Common.House>(); + //鑾峰彇鍏ㄩ儴鐨勬枃浠跺す + var listDirectory = new List<string>(); + var arryDirs = System.IO.Directory.GetDirectories(strPath); + foreach (var file in arryDirs) + { + string[] arry = file.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); + listDirectory.Add(arry[arry.Length - 1]); + } + foreach (var myDir in listDirectory) + { + //鑾峰彇鍚勪釜鏂囦欢澶归噷闈㈢殑浣忓畢鏂囦欢 + string nowPath = System.IO.Path.Combine(strPath, myDir); + var arryHouse = System.IO.Directory.GetFiles(nowPath, "House_*"); + if (arryHouse.Length > 0) + { + //璇诲彇鏂囦欢鍐呭 + var textValue = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(nowPath, arryHouse[0])); + if (textValue == null) + { + continue; + } + var myHouse = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.House>(textValue); + listHome.Add(myHouse); + } + } + return this.SortHouse(listHome); + } + +#endregion + +#region 鈻� 浣忓畢鎺掑簭___________________________ + + /// <summary> + /// 浣忓畢鎺掑簭 + /// </summary> + /// <param name="i_listHouse"></param> + /// <returns></returns> + public List<House> SortHouse(List<House> i_listHouse) + { + //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� + var listName = new List<string>(); + foreach (var house in i_listHouse) + { + listName.Add(house.Name); + } + int numberLength = this.GetNumberMaxLength(listName); + + var listSort = new List<string[]>(); + var dicHouse = new Dictionary<string, House>(); + foreach (var house in i_listHouse) + { + //涓存椂缂撳瓨 + dicHouse[house.Id] = house; + + var strArry = new string[2]; + strArry[0] = house.Id; + strArry[1] = string.Empty; + + string value = string.Empty; + foreach (var c in house.Name) + { + if (char.IsNumber(c) == true) + { + //鏁板瓧 + value += c.ToString(); + continue; + } + else if (value != string.Empty) + { + //濡傛灉鎴块棿鍚嶅瓧甯︽湁鏁板瓧鐨勮瘽,鍒欏乏杈瑰姞闆�,鍥犱负杩欓噷鏈変釜鎺掑簭鐨勯棶棰� + strArry[1] += value.PadLeft(numberLength, '0'); + value = string.Empty; + } + strArry[1] += c.ToString(); + } + if (value != string.Empty) + { + //浠ユ暟瀛楃粨灏剧殑璇� + strArry[1] += value.PadLeft(numberLength, '0'); + } + listSort.Add(strArry); + } + //鎺掑簭 + listSort.Sort((obj1, obj2) => + { + if (obj1[1].CompareTo(obj2[1]) > 0) + { + return 1; + } + return -1; + }); + var listSortHouse = new List<House>(); + foreach (var strArry in listSort) + { + listSortHouse.Add(dicHouse[strArry[0]]); + } + return listSortHouse; + } + + /// <summary> + /// 浜戠浣忓畢鎺掑簭 + /// </summary> + /// <param name="i_listData"></param> + /// <returns></returns> + public List<Common.ResponseEntity.ResidenceObj> SortHouse(List<Common.ResponseEntity.ResidenceObj> i_listData) + { + //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� + var listName = new List<string>(); + foreach (var house in i_listData) + { + listName.Add(house.Name); + } + int numberLength = this.GetNumberMaxLength(listName); + + var listSort = new List<string[]>(); + var dicHouse = new Dictionary<string, Common.ResponseEntity.ResidenceObj>(); + foreach (var house in i_listData) + { + //涓存椂缂撳瓨 + dicHouse[house.Id] = house; + + var strArry = new string[2]; + strArry[0] = house.Id; + strArry[1] = string.Empty; + + string value = string.Empty; + foreach (var c in house.Name) + { + if (char.IsNumber(c) == true) + { + //鏁板瓧 + value += c.ToString(); + continue; + } + else if (value != string.Empty) + { + //濡傛灉鎴块棿鍚嶅瓧甯︽湁鏁板瓧鐨勮瘽,鍒欏乏杈瑰姞闆�,鍥犱负杩欓噷鏈変釜鎺掑簭鐨勯棶棰� + strArry[1] += value.PadLeft(numberLength, '0'); + value = string.Empty; + } + strArry[1] += c.ToString(); + } + if (value != string.Empty) + { + //浠ユ暟瀛楃粨灏剧殑璇� + strArry[1] += value.PadLeft(numberLength, '0'); + } + listSort.Add(strArry); + } + //鎺掑簭 + listSort.Sort((obj1, obj2) => + { + if (obj1[1].CompareTo(obj2[1]) > 0) + { + return 1; + } + return -1; + }); + var listSortHouse = new List<Common.ResponseEntity.ResidenceObj>(); + foreach (var strArry in listSort) + { + listSortHouse.Add(dicHouse[strArry[0]]); + } + return listSortHouse; + } + + /// <summary> + /// 浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴� + /// </summary> + /// <param name="listText"></param> + /// <returns></returns> + private int GetNumberMaxLength(List<string> listText) + { + int maxLength = 0; + foreach (var text in listText) + { + string value = string.Empty; + foreach (var c in text) + { + if (char.IsNumber(c) == true) + { + //鏁板瓧 + value += c.ToString(); + continue; + } + else if (value != string.Empty) + { + //鍒ゆ柇鏁板瓧闀垮害 + if (maxLength <= value.Length) + { + maxLength = value.Length; + } + value = string.Empty; + } + } + //鍒ゆ柇鏁板瓧闀垮害 + if (maxLength <= value.Length) + { + maxLength = value.Length; + } + } + return maxLength; + } + +#endregion + +#region 鈻� 鍒犻櫎浣忓畢___________________________ + + /// <summary> + /// 鍒犻櫎浣忓畢 + /// </summary> + /// <param name="filePath">File path.</param> + public void DeleteHouseMemmory(string houseId) + { + string filePath = this.GetHouseFilePathByHouseId(houseId); + var delPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath)); + if (System.IO.Directory.Exists(delPath) == false) + { + return; + } + var fileList = GetHouseFileListByHomeId(houseId); + foreach (var file in fileList) + { + //鍒犻櫎鏂囦欢 + System.IO.File.Delete(System.IO.Path.Combine(delPath, file)); + } + //鍒犻櫎鏂囦欢澶� + System.IO.Directory.Delete(delPath, true); + //HomeFilePathList涓垹闄よ鍒楄〃 + Common.Config.Instance.HomeFilePathList.RemoveAll((obj) => obj == filePath); + Config.Instance.Save(); + } + +#endregion + +#region 鈻� 鑾峰彇璇ヤ綇瀹呯殑鏂囦欢鍒楄〃_______________ + + /// <summary> + /// 閫氳繃銆恏ouseId銆戣幏鍙栬浣忓畢鐨勬枃浠跺垪琛� + /// </summary> + /// <returns>The house file list by home identifier.</returns> + /// <param name="houseId">House identifier.</param> + public List<string> GetHouseFileListByHomeId(string houseId) + { + var list = new List<string> { }; + var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId); + if (!System.IO.Directory.Exists(path)) + { + return new List<string> { }; + } + var files = System.IO.Directory.GetFiles(path); + foreach (var file in files) + { + var f = file.Substring(path.Length + 1); + System.Console.WriteLine(f); + list.Add(f); + } + return list; + } + +#endregion + +#region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鑾峰彇妤煎眰鍚嶇О + /// </summary> + /// <param name="i_FloorId">妤煎眰ID</param> + /// <returns></returns> + public string GetFloorNameById(string i_FloorId) + { + if (i_FloorId == null) { return string.Empty; } + if (Config.Instance.Home.FloorDics.ContainsKey(i_FloorId) == false) + { + return string.Empty; + } + return Config.Instance.Home.FloorDics[i_FloorId]; + } + + /// <summary> + /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹卛d + /// </summary> + /// <returns>The house identifier by file path.</returns> + /// <param name="filePath">鏂囦欢璺緞</param> + public string GetHouseIdByFilePath(string filePath) + { + string[] sArray = filePath.Split(new string[] { "House_", ".json" }, StringSplitOptions.RemoveEmptyEntries); + if (sArray.Length >= 1) + { + return sArray[0]; + } + return null; + } + + /// <summary> + /// 閫氳繃銆愪綇瀹卛d銆戣幏鍙栦綇瀹呰矾寰� + /// </summary> + /// <returns>The house identifier by file path.</returns> + /// <param name="houseId">浣忓畢id</param> + public string GetHouseFilePathByHouseId(string houseId) + { + return $"House_{houseId}.json"; + } + +#endregion + +#region 鈻� 缁撴瀯浣揰____________________________ + + /// <summary> + /// 娣诲姞浣忓畢鐨勫惎鍔ㄥ弬鏁� + /// </summary> + private class AddResidencePra : IfacePraCommon + { + /// <summary> + /// RequestVersion + /// </summary> + public string RequestVersion = Common.CommonPage.RequestVersion; + /// <summary> + /// LoginAccessToken + /// </summary> + public string LoginAccessToken = Common.Config.Instance.Token; + /// <summary> + /// Name + /// </summary> + public string Name = string.Empty; + } + + /// <summary> + /// 鏂颁綇瀹呯殑淇℃伅 + /// </summary> + private class NewResidenceInfo + { + /// <summary> + /// ZigbeeHomeGuid + /// </summary> + public string Id = string.Empty; + } +#endregion + } +} -- Gitblit v1.8.0