From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期五, 28 二月 2020 15:25:13 +0800 Subject: [PATCH] 2020.2.28 --- ZigbeeApp/Shared/Common/Room.cs | 247 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 169 insertions(+), 78 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs old mode 100755 new mode 100644 index 8310b10..e5c8d07 --- a/ZigbeeApp/Shared/Common/Room.cs +++ b/ZigbeeApp/Shared/Common/Room.cs @@ -98,6 +98,7 @@ { if (m_CurrentRoom == null && Lists.Count > 0) { + if (m_CurrentRoom == null) { m_CurrentRoom = Lists[0]; } return Lists[0]; } return m_CurrentRoom; @@ -193,6 +194,10 @@ var sceneList = new List<SceneUI> { }; foreach (var r in Shared.Common.Room.Lists) { + if(r.IsLove) + { + continue; + } if (r.SceneUIList.Count == 0) { continue; @@ -222,6 +227,11 @@ var pathList = new List<string> { }; foreach (var r in Lists) { + if(r.IsLove) + { + continue; + } + if (r.SceneUIFilePathList.Count == 0) { continue; @@ -263,7 +273,7 @@ for (int i = 0; i < Lists.Count; i++) { var room = Lists[i]; - if (room.IsSharedRoom) + if (room.IsSharedRoom || room.IsLove) { continue; } @@ -335,6 +345,7 @@ } } + Config.Instance.Home.InitFloor(); CurrentRoom.RefreshRoomListView(); @@ -356,7 +367,6 @@ /// </summary> public static void RefreshAllRoomByLocation() { - Lists.Clear(); var homeTemp = Config.Instance.Home; homeTemp.RoomFilePathList.Clear(); @@ -367,7 +377,7 @@ if (listFile.Contains(fRoom) == true) { listFile.Remove(fRoom); - homeTemp.AddRoomListFilePath(fRoom); + homeTemp.RoomFilePathList.Add(fRoom); } var listRoomFile = new List<string>(); @@ -375,7 +385,7 @@ { if (fileName.StartsWith("Room_")) { - homeTemp.AddRoomListFilePath(fileName); + homeTemp.RoomFilePathList.Add(fileName); listRoomFile.Add(fileName); } } @@ -438,6 +448,7 @@ } Save(); HdlAutoBackupLogic.AddOrEditorFile(room.FileName); + CurrentRoom.RefreshRoomListView(); return true; } @@ -541,8 +552,21 @@ //璁惧锛坉eviceUI锛� beforeRoom.DeviceUIList.Clear(); foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList) - { - beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath)); + { + var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceFilePath)); + var tempDeviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); + if (tempDeviceUI != null) + { + var delCommon = tempDeviceUIList.Find((obj) => obj.CommonDevice != null && tempDeviceUI.CommonDevice != null && obj.CommonDevice.Type == tempDeviceUI.CommonDevice.Type && obj.CommonDevice.CommonDeviceAddrEpoint == tempDeviceUI.CommonDevice.CommonDeviceAddrEpoint); + if (delCommon != null) + { + beforeRoom.DeviceUIList.Add(delCommon); + } + else + { + beforeRoom.AddDevice(deviceFilePath); + } + } } //鍦烘櫙(SceneUI) beforeRoom.SceneUIList.Clear(); @@ -678,6 +702,10 @@ { foreach (var r in Lists) { + if(r.IsLove) + { + continue; + } foreach (var scene in r.SceneUIList) { if (scene.Id == sceneId) @@ -696,11 +724,24 @@ /// <returns></returns> public List<Room> GetRoomsByFloorId(string id) { - if (Config.Instance.Home.FloorDics.Count == 0) + try { - return Lists; + 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); } - return Lists.FindAll((obj) => obj.FloorId == id); + catch(Exception ex) + { + System.Console.WriteLine(ex.Message); + return null; + } + } /// <summary> /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂村悕绉� @@ -904,8 +945,6 @@ //淇濆瓨鍒版湰鍦� Save(); - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(FileName); if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1) { //濡傛灉鍙湁涓�涓洖璺�,鍒欎慨鏀圭湡瀹炵墿鐞嗚澶囩殑鎴块棿 @@ -1080,14 +1119,10 @@ List<DeviceUI> deviceUIs = new List<DeviceUI> { }; var dList = AllRoomDeviceUIList; var commonDeviceList = Common.LocalDevice.Current.listAllDevice; - - if (dList.Count == 0) - { - return null; - } + foreach (var device in commonDeviceList) { - if (dList.Find((obj) => obj.CommonDevice == device) == null) + if (dList.Find((obj) => obj.CommonDevice.DeviceEpoint == device.DeviceEpoint && obj.CommonDevice.DeviceAddr == device.DeviceAddr) == null) { deviceUIs.Add(Common.LocalDevice.Current.GetDeviceUI(device)); } @@ -1185,17 +1220,8 @@ /// <param name="scene">Scene.</param> public void AddScene(SceneUI scene) { - //var sceneUI = new SceneUI - //{ - // Name = scene.Name, - // Id = scene.Id, - // IconPath = scene.IconPath, - // IconPathType = scene.IconPathType, - // AddSceneMemberDataList = scene.AddSceneMemberDataList - //}; SceneUIList.Add(scene); SceneUIFilePathList.Add(scene.FileName); - scene.Save(); Save(); } @@ -1205,10 +1231,13 @@ /// <param name="scene"></param> public void DeleteScene(SceneUI scene) { - //scene.IsCollected = false; - scene.Save(); - SceneUIList.Remove(scene); - SceneUIFilePathList.Remove(scene.FileName); + var curScene = SceneUIList.Find((obj) => obj.Id == scene.Id); + if (curScene == null) + { + return; + } + SceneUIList.Remove(curScene); + SceneUIFilePathList.Remove(curScene.FileName); Save(); } @@ -1297,9 +1326,61 @@ { 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 @@ -1316,9 +1397,16 @@ { return; } - SceneUIList.Remove(sceneUI); - SceneUIFilePathList.Remove(sceneUI.FileName); - Save(); + + 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) @@ -1326,6 +1414,11 @@ CurrentRoom.GetLoveRoom().DeleteScene(sceneUI); } } + + SceneUIList.Remove(sceneUI); + SceneUIFilePathList.Remove(sceneUI.FileName); + Save(); + Global.DeleteFilebyHomeId(sceneUI.FileName); HdlAutoBackupLogic.DeleteFile(sceneUI.FileName); } @@ -1343,6 +1436,10 @@ { foreach (var r in Lists) { + if (r.IsLove) + { + continue; + } foreach (var sceneUI in r.SceneUIList) { if (sceneUI.Id == sceneId) @@ -1446,51 +1543,45 @@ /// </summary> public async System.Threading.Tasks.Task<bool> RefreshSceneUIList() { - return false; - //System.Console.WriteLine($"寮�濮嬭姹傜綉鍏冲満鏅�****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); - //bool result = true; - //var sceneList = await ZigBee.Device.Scene.GetSceneListAsync(); - //System.Console.WriteLine($"缁撴潫璇锋眰缃戝叧鍦烘櫙****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); - //if (sceneList == null) - //{ - // return false; - //} - //List<int> sceneIDList = new List<int> { }; - //System.Console.WriteLine($"寮�濮嬫湰鍦板満鏅�****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); - //foreach (var scene in sceneList) - //{ - // if (scene == null) - // { - // continue; - // } - // sceneIDList.Add(scene.ScenesId); - //} - //foreach(var r in Lists) - //{ - // if(r.SceneUIList==null || r.SceneUIList.Count==0) - // { - // continue; - // } - // foreach(var rScene in r.SceneUIList) - // { - // if(rScene==null) - // { - // continue; - // } - // //var scene = sceneList.Find((obj) => rScene.ScenesId == obj.ScenesId); - // if(sceneIDList.Contains(rScene.ScenesId)==false) - // { - // var removeResult = r.SceneUIList.Remove(rScene); - // r.Save(); - // if (removeResult == false) - // { - // result = false; - // } - // } - // } - //} - //System.Console.WriteLine($"缁撴潫鏈湴鍦烘櫙****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); - //return result; + 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 -- Gitblit v1.8.0