| | |
| | | /// 所有的房间信息
|
| | | /// </summary>
|
| | | private Dictionary<string, Room> dicRooms = new Dictionary<string, Room>();
|
| | | /// <summary>
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceRoomId = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | HdlAutoBackupLogic.DeleteFile(roomFilePath);
|
| | |
|
| | | //根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | Common.LocalDevice.Current.DeleteRealDeviceByRoomId(roomId);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceByRoomId(roomId);
|
| | | if (refreshLeftView == true)
|
| | | {
|
| | | //刷新房间视图列表
|
| | |
| | | return listRoom;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | return this.GetRoomByGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="gatewayId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(string gatewayId)
|
| | | {
|
| | | var localGateway = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
|
| | | if (localGateway == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关Id</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(string gwId, string roomId)
|
| | | {
|
| | | var localGateway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | | localGateway.ReSave();
|
| | | //添加备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | |
|
| | | #region ■ 物理设备所属房间___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化物理设备所属房间的记录
|
| | | /// </summary>
|
| | | public void InitRealDeviceRoomId()
|
| | | {
|
| | | this.dicDeviceRoomId = new Dictionary<string, string>();
|
| | | string fullName = DirNameResourse.DeviceRoomIdFile;
|
| | | var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
|
| | | if (strData != null)
|
| | | {
|
| | | this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取全部物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public Dictionary<string, string> GetAllRealDeviceRoomData()
|
| | | {
|
| | | return this.dicDeviceRoomId;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <param name="listDevice">需要保存的设备对象</param>
|
| | | /// <param name="roomId">需要保存的哪个设备的房间ID</param>
|
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | if (listDevice == null || listDevice.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice.Count == 1)
|
| | | {
|
| | | if ((listDevice[0] is OTADevice) == false)
|
| | | {
|
| | | //ota设备不需要处理
|
| | | 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)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (save == true)
|
| | | {
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备的房间名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public string GeteRealDeviceRoomName(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | }
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | return HdlRoomLogic.Current.GetRoomName(room);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备属于哪个房间
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public Room GeteRealDeviceRoom(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="device">随便一个回路</param>
|
| | | public void DeleteRealDeviceFromRoom(CommonDevice device)
|
| | | {
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(new List<string>() { device.DeviceAddr });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="listMac">设备Mac地址</param>
|
| | | public void DeleteRealDeviceFromRoom(List<string> listMac)
|
| | | {
|
| | | bool save = false;
|
| | | foreach (var deviceMacAddr in listMac)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
|
| | | {
|
| | | this.dicDeviceRoomId.Remove(deviceMacAddr);
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | if (save == false)
|
| | | {
|
| | | //没有改变,不需要保存
|
| | | return;
|
| | | }
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | 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
|
| | |
|
| | | #region ■ 房间方法___________________________
|
| | |
| | | if (i_room.IsLove == false && saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //如果只有一个回路,则修改真实物理设备的房间
|
| | | LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, i_room.Id, false);
|
| | | this.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, i_room.Id, false);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | if (deleteReal == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //删除掉它的真实物理设备的所在位置
|
| | | LocalDevice.Current.DeleteRealDeviceFromRoom(device);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(device);
|
| | | }
|
| | |
|
| | | //根据设备,获取所在的房间
|
| | |
| | | var houseInfo = new AreaSpaceInfo();
|
| | | houseInfo.name = Common.Config.Instance.Home.Name;
|
| | | houseInfo.uid = Common.Config.Instance.Home.Id;
|
| | | houseInfo.parentId = "null";
|
| | | houseInfo.parentId = null;
|
| | | listAreaSpaceInfo.Add(houseInfo);
|
| | | //然后添加楼层
|
| | | foreach (var floorId in Common.Config.Instance.Home.FloorDics.Keys)
|
| | |
| | | gatewayInfo.uid = "000101" + gwMac.Substring(2) + "07";
|
| | | gatewayInfo.name = HdlGatewayLogic.Current.GetGatewayName(loaclGateway);
|
| | |
|
| | | var roomGateway = HdlGatewayLogic.Current.GetRoomByGateway(loaclGateway);
|
| | | var roomGateway = HdlRoomLogic.Current.GetRoomByGateway(loaclGateway);
|
| | | if (roomGateway != null)
|
| | | {
|
| | | gatewayInfo.parentId = roomGateway.Id;
|
| | |
| | | {
|
| | | //创建文件对象
|
| | | var result0 = await realMain.CreateFileAsync("DeviceRoomInfo.json");
|
| | | if (result0 == null || result0.Result != 0)
|
| | | if (result0 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result0.Result != 0 && result0.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | | //发送数据流
|
| | |
| | |
|
| | | //创建文件对象
|
| | | var result3 = await realMain.CreateFileAsync("space.json");
|
| | | if (result3 == null || result3.Result != 0)
|
| | | if (result3 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result3.Result != 0 && result3.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | |
|
| | | //发送区域信息
|
| | | var byteData2 = ASCIIEncoding.UTF8.GetBytes(strSendRoomInfo);
|