From 1f5636d69332170ea3a41c76c9519f6ff6f0a8d9 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 28 十月 2019 15:40:30 +0800 Subject: [PATCH] 合并了代码 --- ZigbeeApp/Shared/Common/Room.cs | 406 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 315 insertions(+), 91 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs index e3440a1..c7a830e 100755 --- a/ZigbeeApp/Shared/Common/Room.cs +++ b/ZigbeeApp/Shared/Common/Room.cs @@ -38,12 +38,22 @@ /// </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; @@ -56,6 +66,15 @@ /// 妤煎眰--澶囩敤 /// </summary> public Dictionary<string, string> FloorList = new Dictionary<string, string> { }; + + /// <summary> + /// 娓╁害浼犳劅鍣�(璁惧涓婚敭) + /// </summary> + public string TemperatrueDevice = string.Empty; + /// <summary> + /// 婀垮害浼犳劅鍣�(璁惧涓婚敭) + /// </summary> + public string HumidityDevice = string.Empty; /// <summary> /// 褰撳墠閫夋嫨鐨勬埧闂� @@ -73,6 +92,11 @@ 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> @@ -81,7 +105,7 @@ { get { - return Id == "Favorite"; + return Id == LoveRoomId; } } @@ -110,18 +134,34 @@ { return new List<string> { }; } - var loveRoom = Lists[0]; - return loveRoom.DeviceUIFilePathList; + return CurrentRoom.GetLoveRoom().DeviceUIFilePathList; } } /// <summary> /// 鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨� - /// 鍏堣皟鐢� GetAllRoomDeviceTypeList() /// </summary> /// <value>All room device type list.</value> [Newtonsoft.Json.JsonIgnore] - public static List<DeviceType> AllRoomDeviceTypeList = new List<DeviceType> { }; + 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> /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夊満鏅� @@ -168,11 +208,41 @@ /// <summary> /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - /// 璇峰厛璋冪敤 GetAllRoomDeviceUIList()鏂规硶 /// </summary> /// <value>All room device UIL ist.</value> [Newtonsoft.Json.JsonIgnore] - public static List<DeviceUI> AllRoomDeviceUIList = new List<DeviceUI> { }; + 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) + { + 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 @@ -204,7 +274,7 @@ if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false) { //榛樿娣诲姞鍠滅埍鐨勬埧闂�--绂佹淇敼鎴块棿鍚� - var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = "Favorite" }; + var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = LoveRoomId }; love.Save(true); //娣诲姞鍒癶ouse 鎴块棿璺緞鍒楄〃 var currentHome = Config.Instance.Home; @@ -323,6 +393,15 @@ #region 鈼� 鑾峰彇鎴块棿________________________ /// <summary> + /// 鑾峰彇鍠滅埍鎴块棿 + /// </summary> + /// <returns></returns> + public Room GetLoveRoom() + { + return CurrentRoom.GetRoomById(LoveRoomId); + } + + /// <summary> /// 閫氳繃璺緞鑾峰彇鎴块棿 /// </summary> /// <returns>The room by file path.</returns> @@ -350,21 +429,8 @@ //璁惧锛坉eviceUI锛� beforeRoom.DeviceUIList.Clear(); foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList) - { - 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); - } - } + { + beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath)); } //鍦烘櫙(SceneUI) beforeRoom.SceneUIList.Clear(); @@ -431,6 +497,16 @@ } /// <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> @@ -462,7 +538,7 @@ deviceUI.DeviceAddr = device.DeviceAddr; deviceUI.DeviceEpoint = device.DeviceEpoint; - return Lists.Find((obj) => obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); + return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); } /// <summary> @@ -500,6 +576,55 @@ return null; } + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂� + /// </summary> + /// <param name="id"></param> + /// <returns></returns> + public List<Room> GetRoomsByFloorId(string id) + { + return Lists.FindAll((obj) => obj.FloorId==id); + } + /// <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) + { + var r= Lists.FindAll((obj) => obj.FloorId == id); + r.Insert(0, GetLoveRoom()); + return r; + } + + /// <summary> + /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�) + /// </summary> + /// <returns></returns> + public List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom() + { + var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId); + r.Insert(0, GetLoveRoom()); + return r; + } #endregion @@ -670,7 +795,6 @@ #endregion #region 鈼� 鍒犻櫎璁惧_________________________ - /// <summary> /// 鍒犻櫎鍔熻兘-璁惧 /// </summary> @@ -725,39 +849,6 @@ #region 鈼� 鑾峰彇璁惧_________________________ /// <summary> - /// 鑾峰彇鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - /// </summary> - public static void GetAllRoomDeviceUIList() - { - List<string> devicePathList = new List<string>(); - //鎵�鏈夋埧闂寸殑鎵�鏈夎澶� - AllRoomDeviceUIList.Clear(); - foreach (var room in Shared.Common.Room.Lists) - { - if(room.IsSharedRoom) - { - continue; - } - if (room.DeviceUIList.Count == 0) - { - continue; - } - foreach (var device in room.DeviceUIList) - { - if (device == null || device.CommonDevice == null) - { - continue; - } - if (!devicePathList.Contains(device.FileName)) - { - AllRoomDeviceUIList.Add(device); - devicePathList.Add(device.FileName); - } - } - } - } - - /// <summary> /// 鏍规嵁璁惧鑾峰彇瀹冪殑UI瀵硅薄锛屽鏋滀笉瀛樺湪鍒欐柊寤� /// </summary> /// <returns>The device user interface.</returns> @@ -767,23 +858,106 @@ 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); + } + if (listDevice.Count == 0) + { + return listDevice; + } + return Common.LocalDevice.Current.SortDevice(listDevice); + } + /// <summary> - /// 閲嶆柊鑾峰彇-鎵�鏈夋埧闂寸殑鎵�鏈夎澶囩被鍨� + /// 鑾峰彇鎴块棿璁惧绫诲瀷 /// </summary> - public static void GetAllRoomDeviceTypeList() + /// <param name="room"></param> + /// <returns></returns> + public static List<DeviceType> GetdeviceTypes(Room room) { - AllRoomDeviceTypeList.Clear(); - foreach (var deviceUI in AllRoomDeviceUIList) + List<DeviceType> typeList = new List<DeviceType> { }; + foreach (var deviceUI in room.DeviceUIList) { if (deviceUI == null || deviceUI.CommonDevice == null) { continue; } - if (!AllRoomDeviceTypeList.Contains(deviceUI.CommonDevice.Type)) + if (!typeList.Contains(deviceUI.CommonDevice.Type)) { - AllRoomDeviceTypeList.Add(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> + /// <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; } #endregion @@ -800,25 +974,21 @@ /// <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 = 0) { - if (AllRoomSceneUIList.Find(s => s.Name == sceneName) != null) + var scenes = GetSceneUIsByFloorId(FloorId); + if(scenes!=null && scenes.Count>0) { - return -1; + 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; - //寰幆鐩稿悓鎶ラ敊 - foreach (var tempSceneUI in AllRoomSceneUIList) - { - if (tempSceneUI.Id == getSceneIdAllData.getSceneIdData.NewScenesId) - { - //鍦烘櫙宸插瓨鍦� - return -1; - } - } bool result = true; foreach (var common in commons) @@ -826,12 +996,13 @@ //娣诲姞鏂版垚鍛� var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData { - DeviceAddr = common.DeviceAddr, 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; @@ -881,20 +1052,55 @@ /// <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(sceneUI); - SceneUIFilePathList.Add(sceneUI.FileName); - sceneUI.Save(); + //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(); } + /// <summary> + /// 鍒犻櫎鍦烘櫙 + /// </summary> + /// <param name="scene"></param> + public void DeleteScene(SceneUI scene) + { + //scene.IsCollected = false; + scene.Save(); + SceneUIList.Remove(scene); + SceneUIFilePathList.Remove(scene.FileName); + Save(); + } + + #endregion + + #region 鈼� 璁惧鏄惁鏀惰棌______________________ + + /// <summary> + /// 鏄惁鏄敹钘忚澶� + /// </summary> + /// <param name="room"></param> + /// <param name="filePath"></param> + /// <returns></returns> + public bool IsCollectInRoom(Room room,string filePath) + { + if(room.IsLove) + { + return true; + } + if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null) + { + return false; + } + return true; + } #endregion #region 鈼� 淇敼鍦烘櫙________________________ @@ -941,7 +1147,8 @@ ScenesId = sceneUI.Id, TaskList = addCommon.TaskList, DelayTime = addCommon.DelayTime, - ElseScenesId = addCommon.ElseScenesId + ElseScenesId = addCommon.ElseScenesId, + MemberNumber=addCommon.MemberNumber }; //娣诲姞鏂版垚鍛� 杩斿洖缁撴灉 var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); @@ -1012,7 +1219,21 @@ } 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; + } #endregion #region 鈼� 鍒锋柊鍦烘櫙_________________________ @@ -1121,7 +1342,7 @@ var dicRoom = new Dictionary<string, Common.Room>(); foreach (var room in Common.Room.Lists) { - if (room.FloorId != i_floorKeys) + if (room.FloorId != i_floorKeys || room.IsLove == true) { //涓嶆槸鍚屼竴涓ゼ灞� continue; @@ -1237,6 +1458,8 @@ //鍏嬮殕灞炴�� 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; @@ -1245,5 +1468,6 @@ } #endregion + } } -- Gitblit v1.8.0