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