| | |
| | | return $"House_{Id}.json"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 住宅id--使用云端提供的住宅唯一Id |
| | | /// </summary> |
| | | public string Id = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 住宅名称 |
| | | /// </summary> |
| | | public string Name = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 是否为其他主用户分享过来的住宅 |
| | | /// </summary> |
| | |
| | | /// 当前住宅是其他主帐号分享过来的主帐号的分布式Id
|
| | | /// </summary>
|
| | | public string MainUserDistributedMark; |
| | | |
| | | /// <summary>
|
| | | /// 该住宅是否是虚拟的,true的话代表网关和设备都是虚拟的(默认为false)
|
| | | /// </summary> |
| | | public bool IsVirtually = false; |
| | | /// <summary> |
| | | /// 仅子账号登陆的时候使用,当【IsOthreShare】为"true",并且【AccountType】为"1"时,该账号拥有管理员权限 |
| | | /// </summary> |
| | |
| | | /// 纬度
|
| | | /// </summary>
|
| | | public double Latitude = 0; |
| | | |
| | | /// <summary> |
| | | /// 房间路径列表 |
| | | /// <summary>
|
| | | /// 住宅所在的地理位置的名称
|
| | | /// </summary> |
| | | public List<string> RoomFilePathList = new List<string> { }; |
| | | |
| | | public string ResidenceAddressName = string.Empty; |
| | | /// <summary> |
| | | /// 楼层字典 |
| | | /// key:FloorId |
| | |
| | | /// </summary> |
| | | public Dictionary<string,string> FloorDics = new Dictionary<string,string> { }; |
| | | /// <summary> |
| | | /// 当前楼层Id |
| | | /// -1:未配置(需要重新选择) 1:无模板有设备 2:有模板有设备 3:无模板无设备(请无视这个变量) |
| | | /// </summary> |
| | | public string CurrentFloorId; |
| | | |
| | | public int TemplateMode = -1; |
| | | /// <summary> |
| | | /// 全局场景路径列表---备用 |
| | | /// 该住宅是否是展示模板(此变量是给查看模板数据时使用的,请无视这个变量) |
| | | /// </summary> |
| | | public List<string> SceneFilePathList = new List<string> { }; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsShowTemplate = false; |
| | | /// <summary> |
| | | /// 设备路径列表---备用 |
| | | /// 当前住宅选择的模板名字(请无视这个变量) |
| | | /// </summary> |
| | | public List<string> DeviceFilePathList = new List<string> { }; |
| | | public string SelectTemplate = string.Empty; |
| | | /// <summary> |
| | | /// 功能路径列表---备用 |
| | | /// 自定义单元的标题名称(与ListUintContent个数匹配,请无视这个变量) |
| | | /// </summary> |
| | | public List<string> FunctionFilePathList = new List<string> { }; |
| | | public List<string> ListUintName = new List<string>(); |
| | | /// <summary> |
| | | /// 通用标识--备用 |
| | | /// 自定义单元的内容(与ListUintName个数匹配,请无视这个变量) |
| | | /// </summary> |
| | | public object Tag; |
| | | public List<string> ListUintContent = new List<string>(); |
| | | /// <summary> |
| | | /// 期、栋、层等区域---备用 |
| | | /// 最后编辑的事件(2020.05.26追加) 1970/12/31 23:59格式 |
| | | /// </summary> |
| | | public Dictionary<string, string> LocationInfoList = new Dictionary<string, string> { }; |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 住宅____________________________ |
| | | |
| | | #region ◆ 添加住宅_________________________ |
| | | |
| | | public string LastEditorTime = "1970/12/31 23:59"; |
| | | /// <summary> |
| | | /// 添加住宅 |
| | | /// 标识此住宅的数据是否已经发送过模板数据给网关(只针对TemplateMode=2,请无视这个变量) |
| | | /// </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); |
| | | } |
| | | |
| | | public bool SendTemplateSuccess = false; |
| | | /// <summary> |
| | | /// 添加住宅 |
| | | /// 这个住宅下所拥有的网关id(2020.05.26追加,null代表没有处理过,请无视这个变量) |
| | | /// </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 ◆ 删除住宅_________________________ |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<string> listGatewayId = null; |
| | | /// <summary> |
| | | /// 删除住宅 |
| | | /// <para>标识住宅数据的区分(文件读取时配置,请无视这个变量):</para> |
| | | /// <para>1:本身自己的数据(文件夹名字为住宅id)</para> |
| | | /// <para>2:自己手动创建的保存在本机的备份(文件夹名字以【BackupResidenceData】开头)</para> |
| | | /// <para>3:此数据从云端下载而来(文件夹名字以【DownLoadResidenceData】开头)</para> |
| | | /// </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(); |
| | | } |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int HouseDataDiv = 1; |
| | | /// <summary> |
| | | /// 删除住宅 |
| | | /// 当前住宅的在线状态 -1:虚拟 0:离线 1:本地 2:远程 3:读取中(请无视这个变量) |
| | | /// </summary> |
| | | /// <param name="houseId">House identifier.</param> |
| | | public static void DeleteHouseByHouseId(string houseId) |
| | | { |
| | | DeleteHouse(GetHouseFilePathByHouseId(houseId)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 修改住宅_________________________ |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string NowHomeOnlineStatu = "3"; |
| | | /// <summary> |
| | | /// 修改住宅. |
| | | /// 当前存放住宅数据的文件夹名字(此变量是给本机备份,或者云端下载备份使用的,请无视这个变量) |
| | | /// </summary> |
| | | /// <param name="houseId">House identifier.</param> |
| | | /// <param name="houseName">House name.</param> |
| | | public static void EditorHouseByHouseId(string houseId, string houseName) |
| | | { |
| | | var home = GetHouseByHouseId(houseId); |
| | | if (home == null) |
| | | { |
| | | return; |
| | | } |
| | | home.Name = houseName; |
| | | home.Save(); |
| | | Config.Instance.Save(); |
| | | } |
| | | |
| | | #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(); |
| | | alert.ResultEventHandler += (sender, e) => |
| | | { |
| | | if (e) |
| | | { |
| | | // |
| | | } |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | //清空当前住宅列表 |
| | | Config.Instance.HomeFilePathList.Clear(); |
| | | if (Config.Instance.HomeId == string.Empty && responseDataObj.PageData.Count > 0) |
| | | { |
| | | //赋一个初始值 |
| | | Config.Instance.HomeId = responseDataObj.PageData[0].Id; |
| | | } |
| | | 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); |
| | | } |
| | | //匹配当前住宅 |
| | | if (Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null) |
| | | { |
| | | Config.Instance.HomeId = GetHouseIdByFilePath(Config.Instance.HomeFilePathList[0]); |
| | | } |
| | | 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 |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string SaveDirctoryName = string.Empty; |
| | | |
| | | #endregion |
| | | |
| | |
| | | /// GetCurrentFloorName |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string GetCurrentFloorName |
| | | { |
| | | get |
| | | { |
| | | return GetFloorNameById(CurrentFloorId); |
| | | {
|
| | | return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId); |
| | | } |
| | | } |
| | | |
| | | }
|
| | | /// <summary>
|
| | | /// 当前楼层id
|
| | | /// </summary>
|
| | | private string m_CurrentFloorId = string.Empty;
|
| | | /// <summary> |
| | | /// 获取楼层名称 |
| | | /// 当前楼层Id |
| | | /// </summary> |
| | | /// <param name="floorId"></param> |
| | | /// <returns></returns> |
| | | public string GetFloorNameById(string floorId) |
| | | { |
| | | if (Config.Instance.Home.FloorDics.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | foreach (var floor in Config.Instance.Home.FloorDics) |
| | | { |
| | | if (floorId == floor.Key) |
| | | { |
| | | return floor.Value; |
| | | } |
| | | } |
| | | return null; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string CurrentFloorId
|
| | | {
|
| | | //来回切换备份,会出现问题,楼层id没清除
|
| | | get
|
| | | {
|
| | | //没有楼层
|
| | | if (this.FloorDics.Count == 0) { return string.Empty; }
|
| | |
|
| | | if (this.FloorDics.ContainsKey(m_CurrentFloorId) == true)
|
| | | {
|
| | | //当前的楼层id没问题
|
| | | return m_CurrentFloorId;
|
| | | }
|
| | | //如果当前设置的楼层id并不存在的话,重新设置
|
| | | m_CurrentFloorId = string.Empty;
|
| | | var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
|
| | | foreach (var floorId in dicFloor.Keys)
|
| | | {
|
| | | //给一个过去即可
|
| | | m_CurrentFloorId = floorId;
|
| | | break;
|
| | | }
|
| | | return m_CurrentFloorId;
|
| | | }
|
| | | set { m_CurrentFloorId = value; }
|
| | | } |
| | | /// <summary> |
| | | /// InitFloor |
| | | /// </summary> |
| | | public void InitFloor() |
| | | { |
| | | if (Config.Instance.Home.FloorDics.Count > 0 && string.IsNullOrEmpty(CurrentFloorId)) |
| | | { |
| | | foreach (var floor in Config.Instance.Home.FloorDics) |
| | | { |
| | | CurrentFloorId = floor.Key; |
| | | Save(false); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 房间____________________________ |
| | | |
| | | #region ◆ 添加房间路径_________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加【房间路径】到房间路径列表 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns> |
| | | /// <param name="roomFilePath">Room file path.</param> |
| | | public bool AddRoomListFilePath(string roomFilePath) |
| | | { |
| | | if (RoomFilePathList.Contains(roomFilePath)) |
| | | { |
| | | return false; |
| | | } |
| | | RoomFilePathList.Add(roomFilePath); |
| | | Save(); |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 删除房间路径_________________________ |
| | | |
| | | /// <summary> |
| | | /// 移除房间路径 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns> |
| | | /// <param name="roomFilePath">Room file path.</param> |
| | | public bool RemoveRoomListFilePath(string roomFilePath) |
| | | { |
| | | if (!RoomFilePathList.Contains(roomFilePath)) |
| | | { |
| | | return false; |
| | | } |
| | | RoomFilePathList.Remove(roomFilePath); |
| | | Save(); |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | |
| | | /// <param name="autoBackup">是否备份</param> |
| | | public void Save(bool autoBackup = true) |
| | | { |
| | | //如果当前是展示模板,则不允许保存 |
| | | if (this.IsShowTemplate == true) |
| | | { |
| | | return; |
| | | } |
| | | //修改时间 |
| | | this.LastEditorTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); |
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, Id); |
| | | //如果没有存在住宅目录,先创建 |
| | | if (!System.IO.Directory.Exists(path)) |
| | |
| | | System.IO.Directory.CreateDirectory(path); |
| | | } |
| | | path = System.IO.Path.Combine(path, FileName); |
| | | Shared.IO.FileUtils.WriteFileByBytes(path, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | HdlFileLogic.Current.SaveFileContent(path, this); |
| | | |
| | | if (autoBackup == true && Id == Config.Instance.HomeId) |
| | | { |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |