| | |
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | if (listDevice != null)
|
| | | if (listDevice == null)
|
| | | {
|
| | | if (roomId == string.Empty)
|
| | | {
|
| | | //选择的是未分配
|
| | | this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | }
|
| | | }
|
| | |
|
| | | //保存记录
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
|
| | | UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | |
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
|
| | | {
|
| | |
| | | return;
|
| | | }
|
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | bool save = false;
|
| | | if (roomId == string.Empty)
|
| | | {
|
| | | //选择的是未分配
|
| | | this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //2020.05.18追加:如果记录的房间ID是不存在的话,则重新覆盖
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
|
| | | if (room == null)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (save == true)
|
| | | {
|
| | | //保存记录
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
|
| | | UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | /// </summary>
|
| | | /// <param name="i_RoomId"></param>
|
| | | public void DeleteRealDeviceByRoomId(string i_RoomId)
|
| | | {
|
| | | var listDeleteKey = new List<string>();
|
| | | foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
|
| | | {
|
| | | if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
|
| | | && listDeleteKey.Contains(deviceAddr) == false)
|
| | | {
|
| | | listDeleteKey.Add(deviceAddr);
|
| | | }
|
| | | }
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(listDeleteKey);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | listDevice = this.GetDeviceByGatewayID(gwId);
|
| | | }
|
| | |
|
| | | var dicDevice = new Dictionary<string, CommonDevice>();
|
| | | var listCheck = new HashSet<string>();
|
| | | var listReturn = new List<CommonDevice>();
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | if (dicDevice.ContainsKey(device.DeviceAddr) == false)
|
| | | if (listCheck.Contains(device.DeviceAddr) == false)
|
| | | {
|
| | | dicDevice[device.DeviceAddr] = device;
|
| | | continue;
|
| | | }
|
| | | //设备是否处于在线状态
|
| | | bool online = this.CheckDeviceIsOnline(device);
|
| | | if (online == true)
|
| | | {
|
| | | //如果设备回路在线,则优先使用在线的回路,后来的直接覆盖
|
| | | dicDevice[device.DeviceAddr] = device;
|
| | | }
|
| | | }
|
| | | var listReturn = new List<CommonDevice>();
|
| | | foreach (var device in dicDevice.Values)
|
| | | {
|
| | | listCheck.Add(device.DeviceAddr);
|
| | | listReturn.Add(device);
|
| | | }
|
| | | }
|
| | | return listReturn;
|
| | | }
|
| | |
| | | /// <returns></returns>
|
| | | public bool CheckDeviceIsOnline(CommonDevice i_device)
|
| | | {
|
| | | var listDevice = this.GetDevicesByMac(i_device.DeviceAddr, false);
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | //0:离线 1:在线 2:正在刷新状态
|
| | | return i_device.IsOnline == 1 || i_device.IsOnline == 2;
|
| | | bool statu = i_device.IsOnline == 1 || i_device.IsOnline == 2;
|
| | | if (statu == true)
|
| | | {
|
| | | //有一个回路在线,即在线
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | if (listCheck.Contains(mainkeys) == false)
|
| | | {
|
| | | listDevice.Add(device);
|
| | |
|
| | | listCheck.Add(mainkeys);
|
| | | //刷新一下本地缓存
|
| | | var localDevice = this.GetDevice(mainkeys);
|
| | | if (localDevice != null)
|
| | | {
|
| | | //刷新属性
|
| | | this.SetDeviceInfoToMain(localDevice, device);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | //如果是三路继电器的回路的话,默认为灯光
|
| | | else if (mainDevice.Type == DeviceType.OnOffOutput)
|
| | | {
|
| | | var myType = this.GetHdlMyDeviceEnumInfo(mainDevice);
|
| | | if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad)
|
| | | //2020.05.13变更:继电器都默认为灯光
|
| | | //var myType = this.GetHdlMyDeviceEnumInfo(mainDevice);
|
| | | //if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad)
|
| | | {
|
| | | if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
|
| | | {
|