using System; using System.Collections.Generic; using Shared.Phone.UserCenter; namespace Shared.Common { /// /// 住宅文件 /// [System.Serializable] public class House { #region ◆ 变量____________________________ /// /// 住宅文件 /// /// The file path. [Newtonsoft.Json.JsonIgnore] public string FileName { get { return $"House_{Id}.json"; } } /// /// 住宅id--使用云端提供的住宅唯一Id /// public string Id = string.Empty; /// /// 住宅名称 /// public string Name = string.Empty; /// /// 是否为其他主用户分享过来的住宅 /// public bool IsOthreShare; /// /// 当前住宅是其他主帐号分享过来的主帐号的分布式Id /// public string MainUserDistributedMark; /// /// 该住宅是否是虚拟的,true的话代表网关和设备都是虚拟的(默认为false) /// public bool IsVirtually = false; /// /// 仅子账号登陆的时候使用,当【IsOthreShare】为"true",并且【AccountType】为"1"时,该账号拥有管理员权限 /// public int AccountType; /// /// 经度 /// public double Longitude = 0; /// /// 纬度 /// public double Latitude = 0; /// /// 住宅所在的地理位置的名称 /// public string ResidenceAddressName = string.Empty; /// /// 房间列表(房间的ID) /// public List ListRooms = new List(); /// /// 楼层字典 /// key:FloorId /// value:FloorName /// public Dictionary FloorDics = new Dictionary { }; /// /// 当前楼层Id /// public string CurrentFloorId = string.Empty; #endregion #region ◆ 楼层____________________________ /// /// GetCurrentFloorName /// /// [Newtonsoft.Json.JsonIgnore] public string GetCurrentFloorName { get { return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId); } } /// /// 设置当前楼层的ID /// public void SetCurrentFloorId() { 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 ◆ 添加房间路径_________________________ /// /// 添加房间ID /// /// true, if room list file path was added, false otherwise. /// Room file path. public void AddRoomId(string roomId) { if (ListRooms.Contains(roomId) == false) { ListRooms.Add(roomId); this.Save(); } } #endregion #region ◆ 删除房间路径_________________________ /// /// 移除房间Id /// /// true, if room list file path was added, false otherwise. /// Room file path. public void RemoveRoomId(string roomId) { if (ListRooms.Contains(roomId)==true) { ListRooms.Remove(roomId); Save(); } } #endregion #region ◆ 保存____________________________ /// /// 保存 /// /// 是否备份 public void Save(bool autoBackup = true) { 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))); if (autoBackup == true && Id == Config.Instance.HomeId) { HdlAutoBackupLogic.AddOrEditorFile(FileName); } } #endregion } }