From a5b3c4bae726ef6770d4bfcbf2f4b50a37ed4a15 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期五, 06 三月 2020 15:31:36 +0800 Subject: [PATCH] 删除了郭雪城的 DeviceUi 这个类 --- ZigbeeApp/Shared/Common/Room.cs | 1712 +--------------------------------------------------------- 1 files changed, 35 insertions(+), 1,677 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs index 02204db..c17db61 100755 --- a/ZigbeeApp/Shared/Common/Room.cs +++ b/ZigbeeApp/Shared/Common/Room.cs @@ -12,61 +12,48 @@ /// </summary> [System.Serializable] public class Room - { - #region 鈼� 鍙橀噺____________________________ + { + #region 鈻� 鍙橀噺澹版槑___________________________ /// <summary> - /// 鎴块棿鏂囦欢 + /// 鏄惁鏄枩鐖辨埧闂� /// </summary> - /// <value>The name of the file.</value> [Newtonsoft.Json.JsonIgnore] - public string FileName + public bool IsLove { get { - return $"Room_{Id}.json"; + return Id == "Favorite"; } + } + /// <summary> + /// 鎴块棿鏂囦欢 + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string FileName + { + get + { + return $"Room_{Id}.json"; + } } + /// <summary> /// 鎴块棿id--浣跨敤guid - /// Guid.NewGuid().ToString() /// </summary> public string Id = Guid.NewGuid().ToString(); - /// <summary> - /// 妤煎眰Id - /// 鏂板鏃朵娇鐢℅uid - /// </summary> - public string FloorId = string.Empty; - /// <summary> - /// 妤煎眰鍚嶇О - /// </summary> - public string FloorName - { - get - { - return Config.Instance.Home.GetFloorNameById(FloorId); - } - } /// <summary> /// 鎴块棿鍚� /// </summary> public string Name = string.Empty; - /// <summary> /// 鎴块棿鑳屾櫙鍥� /// </summary> public string BackgroundImage = string.Empty; - /// <summary> /// 鍥剧墖鏉ユ簮 0--鏈湴鍥惧簱 1--鎷嶇収 2--绯荤粺鍥惧簱 /// </summary> public int BackgroundImageType = 0; - - /// <summary> - /// 妤煎眰--澶囩敤 - /// </summary> - public Dictionary<string, string> FloorList = new Dictionary<string, string> { }; - /// <summary> /// 娓╁害浼犳劅鍣�(璁惧涓婚敭) /// </summary> @@ -82,1673 +69,44 @@ /// <summary> /// 婀垮害 /// </summary> - public decimal Humidity; - - /// <summary> - /// 褰撳墠閫夋嫨鐨勬埧闂� - /// </summary> - private static Room m_CurrentRoom = null; - /// <summary> - /// 褰撳墠閫夋嫨鐨勬埧闂� - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public static Room CurrentRoom - { - get - { - if (m_CurrentRoom == null && Lists.Count > 0) - { - if (m_CurrentRoom == null) { m_CurrentRoom = Lists[0]; } - return Lists[0]; - } - return m_CurrentRoom; - } - set { m_CurrentRoom = value; } - } - - /// <summary> - /// 鎴块棿閲屾墍鏈夌殑璁惧鍒楄〃 - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<DeviceUI> DeviceUIList = new List<DeviceUI> { }; - /// <summary> - ///璁惧鏂囦欢璺緞鍒楄〃 - /// </summary> - public readonly List<string> DeviceUIFilePathList = new List<string>(); - - /// <summary> - /// 鍠滅埍鎴块棿id - /// </summary> - public const string LoveRoomId= "Favorite"; - - /// <summary> - /// 鏄惁鏄粯璁ゅ枩鐖辨埧闂� - /// </summary> - /// <value><c>true</c> if is love; otherwise, <c>false</c>.</value> - [Newtonsoft.Json.JsonIgnore] - public bool IsLove - { - get - { - return Id == LoveRoomId; - } - } - + public decimal Humidity; /// <summary> /// 鏄惁鏄垎浜繃鏉ョ殑鎴块棿 /// 娉細鍒嗕韩杩囨潵鐨勬埧闂翠笉鑳藉垹闄わ紝涓嶈兘缂栬緫璇ユ埧闂达紝涓嶈兘瀵硅澶囷紙鍔熻兘锛夈�佸満鏅繘琛屽鍒犳敼 /// </summary> - public bool IsSharedRoom = false; - + public bool IsSharedRoom = false; /// <summary> - /// 鑾峰彇鍠滅埍鎴块棿鐨勬墍鏈夎澶囪矾寰� + /// 妤煎眰Id /// </summary> - /// <value>The love room device list.</value> - [Newtonsoft.Json.JsonIgnore] - public static List<string> LoveRoomDeviceUIFilePathList - { - get - { - if (Lists.Count == 0) - { - return new List<string> { }; - } - return CurrentRoom.GetLoveRoom().DeviceUIFilePathList; - } - } - - /// <summary> - /// 鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨� - /// </summary> - /// <value>All room device type list.</value> - [Newtonsoft.Json.JsonIgnore] - public static List<DeviceType> AllRoomDeviceTypeList - { - get - { - var typeList = new List<DeviceType> { }; - foreach (var deviceUI in AllRoomDeviceUIList) - { - if (deviceUI == null || deviceUI.CommonDevice == null) - { - continue; - } - if (!typeList.Contains(deviceUI.CommonDevice.Type)) - { - typeList.Add(deviceUI.CommonDevice.Type); - } - } - return typeList; - } - } - - /// <summary> - /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夊満鏅� - /// </summary> - /// <value>All room scene UIL ist.</value> - [Newtonsoft.Json.JsonIgnore] - public static List<SceneUI> AllRoomSceneUIList - { - get - { - var sceneList = new List<SceneUI> { }; - foreach (var r in Shared.Common.Room.Lists) - { - if(r.IsLove) - { - continue; - } - if (r.SceneUIList.Count == 0) - { - continue; - } - foreach (var sceneUI in r.SceneUIList) - { - if (sceneUI == null) - { - continue; - } - sceneList.Add(sceneUI); - } - } - return sceneList; - } - } - - /// <summary> - /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夊満鏅矾寰� - /// </summary> - /// <value>All room scene UIL ist.</value> - [Newtonsoft.Json.JsonIgnore] - public List<string> AllRoomSceneUIFilepathList - { - get - { - var pathList = new List<string> { }; - foreach (var r in Lists) - { - if(r.IsLove) - { - continue; - } - - if (r.SceneUIFilePathList.Count == 0) - { - continue; - } - foreach (var path in r.SceneUIFilePathList) - { - pathList.Add(path); - } - } - return pathList; - } - } - - /// <summary> - /// 鍦烘櫙鍒楄〃---涓嶅啀搴忓垪鍖� - /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<SceneUI> SceneUIList = new List<SceneUI> { }; - /// <summary> - ///鍦烘櫙鏂囦欢鍒楄〃 - /// </summary> - public readonly List<string> SceneUIFilePathList = new List<string>(); - - /// <summary> - /// 鎵�鏈夌殑鎴块棿淇℃伅 - /// </summary> - public static List<Room> Lists = new List<Room>(); - - /// <summary> - /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - /// </summary> - /// <value>All room device UIL ist.</value> - [Newtonsoft.Json.JsonIgnore] - public static List<DeviceUI> AllRoomDeviceUIList - { - get - { - List<DeviceUI> deviceList = new List<DeviceUI>(); - for (int i = 0; i < Lists.Count; i++) - { - var room = Lists[i]; - if (room.IsSharedRoom || room.IsLove) - { - continue; - } - if (room.DeviceUIList.Count == 0) - { - continue; - } - for (int j = 0; j < room.DeviceUIList.Count; j++) - { - var device = room.DeviceUIList[j]; - if (device == null || device.CommonDevice == null) - { - continue; - } - if (deviceList.Find((obj) => obj.FileName == device.FileName) == null) - { - deviceList.Add(device); - } - } - } - return deviceList; - } - } - - #endregion - - #region 鈼� 鏋勯�犳柟娉昣_______________________ - - /// <summary> - /// 鏋勯�犳柟娉� - /// </summary> - static Room() - { - InitAllRoom(); - } - - #endregion - - #region 鈼� 鍒濆鍖朹_________________________ - - /// <summary> - /// 鍒濆鍖栨埧闂翠俊鎭� - /// 浠庢枃浠朵腑鍏ㄩ儴璇诲彇鎵�鏈夌殑鎴块棿鏁版嵁鍒板唴瀛� - /// </summary> - public static void InitAllRoom() - { - Lists.Clear(); - if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false) - { - //榛樿娣诲姞鍠滅埍鐨勬埧闂�--绂佹淇敼鎴块棿鍚� - var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "RoomIcon/0.JPG", Id = LoveRoomId }; - love.Save(false); - //娣诲姞鍒癶ouse 鎴块棿璺緞鍒楄〃 - var currentHome = Config.Instance.Home; - currentHome.RoomFilePathList.Insert(0, love.FileName); - currentHome.Save(false); - } - foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList) - { - var room = GetRoomByFilePath(roomFilePath); - - if (null != room) - { - if (room.IsSharedRoom) - { - room.Name = $"{room.Name}"; - } - Lists.Add(room); - - } - } - - Config.Instance.Home.InitFloor(); - - CurrentRoom.RefreshRoomListView(); - } - - /// <summary> - /// 鍒锋柊鎴块棿瑙嗗浘鍒楄〃 - /// </summary> - public void RefreshRoomListView() - { - Application.RunOnMainThread(() => - { - Phone.Device.Room.RoomManagement.Instance.Show(); - }); - } - - /// <summary> - /// 浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿 - /// </summary> - public static void RefreshAllRoomByLocation() - { - var homeTemp = Config.Instance.Home; - homeTemp.RoomFilePathList.Clear(); - - var listFile = Global.FileListByHomeId(); - - //鎴戠殑鍠滅埍鐨勬埧闂村繀椤昏鍦ㄧ0浣嶆墠琛� - string fRoom = "Room_Favorite.json"; - if (listFile.Contains(fRoom) == true) - { - listFile.Remove(fRoom); - homeTemp.RoomFilePathList.Add(fRoom); - } - - var listRoomFile = new List<string>(); - foreach (string fileName in listFile) - { - if (fileName.StartsWith("Room_")) - { - homeTemp.RoomFilePathList.Add(fileName); - listRoomFile.Add(fileName); - } - } - //妫�娴嬫ゼ灞傛暟鎹殑鍚堟硶鎬� - CheckFloorData(listRoomFile); - - homeTemp.Save(false); - InitAllRoom(); - } - - /// <summary> - /// 妫�娴嬫ゼ灞傛暟鎹殑鍚堟硶鎬� - /// </summary> - /// <param name="listRoomFile"></param> - private static void CheckFloorData(List<string> listRoomFile) - { - for (int i = 0; i < listRoomFile.Count; i++) - { - try - { - var byteData = Global.ReadFileByHomeId(listRoomFile[i]); - string valueData = System.Text.Encoding.UTF8.GetString(byteData); - var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData); - - //妫�娴嬪涓墜鏈烘潵鍥炲垱寤�,鐒跺悗鍙堝垹闄や箣鍚�,妤煎眰鏁版嵁涓嶈兘淇濊瘉100%鍚屾鐨勯棶棰� - if (roomTemp.FloorId != string.Empty && Config.Instance.Home.FloorDics.ContainsKey(roomTemp.FloorId) == false) - { - //鏈煡妤煎眰 - Config.Instance.Home.FloorDics[roomTemp.FloorId] = Language.StringByID(R.MyInternationalizationString.uUnKnownFloor); - } - } - catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } - } - } - - #endregion - - #region 鈼� 娣诲姞鎴块棿_________________________ - - /// <summary> - /// 澧炲姞鎴块棿 - /// </summary> - /// <returns><c>true</c>, if room was added, <c>false</c> otherwise.</returns> - /// <param name="room">Room.</param> - public bool AddRoom(Room room) - { - if (string.IsNullOrEmpty(room.FileName) || Global.IsExistsByHomeId(room.FileName)) - { - return false; - } - if (Config.Instance.Home.RoomFilePathList.Contains(room.FileName)) - { - return false; - } - Lists.Add(room); - var r = Config.Instance.Home.AddRoomListFilePath(room.FileName); - if (r == false) - { - return false; - } - Save(); - HdlAutoBackupLogic.AddOrEditorFile(room.FileName); - CurrentRoom.RefreshRoomListView(); - return true; - } - - #endregion - - #region 鈼� 鍒犻櫎鎴块棿_________________________ - - /// <summary> - /// 鍒犻櫎鎴块棿 - /// </summary> - public bool Remove(string roomFilePath) - { - var room = GetRoomByFilePath(roomFilePath); - if (null == room) - { - return false; - } - //鍒犻櫎鏉ヨ嚜鎷嶇収鎴栬�呯郴缁熷浘搴撶殑鎴块棿鑳屾櫙鍥剧墖 - if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2) - { - //鍒犻櫎鎺夊師鏉ョ殑鑷畾涔夊浘鐗� - if (Global.IsExistsByHomeId(room.BackgroundImage) == true) - { - Global.DeleteFilebyHomeId(room.BackgroundImage); - //鍒犻櫎澶囦唤 - HdlAutoBackupLogic.DeleteFile(room.BackgroundImage); - } - } - //鎴戠殑鍠滅埍 - var loveRoom = this.GetLoveRoom(); - if (loveRoom != null) - { - //绉婚櫎鎴戠殑鍠滅埍閲岄潰鐨勮澶� - for (int i = 0; i < room.DeviceUIFilePathList.Count; i++) - { - loveRoom.DeviceUIFilePathList.Remove(room.DeviceUIFilePathList[i]); - loveRoom.DeviceUIList.RemoveAll((obj) => { return room.DeviceUIFilePathList[i] == obj.FileName; }); - } - //绉婚櫎鎴戠殑鍠滅埍閲岄潰鐨勫満鏅� - for (int i = 0; i < room.SceneUIFilePathList.Count; i++) - { - loveRoom.SceneUIFilePathList.Remove(room.SceneUIFilePathList[i]); - loveRoom.SceneUIList.RemoveAll((obj) => { return room.SceneUIFilePathList[i] == obj.FileName; }); - } - loveRoom.Save(false); - } - - if (Global.IsExistsByHomeId(roomFilePath) == false) - { - return false; - } - Config.Instance.Home.RemoveRoomListFilePath(roomFilePath); - //鍒犻櫎鏂囦欢 - Global.DeleteFilebyHomeId(roomFilePath); - Lists.Remove(room); - HdlAutoBackupLogic.DeleteFile(roomFilePath); - - CurrentRoom.RefreshRoomListView(); - - return true; - } - - #endregion - - #region 鈼� 鑾峰彇鎴块棿________________________ - - /// <summary> - /// 鑾峰彇鍠滅埍鎴块棿 - /// </summary> - /// <returns></returns> - public Room GetLoveRoom() - { - return CurrentRoom.GetRoomById(LoveRoomId); - } - - /// <summary> - /// 閫氳繃璺緞鑾峰彇鎴块棿 - /// </summary> - /// <returns>The room by file path.</returns> - /// <param name="roomFilePath">Room file path.</param> - public static Room GetRoomByFilePath(string roomFilePath) - { - try - { - var roomFile = Global.ReadFileByHomeId(roomFilePath); - var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(System.Text.Encoding.UTF8.GetString(roomFile)); - - if (null == nowRoom) - { - System.Console.WriteLine("鎴块棿鏂囦欢璺緞涓嶅锛屾枃浠惰矾寰勪负锛�" + roomFilePath); - return null; - } - - var beforeRoom = Lists.Find((obj) => obj.Id == nowRoom.Id); - if (beforeRoom != null) - { - var tempDeviceUIList = new List<DeviceUI>(); - tempDeviceUIList.AddRange(beforeRoom.DeviceUIList); - var tempSceneUIList = new List<SceneUI>(); - tempSceneUIList.AddRange(beforeRoom.SceneUIList); - //璁惧锛坉eviceUI锛� - beforeRoom.DeviceUIList.Clear(); - foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList) - { - beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath)); - } - //鍦烘櫙(SceneUI) - beforeRoom.SceneUIList.Clear(); - foreach (var sceneFilePath in beforeRoom.SceneUIFilePathList) - { - var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneFilePath)); - var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); - if (tempSceneUI != null) - { - var scene = tempSceneUIList.Find((obj) => obj.FileName == tempSceneUI.FileName); - if (scene != null) - { - beforeRoom.SceneUIList.Add(scene); - } - else - { - beforeRoom.AddScene(scene); - } - } - } - - return beforeRoom; - } - - //璁惧锛坉eviceUI锛� - nowRoom.DeviceUIList.Clear(); - foreach (var deviceFilePath in nowRoom.DeviceUIFilePathList) - { - var tempCommon = LocalDevice.Current.GetDeviceUI(deviceFilePath); - if (tempCommon == null || tempCommon.CommonDevice == null) - { - continue; - } - nowRoom.DeviceUIList.Add(tempCommon); - } - //鍦烘櫙(SceneUI) - nowRoom.SceneUIList.Clear(); - foreach (var sceneUIFilePath in nowRoom.SceneUIFilePathList) - { - var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneUIFilePath)); - var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); - if (tempScene == null) - { - continue; - } - nowRoom.SceneUIList.Add(tempScene); - } - return nowRoom; - } - catch(Exception ex) - { - return null; - } - } - - /// <summary> - /// 鏍规嵁鎴块棿Id锛岃幏鍙栨埧闂村璞� - /// </summary> - /// <returns>The room by name.</returns> - /// <param name="roomId">鎴块棿ID</param> - public Room GetRoomById(string roomId) - { - if (string.IsNullOrEmpty(roomId)) - { - return null; - } - return Lists.Find((obj) => obj.Id == roomId); - } - - /// <summary> - /// 鏍规嵁鎴块棿鍚嶅瓧锛岃幏鍙栨埧闂村璞� - /// </summary> - /// <returns>The room by name.</returns> - /// <param name="roomName">鎴块棿鍚�</param> - public Room GetRoomByName(string roomName) - { - return Lists.Find((obj) => obj.Name == roomName); - } - - /// <summary> - /// 鏍规嵁璁惧鑾峰彇鎴块棿鍚嶅瓧(妤煎眰+鎴块棿鍚�) - /// </summary> - /// <returns>鎴块棿鍚�</returns> - /// <param name="device">璁惧瀵硅薄</param> - public string GetRoomNameByDevice(CommonDevice device) - { - var room = this.GetRoomByDevice(device); - if (room == null) - { - //鏈垎閰嶅尯鍩� - return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); - } - if (Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true) - { - //(妤煎眰+鎴块棿鍚�) - return Config.Instance.Home.FloorDics[room.FloorId] + " " + room.Name; - } - return room.Name; - } - - /// <summary> - /// 鑾峰彇璁惧鎵�鍦ㄧ殑鎴块棿 - /// </summary> - /// <returns>The room by device.</returns> - /// <param name="device">璁惧瀵硅薄</param> - public Room GetRoomByDevice(CommonDevice device) - { - string deviceFile = device.FilePath; - return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile)); - } - - /// <summary> - /// 閫氳繃鍦烘櫙id鑾峰彇鎴块棿鍚� - /// </summary> - /// <returns>The room name by scene identifier.</returns> - /// <param name="sceneId">Scene identifier.</param> - public string GetRoomNameBySceneId(int sceneId) - { - var room = GetRoomBySceneId(sceneId); - if (room == null) - { - return null; - } - return room.Name; - } - - /// <summary> - /// 閫氳繃鍦烘櫙id鑾峰彇鎴块棿瀵硅薄 - /// </summary> - /// <returns>The room by scene identifier.</returns> - /// <param name="sceneId">Scene identifier.</param> - public Room GetRoomBySceneId(int sceneId) - { - foreach (var r in Lists) - { - if(r.IsLove) - { - continue; - } - foreach (var scene in r.SceneUIList) - { - if (scene.Id == sceneId) - { - return r; - } - } - } - return null; - } - - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂� - /// </summary> - /// <param name="id"></param> - /// <returns></returns> - public List<Room> GetRoomsByFloorId(string id) - { - try - { - if (Lists == null || Lists.Count == 0 || Lists.Count == 1) - { - return null; - } - if (Config.Instance.Home.FloorDics.Count == 0) - { - return Lists; - } - return Lists.FindAll((obj) => obj.FloorId == id); - } - catch(Exception ex) - { - System.Console.WriteLine(ex.Message); - return null; - } - - } - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂村悕绉� - /// </summary> - /// <param name="id"></param> - /// <returns></returns> - public List<string> GetRoomNamesByFloorId(string id) - { - List<string> names = new List<string> { }; - foreach (var r in Lists) - { - if (r.FloorId == id) - { - names.Add(r.Name); - } - } - return names; - } - - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�) - /// </summary> - /// <param name="id"></param> - /// <returns></returns> - public List<Room> GetRoomsByFloorIdAppendLoveRoom(string id) - { - if (Config.Instance.Home.FloorDics.Count == 0) - { - return Lists; - } - var r= Lists.FindAll((obj) => obj.FloorId == id); - r.Insert(0, GetLoveRoom()); - return r; - } - - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�) - /// </summary> - /// <returns></returns> - public List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom() - { - if(Config.Instance.Home.FloorDics.Count==0) - { - return Lists; - } - var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId); - r.Insert(0, GetLoveRoom()); - return r; - } - - #endregion - - #region 鈼� 鎴块棿鏂规硶________________________ - - /// <summary> - /// 璁惧鐨勬埧闂村彉鏇� - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="roomId">鏂版埧闂碔d</param> - /// <param name="saveRealRoom">鏄惁淇敼鐪熷疄鐗╃悊璁惧鐨勬埧闂�,涓嶅嚭鎰忓,杩欎釜鍊奸粯璁や负true鍗冲彲</param> - public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true) - { - //鎴块棿鏄惁淇敼 - if (this.IsRoomChanged(device, roomId) == false) - { - return; - } - //浠庡師鏉ョ殑鎴块棿绉婚櫎璁惧 - this.DeleteDevice(device); - - //娣诲姞鍒版柊鐨勬埧闂� - var room = this.GetRoomById(roomId); - if (room != null) - { - room.AddDevice(device, saveRealRoom); - } - } + public string FloorId = string.Empty; /// <summary> - /// 鎴块棿鍚嶅瓧鏄惁鏈変慨鏀� + /// 鎴块棿閲屾墍鏈夌殑璁惧鍒楄〃(璁惧鐨勪富閿�:mac鍦板潃_绔彛) /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="roomId">鏂版埧闂碔d</param> - /// <returns></returns> - public bool IsRoomChanged(CommonDevice device, string roomId) - { - var room = this.GetRoomByDevice(device); - if (room == null || room.Id != roomId) - { - return true; - } - return false; - } - + public List<string> ListDevice = new List<string>(); /// <summary> - /// 鑾峰彇鎴块棿鎵�鍦ㄥ尯鍩� - /// 妤煎眰,鎴块棿鍚� + ///鍦烘櫙鍒楄〃(鍦烘櫙鐨処D) /// </summary> - /// <returns></returns> - public string GetZoneName() - { - if (string.IsNullOrEmpty(FloorId)) - { - return Name; - } - var floorName = Config.Instance.Home.GetFloorNameById(FloorId); - if (floorName == null) - { - return Name; - } - return $"{floorName},{Name}"; - } - - #endregion - - #region 鈼� 鏇存柊鎴块棿_________________________ - - /// <summary> - /// Updates the memorry. - /// </summary> - /// <param name="roomFilePath">Room file path.</param> - public static void UpdateMemorry(string roomFilePath) - { - GetRoomByFilePath(roomFilePath); - } - - #endregion - - #region 鈼� 鎴块棿鑳屾櫙鍥剧殑鐩稿叧___________________ - - /// <summary> - /// 绉诲姩鑳屾櫙鍥剧墖鍒颁綇瀹呯洰褰曚笅 - /// </summary> - /// <param name="oldFile">闇�瑕佺Щ鍔ㄧ殑鏂囦欢(鐩存帴鏂囦欢鍚�)</param> - /// <param name="newFile">瑕佺Щ鍔ㄥ埌鐨勪綅缃�-(鍖呭惈浣忓畢璺緞锛氫綇瀹�/鏂囦欢鍚�)</param> - public void MoveBackGroundIamageFileToDirectory(string oldFile, string newFile) - { - try - { - var newPath = System.IO.Path.Combine(Config.Instance.FullPath, newFile); - var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath,oldFile); - Global.MoveFileToDirectory(path, newPath); - //澶囦唤 - Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(oldFile); - //Save(); - } - catch (Exception ex) - { - System.Console.WriteLine("绉诲姩鍥剧墖寮傚父 " + ex.Message); - } - } - - #endregion - - #region 鈼� 娣诲姞璁惧________________________ - - /// <summary> - /// 娣诲姞璁惧(姝ゆ柟娉曠洰鍓嶅彧缁欍�愭垜鐨勫枩鐖便�戜娇鐢�) - /// </summary> - /// <param name="deviceUIFilePath">Device UIF ile path.</param> - public void AddDevice(string deviceUIFilePath) - { - if (string.IsNullOrEmpty(deviceUIFilePath)) - { - return; - } - var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath); - if (null == deviceUI.CommonDevice) - { - //褰撳墠瀵硅薄鏁版嵁鏃犳晥 - return; - } - if (!DeviceUIFilePathList.Contains(deviceUIFilePath) && !DeviceUIList.Contains(deviceUI)) - { - DeviceUIFilePathList.Add(deviceUIFilePath); - DeviceUIList.Add(deviceUI); - } - //淇濆瓨鍒版湰鍦� - Save(); - } - - /// <summary> - /// 娣诲姞璁惧(姝ゆ柟娉曠洰鍓嶅彧缁橰oom閲岄潰浣跨敤) - /// </summary> - /// <param name="device">瑕佹坊鍔犵殑璁惧瀵硅薄</param> - /// <param name="saveRealRoom">鏄惁淇敼鐪熷疄鐗╃悊璁惧鐨勬埧闂�,涓嶅嚭鎰忓,杩欎釜鍊奸粯璁や负true鍗冲彲</param> - public void AddDevice(CommonDevice device, bool saveRealRoom) - { - if (device == null) - { - return; - } - //璁惧淇℃伅淇濆瓨鍒版湰鍦� - device.Save(); - - var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); - if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false) - { - DeviceUIFilePathList.Add(deviceUI.FileName); - DeviceUIList.Add(deviceUI); - //淇濆瓨鍒版湰鍦� - Save(); - - if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1) - { - //濡傛灉鍙湁涓�涓洖璺�,鍒欎慨鏀圭湡瀹炵墿鐞嗚澶囩殑鎴块棿 - LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, this.Id, false); - } - } - } - - #endregion - - #region 鈼� 鍒犻櫎璁惧_________________________ - /// <summary> - /// 鍒犻櫎鍔熻兘-璁惧 - /// </summary> - /// <param name="deviceUIFilePath">Device UIF ile path.</param> - public void DeleteDevice(string deviceUIFilePath) - { - if (deviceUIFilePath == null) return; - if (DeviceUIFilePathList.Contains(deviceUIFilePath)) - { - DeviceUIFilePathList.Remove(deviceUIFilePath); - DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath); - Save(); - } - } - - /// <summary> - /// 鍒犻櫎璁惧 - /// </summary> - /// <param name="device">瑕佸垹闄ょ殑璁惧瀵硅薄</param> - public void DeleteDevice(CommonDevice device) - { - if (device == null) - { - return; - } - //鏍规嵁璁惧锛岃幏鍙栨墍鍦ㄧ殑鎴块棿 - var room = this.GetRoomByDevice(device); - if (room == null) - { - return; - } - string deviceFile = device.FilePath; - //绉婚櫎缂撳瓨 - if (room.DeviceUIFilePathList.Contains(deviceFile) == false) - { - return; - } - room.DeviceUIFilePathList.Remove(deviceFile); - - room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile); - room.Save(); - //鏇存敼鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(room.FileName); - - //閫掑綊锛氬垹闄ゆ帀浠ュ墠鐨勬棫鏁版嵁瀵艰嚧鐨勫涓埧闂寸殑闂 - this.DeleteDevice(device); - } - - /// <summary> - /// 鍒犻櫎鎴戠殑鍠滅埍鐨勮澶� - /// </summary> - /// <param name="device">瑕佸垹闄ょ殑璁惧瀵硅薄</param> - public void DeleteLoveDevice(CommonDevice device) - { - if (device == null) - { - return; - } - //鎴戠殑鍠滅埍 - var loveRoom = this.GetLoveRoom(); - if (loveRoom != null) - { - string deviceFile = device.FilePath; - //绉婚櫎缂撳瓨 - if (loveRoom.DeviceUIFilePathList.Contains(deviceFile) == false) - { - return; - } - loveRoom.DeviceUIFilePathList.Remove(deviceFile); - loveRoom.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile); - } - } - - #endregion - - #region 鈼� 鑾峰彇璁惧_________________________ - - /// <summary> - /// 鏍规嵁璁惧鑾峰彇瀹冪殑UI瀵硅薄锛屽鏋滀笉瀛樺湪鍒欐柊寤� - /// </summary> - /// <returns>The device user interface.</returns> - /// <param name="device">璁惧瀵硅薄</param> - public DeviceUI GetDeviceUI(CommonDevice device) - { - return Common.LocalDevice.Current.GetDeviceUI(device); - } - - /// <summary> - /// 鑾峰彇褰撳墠鎴块棿涓嬬殑鍏ㄩ儴璁惧 - /// </summary> - /// <returns></returns> - public List<CommonDevice> GetRoomListDevice() - { - var listDevice = new List<CommonDevice>(); - foreach (var device in this.DeviceUIList) - { - if (device == null || device.CommonDevice == null) - { - continue; - } - listDevice.Add(device.CommonDevice); - } - return listDevice; - } - - /// <summary> - /// 鑾峰彇鎴块棿璁惧绫诲瀷 - /// </summary> - /// <param name="room"></param> - /// <returns></returns> - public static List<DeviceType> GetdeviceTypes(Room room) - { - List<DeviceType> typeList = new List<DeviceType> { }; - foreach (var deviceUI in room.DeviceUIList) - { - if (deviceUI == null || deviceUI.CommonDevice == null) - { - continue; - } - if (!typeList.Contains(deviceUI.CommonDevice.Type)) - { - typeList.Add(deviceUI.CommonDevice.Type); - } - } - return typeList; - } - - /// <summary> - /// 鑾峰彇璇ョ被鍨嬬殑璁惧 - /// </summary> - /// <param name="room"></param> - /// <param name="deviceType"></param> - /// <returns></returns> - public static List<DeviceUI> GetDeviceUIs(Room room ,DeviceType deviceType) - { - List<DeviceUI> typeList = new List<DeviceUI> { }; - foreach (var deviceUI in room.DeviceUIList) - { - if (deviceUI == null || deviceUI.CommonDevice == null) - { - continue; - } - if(deviceUI.CommonDevice.Type!=deviceType) - { - continue; - } - if (!typeList.Contains(deviceUI)) - { - typeList.Add(deviceUI); - } - } - return typeList; - } - - /// <summary> - /// 鑾峰彇鏈垎閰嶅尯鍩熻澶� - /// </summary> - /// <returns></returns> - public List<DeviceUI> GetUnalloctedDeviceUIs() - { - List<DeviceUI> deviceUIs = new List<DeviceUI> { }; - var dList = AllRoomDeviceUIList; - var commonDeviceList = Common.LocalDevice.Current.listAllDevice; - - foreach (var device in commonDeviceList) - { - if (dList.Find((obj) => obj.CommonDevice.DeviceEpoint == device.DeviceEpoint && obj.CommonDevice.DeviceAddr == device.DeviceAddr) == null) - { - deviceUIs.Add(Common.LocalDevice.Current.GetDeviceUI(device)); - } - } - if (deviceUIs.Count == 0) - { - return null; - } - return deviceUIs; - } - - //public List<DeviceUI> GetUnalloctedDeviceUITypes - - #endregion - - #region 鈼� 娣诲姞鍦烘櫙_________________________ - - /// <summary> - /// 娣诲姞鍦烘櫙 0澶辫触 1鎴愬姛 -1宸茬粡瀛樺湪 - /// </summary> - /// <returns>The scene.</returns> - /// <param name="sceneName">Scene name.</param> - /// <param name="sceneIconPath">鑳屾櫙鍥剧墖锛屼笉鍖呭惈浣忓畢璺緞 濡傛灉iconPathType=1鎴栬��2 闇�瑕佹嫾鎺ヤ綇瀹� 鍙樻垚 浣忓畢/sceneIconPath</param> - /// <param name="commons">Commons.</param> - /// <param name="iconPathType">I鍦烘櫙鑳屾櫙鍥剧墖鏉ユ簮绫诲瀷 鍥剧墖鏉ユ簮 0--鏈湴鍥惧簱 1--鎷嶇収 2--绯荤粺鍥惧簱 榛樿0</param> - public async System.Threading.Tasks.Task<int> AddScene(string sceneName, string sceneIconPath, List<ZigBee.Device.Scene.AddSceneMemberData> commons, int iconPathType) - { - //var scenes = GetSceneUIsByFloorId(FloorId); - //if(scenes!=null && scenes.Count>0) - //{ - // if (scenes.Find(s => s.Name == sceneName) != null) - // { - // return -1; - // } - //} - - var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName); - if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null) - { - return 0; - } - var getSceneIdData = getSceneIdAllData.getSceneIdData; - - bool result = true; - foreach (var common in commons) - { - //娣诲姞鏂版垚鍛� - var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData - { - Type = common.Type, - DeviceAddr = common.DeviceAddr, - Epoint = common.Epoint, - ScenesId = getSceneIdData.NewScenesId, - TaskList = common.TaskList, - DelayTime = common.DelayTime, - MemberNumber=common.MemberNumber, - ElseScenesId = common.ElseScenesId - }; - //common.ScenesId = getSceneIdData.NewScenesId; - //娣诲姞鏂版垚鍛� 杩斿洖缁撴灉 - var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); - if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null) - { - continue; - } - var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData; - if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1) - { - result = false; - } - } - //鍔犲叆鎴愬姛 - if (result) - { - var sceneUI = new SceneUI - { - Name = sceneName, - Id = getSceneIdData.NewScenesId, - IconPath = sceneIconPath, - IconPathType = iconPathType, - AddSceneMemberDataList= commons - }; - sceneUI.Save(); - SceneUIList.Add(sceneUI); - SceneUIFilePathList.Add(sceneUI.FileName); - Save(); - return 1; - } - return 0; - } - - /// <summary> - /// 娣诲姞鍦烘櫙 - /// </summary> - /// <param name="scene">Scene.</param> - public void AddScene(SceneUI scene) - { - SceneUIList.Add(scene); - SceneUIFilePathList.Add(scene.FileName); - Save(); - } - - /// <summary> - /// 鍒犻櫎鍦烘櫙 - /// </summary> - /// <param name="scene"></param> - public void DeleteScene(SceneUI scene) - { - var curScene = SceneUIList.Find((obj) => obj.Id == scene.Id); - if (curScene == null) - { - return; - } - SceneUIList.Remove(curScene); - SceneUIFilePathList.Remove(curScene.FileName); - Save(); - } - - #endregion - - #region 鈼� 璁惧鏄惁鏀惰棌______________________ - - /// <summary> - /// 鏄惁鏄敹钘忚澶� - /// </summary> - /// <param name="filePath"></param> - /// <returns></returns> - public bool IsCollectInRoom(string filePath) - { - if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null) - { - return false; - } - return true; - } - #endregion - - #region 鈼� 淇敼鍦烘櫙________________________ - - /// <summary> - /// 淇敼鍦烘櫙璁惧 0澶辫触 1鎴愬姛 - /// </summary> - /// <returns>The scene.</returns> - /// <param name="sceneUI">Scene user interface.</param> - /// <param name="sceneRemoveMemberData">Scene remove member data.</param> - /// <param name="addCommons">Add commons.</param> - public async System.Threading.Tasks.Task<int> ModifyScene(SceneUI sceneUI, Scene.SceneRemoveMemberData sceneRemoveMemberData, List<Scene.AddSceneMemberData> addCommons) - { - //if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null) - //{ - // return 0; - //} - - bool result = true; - //绉婚櫎鎴愬憳 杩斿洖缁撴灉 - var removeSceneMemberResponseAllData = await ZigBee.Device.Scene.RemoveSceneMemberAsync(sceneRemoveMemberData); - if (removeSceneMemberResponseAllData == null || removeSceneMemberResponseAllData.removeSceneMemberResponseData == null) - { - return 0; - } - var removeSceneMemberResponseData = removeSceneMemberResponseAllData.removeSceneMemberResponseData; - if (removeSceneMemberResponseData == null) - { - return 0; - } - if (removeSceneMemberResponseData.Result != 0) - { - result = false; - } - //娣诲姞 - foreach (var addCommon in addCommons) - { - //娣诲姞鏂版垚鍛� - var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData - { - DeviceAddr = addCommon.DeviceAddr, - Type = addCommon.Type, - Epoint = addCommon.Epoint, - ScenesId = sceneUI.Id, - TaskList = addCommon.TaskList, - DelayTime = addCommon.DelayTime, - ElseScenesId = addCommon.ElseScenesId, - MemberNumber=addCommon.MemberNumber - }; - //娣诲姞鏂版垚鍛� 杩斿洖缁撴灉 - var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); - if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null) - { - result = false; - System.Console.WriteLine("娣诲姞鍦烘櫙澶辫触"); - continue; - } - var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData; - if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1) - { - result = false; - } - } - //鍔犲叆鎴愬姛 - if (result) - { - sceneUI.AddSceneMemberDataList = addCommons; - sceneUI.Save(); - if (IsLove == false) - { - var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id); - if (curScene != null) - { - curScene.Name = sceneUI.Name; - curScene.IconPath = sceneUI.IconPath; - curScene.IconPathType = sceneUI.IconPathType; - curScene.AddSceneMemberDataList = sceneUI.AddSceneMemberDataList; - curScene.SceneDelayTime = sceneUI.SceneDelayTime; - curScene.Save(false); - Common.Room.CurrentRoom.GetLoveRoom().Save(); - } - } - return 1; - } - return 0; - } - - /// <summary> - /// 璁剧疆銆佸悓姝ュ欢鏃舵椂闂� - /// </summary> - /// <param name="scene"></param> - public void ModifySceneDelayTime(SceneUI scene) - { - if (IsLove) - { - foreach (var r in Lists) - { - if (r.IsLove || r.SceneUIList.Count == 0) - { - continue; - } - foreach (var sce in r.SceneUIList) - { - if (sce.Id == scene.Id) - { - sce.SceneDelayTime = scene.SceneDelayTime; - sce.Save(false); - r.Save(false); - break; - } - } - } - } - else - { - var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == scene.Id); - if (curScene != null) - { - curScene.SceneDelayTime = scene.SceneDelayTime; - curScene.Save(false); - Common.Room.CurrentRoom.GetLoveRoom().Save(false); - } - } - } - - #endregion - - #region 鈼� 鍒犻櫎鍦烘櫙________________________ - - /// <summary> - /// 绉婚櫎鍦烘櫙--璇ヤ粎杩涜浜嗗鏈湴鍦烘櫙鏁版嵁鐨勫垹闄� - /// </summary> - /// <param name="sceneUI">Scene user interface.</param> - public void RemoveScene(SceneUI sceneUI) - { - if(Global.IsExistsByHomeId(sceneUI.FileName)==false) - { - return; - } - - if (sceneUI.IconPathType == 1 || sceneUI.IconPathType == 2) - { - if (Global.IsExistsByHomeId(sceneUI.IconPath)) - { - Global.DeleteFilebyHomeId(sceneUI.IconPath); - HdlAutoBackupLogic.DeleteFile(sceneUI.IconPath); - } - } - - if (IsLove == false) - { - if (CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id) != null) - { - CurrentRoom.GetLoveRoom().DeleteScene(sceneUI); - } - } - - SceneUIList.Remove(sceneUI); - SceneUIFilePathList.Remove(sceneUI.FileName); - Save(); - - Global.DeleteFilebyHomeId(sceneUI.FileName); - HdlAutoBackupLogic.DeleteFile(sceneUI.FileName); - } - - #endregion - - #region 鈼� 鑾峰彇鍦烘櫙________________________ - - /// <summary> - /// 閫氳繃鍦烘櫙id鑾峰彇鍦烘櫙 - /// </summary> - /// <returns>The scene UIB y scene identifier.</returns> - /// <param name="sceneId">Scene identifier.</param> - public SceneUI GetSceneUIBySceneId(int sceneId) - { - foreach (var r in Lists) - { - if (r.IsLove) - { - continue; - } - foreach (var sceneUI in r.SceneUIList) - { - if (sceneUI.Id == sceneId) - { - return sceneUI; - } - } - } - return null; - } - - /// <summary> - /// 鑾峰彇璇ユゼ灞傛墍鏈夊満鏅� - /// </summary> - /// <param name="floorId"></param> - /// <returns></returns> - public List<SceneUI> GetSameFloorScenes(string floorId) - { - List<SceneUI> sceneUIs = new List<SceneUI> { }; - var rooms= CurrentRoom.GetRoomsByFloorId(floorId); - foreach(var r in rooms) - { - sceneUIs.AddRange(r.SceneUIList); - } - return sceneUIs; - } - - /// <summary> - /// 鑾峰彇璇ユゼ灞傜殑鍦烘櫙 - /// </summary> - /// <param name="floorId"></param> - /// <returns></returns> - public List<SceneUI> GetSceneUIsByFloorId(string floorId) - { - var rooms = GetRoomsByFloorId(floorId); - if (rooms == null) - { - return null; - } - var sceneList = new List<SceneUI> { }; - foreach (var r in rooms) - { - if (r.SceneUIList.Count == 0) - { - continue; - } - foreach (var sceneUI in r.SceneUIList) - { - if (sceneUI == null) - { - continue; - } - sceneList.Add(sceneUI); - } - } - return sceneList; - } - - /// <summary> - /// 鑾峰彇鏈垎閰嶅尯鍩熷満鏅� - /// </summary> - /// <returns></returns> - public List<SceneUI> GetUnalloctedScenes() - { - List<SceneUI> sceneUIs = new List<SceneUI> { }; - var sList = AllRoomSceneUIFilepathList; - - List<string> sfile = new List<string> { }; - foreach (var path in Global.FileListByHomeId()) - { - if (path.StartsWith("Scene_", StringComparison.Ordinal)) - { - sfile.Add(path); - } - } - foreach (var path in sfile) - { - if (sList.Find((obj) => obj == path) == null) - { - var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(path)); - var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); - if (tempSceneUI != null) - { - sceneUIs.Add(tempSceneUI); - } - } - } - if (sceneUIs.Count == 0) - { - return null; - } - return sceneUIs; - } - - #endregion - - #region 鈼� 鍒锋柊鍦烘櫙_________________________ - - /// <summary> - /// 鍒锋柊鎴块棿鐨勫満鏅垪琛� - /// </summary> - public async System.Threading.Tasks.Task<bool> RefreshSceneUIList() - { - bool result = true; - var sceneList = await ZigBee.Device.Scene.GetSceneListAsync(); - if (sceneList == null) - { - return false; - } - List<int> sceneIDList = new List<int> { }; - foreach (var scene in sceneList) - { - if (scene == null) - { - continue; - } - sceneIDList.Add(scene.ScenesId); - } - foreach (var r in Lists) - { - if(r.IsLove) - { - continue; - } - if (r.SceneUIList == null || r.SceneUIList.Count == 0) - { - continue; - } - foreach (var rScene in r.SceneUIList) - { - if (rScene == null) - { - continue; - } - if (sceneIDList.Contains(rScene.Id) == false) - { - r.RemoveScene(rScene); - result = true; - } - } - } - return result; - } - - #endregion - - #region 鈼� 淇濆瓨____________________________ - - /// <summary> - /// 淇濆瓨 - /// </summary> - /// <param name="autoBackup">鏄惁鑷姩澶囦唤锛岄粯璁rue</param> - public void Save(bool autoBackup = true) - { - //淇濆瓨鎴块棿淇℃伅 - Global.WriteFileByBytesByHomeId(FileName, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); - if (autoBackup == true) - { - HdlAutoBackupLogic.AddOrEditorFile(FileName); - } - } - - #endregion - - #region 鈼� 妤煎眰鍜屾埧闂撮『搴忕浉鍏砡______________ - - /// <summary> - /// 鏍规嵁妤煎眰鐨勪富閿幏鍙栨帓搴忓悗鐨勬埧闂村垪琛� - /// </summary> - /// <param name="i_floorKeys">妤煎眰鐨勪富閿�</param> - /// <param name="getShard">鍒嗕韩鐨勬埧闂存槸鍚︿篃鑾峰彇</param> - /// <returns></returns> - public List<Room> GetFloorSortRoom(string i_floorKeys, bool getShard = true) - { - Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); - //璇诲彇鎴块棿椤哄簭 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); - } - - var listRoomSort = new List<string>(); - if (dicAllSort.ContainsKey(i_floorKeys) == true) - { - listRoomSort = dicAllSort[i_floorKeys]; - } - else - { - dicAllSort[i_floorKeys] = listRoomSort; - } - - var dicRoom = new Dictionary<string, Common.Room>(); - foreach (var room in Common.Room.Lists) - { - if (room.FloorId != i_floorKeys || room.IsLove == true) - { - //涓嶆槸鍚屼竴涓ゼ灞� - continue; - } - if (listRoomSort.Contains(room.Id) == false) - { - //鏂版坊鍔犵殑鎴块棿 - listRoomSort.Add(room.Id); - } - if (getShard == false && room.IsSharedRoom == true) - { - //涓嶈鍒嗕韩鐨勬埧闂� - continue; - } - dicRoom[room.Id] = room; - } - - var listSortRoom = new List<Room>(); - for (int i = 0; i < listRoomSort.Count; i++) - { - if (dicRoom.ContainsKey(listRoomSort[i]) == true) - { - listSortRoom.Add(dicRoom[listRoomSort[i]]); - } - } - - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, dicAllSort); - return listSortRoom; - } - - /// <summary> - /// 淇濆瓨鎴块棿鐨勯『搴� - /// </summary> - /// <param name="i_floorKeys">妤煎眰涓婚敭</param> - /// <param name="listSort">鎴块棿椤哄簭(鎴块棿鐨勪富閿�)</param> - public void SaveRoomSort(string i_floorKeys, List<string> listSort) - { - Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>(); - //璇诲彇鎴块棿椤哄簭 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData); - } - - //淇濆瓨椤哄簭 - dicAllSort[i_floorKeys] = listSort; - UserCenterLogic.SaveFileContent(fullName, dicAllSort); - dicAllSort.Clear(); - } - - /// <summary> - /// 鑾峰彇鎺掑簭鍚庣殑妤煎眰 - /// </summary> - /// <returns></returns> - public Dictionary<string, string> GetFloorSortList() - { - //璇诲彇妤煎眰椤哄簭 - var listFloorSort = new List<string>(); - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData); - } - foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys) - { - if (listFloorSort.Contains(keys) == false) - { - //鏂版坊鍔犵殑妤煎眰 - listFloorSort.Add(keys); - } - } - - var dic = new Dictionary<string, string>(); - for (int i = 0; i < listFloorSort.Count; i++) - { - if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true) - { - dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]]; - } - } - - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, listFloorSort); - return dic; - } - - /// <summary> - /// 淇濆瓨妤煎眰鐨勯『搴� - /// </summary> - /// <param name="listSort">妤煎眰鐨勪富閿�</param> - public void SaveFloorSort(List<string> listSort) - { - string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile); - //淇濆瓨椤哄簭 - UserCenterLogic.SaveFileContent(fullName, listSort); - } + public List<int> ListSceneId = new List<int>(); #endregion - #region 鈼� 鍏嬮殕鎴块棿瀵硅薄_____________________ + #region 鈻� 淇濆瓨_______________________________ /// <summary> - /// 鍏嬮殕鎴块棿瀵硅薄 + /// 淇濆瓨 /// </summary> - /// <returns></returns> - public Room CloneRoomClass() + /// <param name="autoBackup">鏄惁鑷姩澶囦唤锛岄粯璁rue</param> + public void Save(bool autoBackup = true) { - var newRoom = new Room(); - //鍏嬮殕灞炴�� - newRoom.Id = this.Id; - newRoom.FloorId = this.FloorId; - newRoom.TemperatrueDevice = this.TemperatrueDevice; - newRoom.HumidityDevice = this.HumidityDevice; - newRoom.Name = this.Name; - newRoom.BackgroundImage = this.BackgroundImage; - newRoom.BackgroundImageType = this.BackgroundImageType; - - return newRoom; + //淇濆瓨鎴块棿淇℃伅 + Global.WriteFileByBytesByHomeId(FileName, Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); + if (autoBackup == true) + { + HdlAutoBackupLogic.AddOrEditorFile(FileName); + } } #endregion - } } -- Gitblit v1.8.0