| | |
| | | /// </summary> |
| | | public string HumidityDevice = string.Empty; |
| | | |
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// </summary> |
| | | private static Room m_CurrentRoom = null; |
| | | /// <summary> |
| | | /// 当前选择的房间 |
| | | /// </summary> |
| | | public static Room CurrentRoom; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static Room CurrentRoom
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_CurrentRoom == null && Lists.Count > 0)
|
| | | {
|
| | | return Lists[0];
|
| | | }
|
| | | return m_CurrentRoom;
|
| | | }
|
| | | set { m_CurrentRoom = value; }
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 房间里所有的设备列表 |
| | |
| | | /// </summary> |
| | | public static void InitAllRoom() |
| | | { |
| | | if (CanInitAllRoom == false) |
| | | { |
| | | return; |
| | | } |
| | | //if (CanInitAllRoom == false) |
| | | //{ |
| | | // return; |
| | | //} |
| | | Lists.Clear(); |
| | | if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false) |
| | | { |
| | |
| | | /// <param name="roomId">房间ID</param> |
| | | public Room GetRoomById(string roomId) |
| | | { |
| | | if (string.IsNullOrEmpty(roomId)) |
| | | { |
| | | return null; |
| | | } |
| | | return Lists.Find((obj) => obj.Id == roomId); |
| | | } |
| | | |
| | |
| | | /// <param name="device">设备对象</param> |
| | | public Room GetRoomByDevice(CommonDevice device) |
| | | { |
| | | var deviceUI = new DeviceUI { }; |
| | | deviceUI.DeviceAddr = device.DeviceAddr; |
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); |
| | | string deviceFile = device.FilePath; |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile)); |
| | | } |
| | | |
| | | /// <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; |
| | |
| | | { |
| | | return; |
| | | } |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUIFilePath)); |
| | | var deviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); |
| | | if (null == deviceUI || null == deviceUI.CommonDevice) |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath); |
| | | if (null == deviceUI.CommonDevice) |
| | | { |
| | | //当前对象数据无效 |
| | | return; |
| | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | |
| | | DeviceUI deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | DeviceUIFilePathList.Add(deviceUI.FileName); |
| | |
| | | public void DeleteDevice(string deviceUIFilePath) |
| | | { |
| | | if (deviceUIFilePath == null) return; |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath) && Global.IsExistsByHomeId(deviceUIFilePath)) |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath)) |
| | | { |
| | | DeviceUIFilePathList.Remove(deviceUIFilePath); |
| | | DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath); |
| | | HdlAutoBackupLogic.DeleteFile(deviceUIFilePath); |
| | | Save(); |
| | | } |
| | | } |
| | |
| | | { |
| | | return; |
| | | } |
| | | DeviceUI deviceUI = new DeviceUI(); |
| | | deviceUI.DeviceAddr = device.DeviceAddr; |
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | //根据设备,获取所在的房间 |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null) |
| | | { |
| | | return; |
| | | } |
| | | //移除缓存 |
| | | if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | return; |
| | | } |
| | | room.DeviceUIFilePathList.Remove(deviceUI.FileName); |
| | | |
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName); |
| | | room.Save(); |
| | | //更改自动备份 |
| | | 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); |
| | | } |
| | | |
| | |
| | | /// 获取当前房间下的全部设备 |
| | | /// </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); |
| | | 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> |
| | |
| | | #endregion |
| | | |
| | | } |
| | | } |
| | | } |