陈嘉乐
2020-09-02 652243206427f35a256400a149a1734085824cb9
ZigbeeApp/Shared/Common/House.cs
@@ -60,19 +60,63 @@
        /// </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
        /// -1:未配置(需要重新选择) 1:无模板有设备  2:有模板有设备  3:无模板无设备(请无视这个变量)
        /// </summary>
        public string CurrentFloorId = string.Empty;
        public int TemplateMode = -1;
        /// <summary>
        /// 该住宅是否是展示模板(此变量是给查看模板数据时使用的,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public bool IsShowTemplate = false;
        /// <summary>
        /// 当前住宅选择的模板名字(请无视这个变量)
        /// </summary>
        public string SelectTemplate = string.Empty;
        /// <summary>
        /// 自定义单元的标题名称(与ListUintContent个数匹配,请无视这个变量)
        /// </summary>
        public List<string> ListUintName = new List<string>();
        /// <summary>
        /// 自定义单元的内容(与ListUintName个数匹配,请无视这个变量)
        /// </summary>
        public List<string> ListUintContent = new List<string>();
        /// <summary>
        /// 最后编辑的事件(2020.05.26追加) 1970/12/31 23:59格式
        /// </summary>
        public string LastEditorTime = "1970/12/31 23:59";
        /// <summary>
        /// 标识此住宅的数据是否已经发送过模板数据给网关(只针对TemplateMode=2,请无视这个变量)
        /// </summary>
        public bool SendTemplateSuccess = false;
        /// <summary>
        /// 这个住宅下所拥有的网关id(2020.05.26追加,null代表没有处理过,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<string> listGatewayId = null;
        /// <summary>
        /// <para>标识住宅数据的区分(文件读取时配置,请无视这个变量):</para>
        /// <para>1:本身自己的数据(文件夹名字为住宅id)</para>
        /// <para>2:自己手动创建的保存在本机的备份(文件夹名字以【BackupResidenceData】开头)</para>
        /// <para>3:此数据从云端下载而来(文件夹名字以【DownLoadResidenceData】开头)</para>
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int HouseDataDiv = 1;
        /// <summary>
        /// 当前住宅的在线状态 -1:虚拟 0:离线 1:本地 2:远程 3:读取中(请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string NowHomeOnlineStatu = "3";
        /// <summary>
        /// 当前存放住宅数据的文件夹名字(此变量是给本机备份,或者云端下载备份使用的,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string SaveDirctoryName = string.Empty;
        #endregion
@@ -86,61 +130,43 @@
        public string GetCurrentFloorName
        {
            get
            {
            {
                return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId);
            }
        }
        }
        /// <summary>
        /// 当前楼层id
        /// </summary>
        private string m_CurrentFloorId = string.Empty;
        /// <summary>
        /// 设置当前楼层的ID
        /// 当前楼层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)
        [Newtonsoft.Json.JsonIgnore]
        public string CurrentFloorId
        {
            //来回切换备份,会出现问题,楼层id没清除
            get
            {
                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();
            }
                //没有楼层
                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; }
        }
        #endregion
@@ -153,6 +179,13 @@
        /// <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))
@@ -160,7 +193,8 @@
                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);