| | |
| | | /// <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> |
| | |
| | | { |
| | | 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;
|
| | | }
|
| | | string deviceFile = device.FilePath;
|
| | | //移除缓存
|
| | | if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false)
|
| | | if (room.DeviceUIFilePathList.Contains(deviceFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | room.DeviceUIFilePathList.Remove(deviceUI.FileName);
|
| | | room.DeviceUIFilePathList.Remove(deviceFile);
|
| | |
|
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName);
|
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
|
| | | room.Save();
|
| | | //更改自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(room.FileName); |
| | |
| | | }
|
| | | listDevice.Add(device.CommonDevice);
|
| | | }
|
| | | if (listDevice.Count == 0)
|
| | | {
|
| | | return listDevice;
|
| | | }
|
| | | return Common.LocalDevice.Current.SortDevice(listDevice);
|
| | | return listDevice;
|
| | | } |
| | | |
| | | /// <summary> |