| | |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 住宅____________________________ |
| | | |
| | | #region ◆ 添加住宅_________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加住宅 |
| | | /// </summary> |
| | | /// <param name="houseId">住宅id</param> |
| | | /// <param name="houseName">住宅名称.</param> |
| | | /// <param name="numHomeId">住宅数字型id</param> |
| | | public static void AddHouse(string houseId, string houseName, int numHomeId) |
| | | { |
| | | AddHouse(houseId, houseName, false, 0); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加住宅 |
| | | /// </summary> |
| | | /// <param name="houseId">住宅id</param> |
| | | /// <param name="houseName">住宅名称.</param> |
| | | /// <param name="isOthreShare">是否为其他主用户分享过来的住宅</param> |
| | | /// <param name="accountType">仅子账号登陆的时候使用,当【IsOthreShare】为"true",并且【AccountType】为"1"时,该账号拥有管理员权限</param> |
| | | public static void AddHouse(string houseId, string houseName, bool isOthreShare, int accountType) |
| | | { |
| | | var home = new House |
| | | { |
| | | Id = houseId, |
| | | Name = houseName, |
| | | IsOthreShare = isOthreShare, |
| | | AccountType = accountType |
| | | }; |
| | | //创建文件夹 |
| | | Global.CreateHomeDirectory(houseId); |
| | | home.Save(); |
| | | Config.Instance.HomeFilePathList.Add(home.FileName); |
| | | Config.Instance.Save(); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 删除住宅_________________________ |
| | | |
| | | /// <summary> |
| | | /// 删除住宅 |
| | | /// </summary> |
| | | /// <param name="filePath">File path.</param> |
| | | public static void DeleteHouse(string filePath) |
| | | { |
| | | 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 = GetHouseFileListByFilePath(filePath); |
| | | 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(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除住宅 |
| | | /// </summary> |
| | | /// <param name="houseId">House identifier.</param> |
| | | public static void DeleteHouseByHouseId(string houseId) |
| | | { |
| | | DeleteHouse(GetHouseFilePathByHouseId(houseId)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 修改住宅_________________________ |
| | | |
| | | /// <summary> |
| | | /// 修改住宅. |
| | | /// </summary> |
| | | /// <param name="houseId">House identifier.</param> |
| | | /// <param name="houseName">House name.</param> |
| | | public static void EditorHouseByHouseId(string houseId, string houseName) |
| | | { |
| | | if (Config.Instance.Home.Id == houseId)
|
| | | {
|
| | | Config.Instance.Home.Name = houseName;
|
| | | } |
| | | var home = GetHouseByHouseId(houseId); |
| | | if (home == null) |
| | | { |
| | | return; |
| | | } |
| | | home.Name = houseName; |
| | | home.Save();
|
| | | //住宅修改名称的话,主页需要重新刷新
|
| | | Phone.UserView.UserPage.Instance.RefreshForm = true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取住宅_________________________ |
| | | /// <summary> |
| | | /// 通过【id】获取住宅 |
| | | /// </summary> |
| | | /// <returns>The house by house identifier.</returns> |
| | | /// <param name="houseId">住宅id</param> |
| | | public static House GetHouseByHouseId(string houseId) |
| | | { |
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json"); |
| | | var file = Shared.IO.FileUtils.ReadFile(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 static House GetHouseByFilePath(string filePath) |
| | | { |
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath); |
| | | var file = Shared.IO.FileUtils.ReadFile(path); |
| | | if (file == null) |
| | | { |
| | | return null; |
| | | } |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取住宅列表_____________________ |
| | | /// <summary> |
| | | /// Gets the home lists.获取住宅列表 |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<List<string>> GetHomeLists() |
| | | { |
| | | var pageSetting = new SendDataToServer.ResidenceListPageSettingObj() |
| | | { |
| | | PageSize = CommonPage.PageSize |
| | | }; |
| | | |
| | | var reqDto = new SendDataToServer.ResidenceListObj() |
| | | { |
| | | LoginAccessToken = Config.Instance.Token, |
| | | PageSetting = pageSetting |
| | | }; |
| | | var requestObj = new SendDataToServer.ResidenceListReqDto() |
| | | { |
| | | ReqDto = reqDto, |
| | | RequestVersion = CommonPage.RequestVersion, |
| | | }; |
| | | try |
| | | {
|
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); |
| | | var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | 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) |
| | | { |
| | | //当住宅为空时先提示用户新建住宅 |
| | | var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CurrentlyTheUserIshHouseIsEmptyPleaseBuildANewHouseFirst), Language.StringByID(R.MyInternationalizationString.Close), Language.StringByID(R.MyInternationalizationString.Confrim)); |
| | | alert.Show(); |
| | | } |
| | | else |
| | | { |
| | | //清空当前住宅列表 |
| | | 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); |
| | | } |
| | | //如果切换了账号,或者原来的id不存在,则重置住宅ID |
| | | if (Config.Instance.TheSameLoginAccount == false || |
| | | Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null) |
| | | { |
| | | Config.Instance.HomeId = listHouse[0].Id; |
| | | foreach (var house in listHouse)
|
| | | {
|
| | | //初始选择它自己的住宅
|
| | | if (house.IsOthreShare == false)
|
| | | {
|
| | | Config.Instance.HomeId = house.Id;
|
| | | Config.Instance.Home = House.GetHouseByHouseId(house.Id);
|
| | | break;
|
| | | }
|
| | | } |
| | | } |
| | | Config.Instance.Save(); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"获取失败{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | } |
| | | return Config.Instance.HomeFilePathList; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取住宅id_______________________ |
| | | /// <summary> |
| | | /// 通过【文件路径】获取住宅id |
| | | /// </summary> |
| | | /// <returns>The house identifier by file path.</returns> |
| | | /// <param name="filePath">文件路径</param> |
| | | public static string GetHouseIdByFilePath(string filePath) |
| | | { |
| | | string[] sArray = filePath.Split(new string[] { "House_", ".json" }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (sArray.Length >= 1) |
| | | { |
| | | return sArray[0]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取住宅路径_____________________ |
| | | /// <summary> |
| | | /// 通过【住宅id】获取住宅路径 |
| | | /// </summary> |
| | | /// <returns>The house identifier by file path.</returns> |
| | | /// <param name="houseId">住宅id</param> |
| | | public static string GetHouseFilePathByHouseId(string houseId) |
| | | { |
| | | if (string.IsNullOrEmpty(houseId)) |
| | | { |
| | | return null; |
| | | } |
| | | return $"House_{houseId}.json"; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取该住宅的文件列表______________ |
| | | |
| | | /// <summary> |
| | | /// 通过【houseId】获取该住宅的文件列表 |
| | | /// </summary> |
| | | /// <returns>The house file list by home identifier.</returns> |
| | | /// <param name="houseId">House identifier.</param> |
| | | public static 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过【文件路径】获取住宅下文件列表 |
| | | /// </summary> |
| | | /// <returns>The house file list by file path.</returns> |
| | | /// <param name="filePath">File path.</param> |
| | | public static List<string> GetHouseFileListByFilePath(string filePath) |
| | | { |
| | | return GetHouseFileListByHomeId(GetHouseIdByFilePath(filePath)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 楼层____________________________ |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | get |
| | | { |
| | | return GetFloorNameById(CurrentFloorId); |
| | | return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取楼层名称 |
| | | /// </summary> |
| | | /// <param name="floorId"></param> |
| | | /// <returns></returns> |
| | | public string GetFloorNameById(string floorId) |
| | | { |
| | | if (Config.Instance.Home.FloorDics.Count == 0) |
| | | { |
| | | return string.Empty; |
| | | } |
| | | |
| | | foreach (var floor in Config.Instance.Home.FloorDics) |
| | | { |
| | | if (floorId == floor.Key) |
| | | { |
| | | return floor.Value; |
| | | } |
| | | }
|
| | | return string.Empty; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 房间____________________________ |
| | | |
| | | #region ◆ 添加房间路径_________________________ |
| | | |
| | |
| | | Save(); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion |
| | | |