| | |
| | | return m_Current;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// 当前主页选择的房间对象
|
| | | /// </summary>
|
| | | private Room m_CurrentRoom = null;
|
| | | public Room NowMainPageRoom = null;
|
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// 当前分类选择的房间对象
|
| | | /// </summary>
|
| | | public Room CurrentRoom
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_CurrentRoom == null && dicRooms.Count > 0)
|
| | | {
|
| | | //设置初始值
|
| | | foreach (var room in dicRooms.Values)
|
| | | {
|
| | | m_CurrentRoom = room;
|
| | | break;
|
| | | }
|
| | | }
|
| | | return m_CurrentRoom;
|
| | | }
|
| | | set { m_CurrentRoom = value; }
|
| | | }
|
| | |
|
| | | public Room NowCategoryRoom = null;
|
| | | /// <summary>
|
| | | /// 所有的房间信息
|
| | | /// </summary>
|
| | | private Dictionary<string, Room> dicRooms = new Dictionary<string, Room>();
|
| | | /// <summary>
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceRoomId = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | /// </summary>
|
| | | public void InitAllRoom()
|
| | | {
|
| | | this.NowMainPageRoom = null;
|
| | | this.NowCategoryRoom = null;
|
| | |
|
| | | //清空本地缓存
|
| | | this.dicRooms.Clear();
|
| | | //检测我的喜爱这个房间对象
|
| | | this.CheckLoveRoom();
|
| | | |
| | | foreach (var roomId in Config.Instance.Home.ListRooms)
|
| | |
|
| | | var listFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | | foreach (var fileName in listFile)
|
| | | {
|
| | | //从文件里面获取房间对象
|
| | | var room = this.GetRoomByFilePath($"Room_{roomId}.json");
|
| | | if (room != null)
|
| | | if (fileName.StartsWith("Room_") == true)
|
| | | {
|
| | | this.dicRooms[room.Id] = (room);
|
| | | //从文件里面获取房间对象
|
| | | var room = this.GetRoomByFilePath(fileName);
|
| | | if (room != null)
|
| | | {
|
| | | this.dicRooms[room.Id] = (room);
|
| | | }
|
| | | }
|
| | | }
|
| | | //设置当前楼层的ID
|
| | | Config.Instance.Home.SetCurrentFloorId();
|
| | | //顺便刷新场景
|
| | | HdlSceneLogic.Current.ReFreshByLocal();
|
| | | //刷新房间视图列表
|
| | |
| | | /// </summary>
|
| | | public void RefreshAllRoomByLocation()
|
| | | {
|
| | | var homeTemp = Config.Instance.Home;
|
| | | homeTemp.ListRooms.Clear();
|
| | |
|
| | | var listFile = Global.FileListByHomeId();
|
| | | var listFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | |
|
| | | //我的喜爱的房间必须要在第0位才行
|
| | | string fRoom = "Room_Favorite.json";
|
| | | if (listFile.Contains(fRoom) == true)
|
| | | {
|
| | | listFile.Remove(fRoom);
|
| | | homeTemp.ListRooms.Add("Favorite");
|
| | | }
|
| | |
|
| | | var listRoomFile = new List<string>();
|
| | |
| | | if (fileName.StartsWith("Room_"))
|
| | | {
|
| | | string roomId = fileName.Replace("Room_", string.Empty).Replace(".json", string.Empty);
|
| | | homeTemp.ListRooms.Add(roomId);
|
| | | listRoomFile.Add(fileName);
|
| | | }
|
| | | }
|
| | |
| | | this.CheckAdminFloorData(listRoomFile);
|
| | | }
|
| | |
|
| | | homeTemp.Save(false);
|
| | | InitAllRoom();
|
| | | this.InitAllRoom();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | MainPage.ListRoomViewFrom.Instance?.ShowForm();
|
| | | MainPage.LeftListRoomViewFrom.Instance?.RefreshListRoom();
|
| | | });
|
| | | }
|
| | |
|
| | |
| | | /// <param name="rorefreshRoomViewom">是否刷新房间视图列表界面</param>
|
| | | public void AddRoom(Room room, bool refreshRoomView = true)
|
| | | {
|
| | | if (Global.IsExistsByHomeId(room.FileName) == true
|
| | | || Config.Instance.Home.ListRooms.Contains(room.Id) == true)
|
| | | if (Global.IsExistsByHomeId(room.FileName) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //添加到缓存
|
| | | this.dicRooms[room.Id] = room;
|
| | | //把房间ID添加到住宅
|
| | | Config.Instance.Home.AddRoomId(room.Id);
|
| | | //生成文件
|
| | | room.Save();
|
| | | //备份
|
| | |
| | | /// 删除房间
|
| | | /// </summary>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | /// <param name="refreshLeftView">是否刷新左滑界面(此变量目前是给删除全部房间用的)</param>
|
| | | /// <returns></returns>
|
| | | public void RemoveRoom(string roomId)
|
| | | public void RemoveRoom(string roomId, bool refreshLeftView = true)
|
| | | {
|
| | | if (this.NowMainPageRoom != null && this.NowMainPageRoom.Id == roomId)
|
| | | {
|
| | | //当删除的是主页的房间的时候
|
| | | this.NowMainPageRoom = this.GetLoveRoom();
|
| | | }
|
| | | if (this.NowCategoryRoom != null && this.NowCategoryRoom.Id == roomId)
|
| | | {
|
| | | //当删除的是分类的房间的时候
|
| | | this.NowCategoryRoom = this.GetLoveRoom();
|
| | | }
|
| | |
|
| | | //根据房间Id,获取房间对象
|
| | | var room = this.GetRoomById(roomId);
|
| | | if (room == null)
|
| | |
| | | }
|
| | | loveRoom.Save(false);
|
| | | }
|
| | |
|
| | | Config.Instance.Home.RemoveRoomId(roomId);
|
| | | this.dicRooms.Remove(roomId);
|
| | |
|
| | | string roomFilePath = room.FileName;
|
| | |
| | | Global.DeleteFilebyHomeId(roomFilePath);
|
| | | }
|
| | | HdlAutoBackupLogic.DeleteFile(roomFilePath);
|
| | | //刷新房间视图列表
|
| | | this.RefreshRoomListView();
|
| | |
|
| | | //根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | HdlRoomLogic.Current.DeleteRealDeviceByRoomId(roomId);
|
| | | if (refreshLeftView == true)
|
| | | {
|
| | | //刷新房间视图列表
|
| | | this.RefreshRoomListView();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除全部的房间
|
| | | /// </summary>
|
| | | public void DeleteAllRoom()
|
| | | {
|
| | | var listRoomId = new List<string>();
|
| | | foreach (var room in this.dicRooms.Values)
|
| | | {
|
| | | if (room.IsLove == false)
|
| | | {
|
| | | listRoomId.Add(room.Id);
|
| | | }
|
| | | }
|
| | | foreach (var roomId in listRoomId)
|
| | | {
|
| | | this.RemoveRoom(roomId, false);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | public string GetRoomNameByDevice(CommonDevice device)
|
| | | {
|
| | | var room = this.GetRoomByDevice(device);
|
| | | return this.GetFloorRoomName(room);
|
| | | return this.GetRoomName(room);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// </summary>
|
| | | /// <returns>房间名</returns>
|
| | | /// <param name="room">房间对象</param>
|
| | | public string GetFloorRoomName(Room room)
|
| | | public string GetRoomName(Room room)
|
| | | {
|
| | | if (room == null)
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | return listRoom;
|
| | | return this.SortRoom(listRoom);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | listRoom.Add(room);
|
| | | }
|
| | | return listRoom;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取当前楼层的房间名称
|
| | | /// </summary>
|
| | | /// <param name="id"></param>
|
| | | /// <returns></returns>
|
| | | public List<string> GetRoomNamesByFloorId(string id)
|
| | | {
|
| | | var listName = new List<string>();
|
| | | if (Config.Instance.Home.FloorDics.Count == 0)
|
| | | {
|
| | | //没有楼层
|
| | | foreach (var room in this.dicRooms.Values)
|
| | | {
|
| | | listName.Add(room.Name);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | foreach (var room in this.dicRooms.Values)
|
| | | {
|
| | | if (room.FloorId == id)
|
| | | {
|
| | | listName.Add(room.Name);
|
| | | }
|
| | | }
|
| | | }
|
| | | return listName;
|
| | | return this.SortRoom(listRoom);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | listRoom = this.SortRoom(listRoom);
|
| | |
|
| | | listRoom.Insert(0, GetLoveRoom());
|
| | | 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 List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
|
| | | public Dictionary<string, string> GetAllRealDeviceRoomData()
|
| | | {
|
| | | return this.GetRoomsByFloorIdAppendLoveRoom(Config.Instance.Home.CurrentFloorId);
|
| | | 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
|
| | |
| | | {
|
| | | //从原来的房间移除设备
|
| | | this.DeleteDevice(device);
|
| | | //移除我的喜爱
|
| | | this.DeleteLoveDevice(device);
|
| | | //设备改变房间的话,主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | return;
|
| | | }
|
| | | //房间是否修改
|
| | |
| | | {
|
| | | return;
|
| | | }
|
| | | //从原来的房间移除设备
|
| | | this.DeleteDevice(device);
|
| | | //从原来的房间移除设备,这里不删除真实设备的房间
|
| | | this.DeleteDevice(device, false);
|
| | |
|
| | | //添加到新的房间
|
| | | var room = this.GetRoomById(roomId);
|
| | |
| | | {
|
| | | this.AddDevice(room, device, saveRealRoom);
|
| | | }
|
| | | //设备改变房间的话,主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取房间所在区域
|
| | | /// 楼层,房间名
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public string GetZoneName(Room i_room)
|
| | | {
|
| | | if (string.IsNullOrEmpty(i_room.FloorId))
|
| | | {
|
| | | return i_room.Name;
|
| | | }
|
| | | var floorName = Config.Instance.Home.GetFloorNameById(i_room.FloorId);
|
| | | if (floorName == null)
|
| | | {
|
| | | return i_room.Name;
|
| | | }
|
| | | return $"{floorName},{i_room.Name}";
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | //保存到本地
|
| | | loveRoom.ListDevice.Add(mainkeys);
|
| | | loveRoom.Save();
|
| | | //添加收藏设备时,需要刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// 删除设备(这个函数不删除我的喜爱)
|
| | | /// </summary>
|
| | | /// <param name="device">要删除的设备对象</param>
|
| | | public void DeleteDevice(CommonDevice device)
|
| | | /// <param name="deleteReal">是否删除真实物理设备的房间</param>
|
| | | public void DeleteDevice(CommonDevice device, bool deleteReal = true)
|
| | | {
|
| | | if (device == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果它只有一个回路
|
| | | if (deleteReal == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //删除掉它的真实物理设备的所在位置
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(device);
|
| | | }
|
| | |
|
| | | //根据设备,获取所在的房间
|
| | | var room = this.GetRoomByDevice(device);
|
| | | if (room == null)
|
| | |
| | | HdlAutoBackupLogic.AddOrEditorFile(room.FileName);
|
| | |
|
| | | //递归:删除掉以前的旧数据导致的多个房间的问题
|
| | | this.DeleteDevice(device);
|
| | | this.DeleteDevice(device, deleteReal);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | loveRoom.Save();
|
| | | //更改自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(loveRoom.FileName);
|
| | | //添加收藏设备时,需要刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | #region ■ 楼层和房间顺序相关_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据楼层的主键获取排序后的房间列表(支持无楼层模式)
|
| | | /// 根据楼层的主键获取排序后的房间列表(支持无楼层模式,不获取收藏房间)
|
| | | /// </summary>
|
| | | /// <param name="i_floorKeys">楼层的主键</param>
|
| | | /// <param name="getShard">分享的房间是否也获取</param>
|
| | |
| | | {
|
| | | i_floorKeys = string.Empty;
|
| | | }
|
| | | Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>();
|
| | | //读取房间顺序
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile);
|
| | | var strData = UserCenterLogic.LoadFileContent(fullName);
|
| | | if (strData != null)
|
| | | {
|
| | | dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
|
| | | }
|
| | |
|
| | | var listRoomSort = new List<string>();
|
| | | if (dicAllSort.ContainsKey(i_floorKeys) == true)
|
| | | {
|
| | | listRoomSort = dicAllSort[i_floorKeys];
|
| | | }
|
| | | else
|
| | | {
|
| | | dicAllSort[i_floorKeys] = listRoomSort;
|
| | | }
|
| | |
|
| | | var dicRoom = new Dictionary<string, Common.Room>();
|
| | | var listRoom = new List<Room>();
|
| | | foreach (var room in this.dicRooms.Values)
|
| | | {
|
| | | if (room.FloorId != i_floorKeys && i_floorKeys != string.Empty)
|
| | | if (room.FloorId != i_floorKeys && i_floorKeys != string.Empty
|
| | | || room.IsLove == true)
|
| | | {
|
| | | //不是同一个楼层
|
| | | //不是同一个楼层,不要我的喜爱
|
| | | continue;
|
| | | }
|
| | | if (room.IsLove == true)
|
| | | {
|
| | | //不要我的喜爱
|
| | | continue;
|
| | | }
|
| | | if (listRoomSort.Contains(room.Id) == false)
|
| | | {
|
| | | //新添加的房间
|
| | | listRoomSort.Add(room.Id);
|
| | | }
|
| | | if (getShard == false && room.IsSharedRoom == true)
|
| | | {
|
| | | //不要分享的房间
|
| | | continue;
|
| | | }
|
| | | dicRoom[room.Id] = room;
|
| | | listRoom.Add(room);
|
| | | }
|
| | |
|
| | | var listSortRoom = new List<Room>();
|
| | | for (int i = 0; i < listRoomSort.Count; i++)
|
| | | {
|
| | | if (dicRoom.ContainsKey(listRoomSort[i]) == true)
|
| | | {
|
| | | listSortRoom.Add(dicRoom[listRoomSort[i]]);
|
| | | }
|
| | | }
|
| | |
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, dicAllSort);
|
| | | return listSortRoom;
|
| | | return this.SortRoom(listRoom);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存房间的顺序
|
| | | /// 排序房间对象
|
| | | /// </summary>
|
| | | /// <param name="i_floorKeys">楼层主键</param>
|
| | | /// <param name="listSort">房间顺序(房间的主键)</param>
|
| | | public void SaveRoomSort(string i_floorKeys, List<string> listSort)
|
| | | /// <param name="listRoom"></param>
|
| | | /// <returns></returns>
|
| | | public List<Room> SortRoom(List<Room> listRoom)
|
| | | {
|
| | | Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>();
|
| | | //读取房间顺序
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile);
|
| | | var strData = UserCenterLogic.LoadFileContent(fullName);
|
| | | if (strData != null)
|
| | | //从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | var listName = new List<string>();
|
| | | foreach (var room in listRoom)
|
| | | {
|
| | | dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
|
| | | listName.Add(room.Name);
|
| | | }
|
| | | int numberLength = this.GetNumberMaxLength(listName);
|
| | |
|
| | | //保存顺序
|
| | | dicAllSort[i_floorKeys] = listSort;
|
| | | UserCenterLogic.SaveFileContent(fullName, dicAllSort);
|
| | | dicAllSort.Clear();
|
| | | var listSort = new List<string[]>();
|
| | | foreach (var room in listRoom)
|
| | | {
|
| | | var strArry = new string[2];
|
| | | strArry[0] = room.Id;
|
| | | strArry[1] = string.Empty;
|
| | |
|
| | | string value = string.Empty;
|
| | | foreach (var c in room.Name)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //如果房间名字带有数字的话,则左边加零,因为这里有个排序的问题
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | value = string.Empty;
|
| | | }
|
| | | strArry[1] += c.ToString();
|
| | | }
|
| | | if (value != string.Empty)
|
| | | {
|
| | | //以数字结尾的话
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | }
|
| | | listSort.Add(strArry);
|
| | | }
|
| | | //排序
|
| | | listSort.Sort((obj1, obj2) =>
|
| | | {
|
| | | if (obj1[1].CompareTo(obj2[1]) > 0)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | });
|
| | | var listSortRoom = new List<Room>();
|
| | | foreach (var strArry in listSort)
|
| | | {
|
| | | var room = this.GetRoomById(strArry[0]);
|
| | | listSortRoom.Add(room);
|
| | | }
|
| | | return listSortRoom;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public Dictionary<string, string> GetFloorSortList()
|
| | | {
|
| | | //读取楼层顺序
|
| | | var listFloorSort = new List<string>();
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile);
|
| | | var strData = UserCenterLogic.LoadFileContent(fullName);
|
| | | if (strData != null)
|
| | | //没有楼层
|
| | | if (Config.Instance.Home.FloorDics.Count == 0)
|
| | | {
|
| | | listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData);
|
| | | return new Dictionary<string, string>();
|
| | | }
|
| | | foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys)
|
| | | //从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | var listName = new List<string>();
|
| | | foreach (var floorName in Config.Instance.Home.FloorDics.Values)
|
| | | {
|
| | | if (listFloorSort.Contains(keys) == false)
|
| | | {
|
| | | //新添加的楼层
|
| | | listFloorSort.Add(keys);
|
| | | }
|
| | | listName.Add(floorName);
|
| | | }
|
| | | int numberLength = this.GetNumberMaxLength(listName);
|
| | |
|
| | | var listSort = new List<string[]>();
|
| | | foreach (var floorId in Config.Instance.Home.FloorDics.Keys)
|
| | | {
|
| | | var strArry = new string[2];
|
| | | strArry[0] = floorId;
|
| | | strArry[1] = string.Empty;
|
| | |
|
| | | string value = string.Empty;
|
| | | string floorName = Config.Instance.Home.FloorDics[floorId];
|
| | | foreach (var c in floorName)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //如果房间名字带有数字的话,则左边加零,因为这里有个排序的问题
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | value = string.Empty;
|
| | | }
|
| | | strArry[1] += c.ToString();
|
| | | }
|
| | | if (value != string.Empty)
|
| | | {
|
| | | //以数字结尾的话
|
| | | strArry[1] += value.PadLeft(numberLength, '0');
|
| | | }
|
| | | listSort.Add(strArry);
|
| | | }
|
| | | //楼层排序
|
| | | listSort.Sort((obj1, obj2) =>
|
| | | {
|
| | | if (obj1[1].CompareTo(obj2[1]) > 0)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | | return -1;
|
| | | });
|
| | | var dic = new Dictionary<string, string>();
|
| | | for (int i = 0; i < listFloorSort.Count; i++)
|
| | | foreach (var strArry in listSort)
|
| | | {
|
| | | if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true)
|
| | | {
|
| | | dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]];
|
| | | }
|
| | | dic[strArry[0]] = Config.Instance.Home.FloorDics[strArry[0]];
|
| | | }
|
| | |
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, listFloorSort);
|
| | | return dic;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 发送房间信息给网关_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 保存楼层的顺序
|
| | | /// 发送房间信息给网关
|
| | | /// </summary>
|
| | | /// <param name="listSort">楼层的主键</param>
|
| | | public void SaveFloorSort(List<string> listSort)
|
| | | public void SetRoomInfoToGateway()
|
| | | {
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile);
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, listSort);
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2)
|
| | | {
|
| | | //不是主人和管理员,则不处理
|
| | | return;
|
| | | }
|
| | | var realMain = ZbGateway.MainGateWay;
|
| | | if (realMain == null || Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //没有主网关,则不理
|
| | | return;
|
| | | }
|
| | | //获取房间全部的设备对象
|
| | | string strSendDeviceRoomInfo = string.Empty;
|
| | | foreach (var room in this.dicRooms.Values)
|
| | | {
|
| | | if (room.IsSharedRoom || room.IsLove)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var listDevice = this.GetRoomListDevice(room);
|
| | | //发送给网关的设备房间json
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | if (strSendDeviceRoomInfo != string.Empty)
|
| | | {
|
| | | strSendDeviceRoomInfo += "\r\n";
|
| | | }
|
| | | strSendDeviceRoomInfo += " " + this.SetDoublMark(device.DeviceAddr) + " ";
|
| | | strSendDeviceRoomInfo += this.SetDoublMark("0x" + Convert.ToString(device.DeviceEpoint, 16).PadLeft(2, '0')) + " ";
|
| | | strSendDeviceRoomInfo += this.SetDoublMark(LocalDevice.Current.GetDeviceEpointName(device).Replace(UserCenterResourse.douMarks, string.Empty)) + " ";
|
| | | strSendDeviceRoomInfo += this.SetDoublMark(room.Id);
|
| | | }
|
| | | }
|
| | |
|
| | | var listAreaSpaceInfo = new List<AreaSpaceInfo>();
|
| | | //首先添加住宅
|
| | | var houseInfo = new AreaSpaceInfo();
|
| | | houseInfo.name = Common.Config.Instance.Home.Name;
|
| | | houseInfo.uid = Common.Config.Instance.Home.Id;
|
| | | houseInfo.parentId = null;
|
| | | listAreaSpaceInfo.Add(houseInfo);
|
| | | //然后添加楼层
|
| | | foreach (var floorId in Common.Config.Instance.Home.FloorDics.Keys)
|
| | | {
|
| | | var floorInfo = new AreaSpaceInfo();
|
| | | floorInfo.name = Common.Config.Instance.Home.FloorDics[floorId];
|
| | | floorInfo.uid = floorId;
|
| | | floorInfo.parentId = Common.Config.Instance.Home.Id;
|
| | | listAreaSpaceInfo.Add(floorInfo);
|
| | | }
|
| | | //然后添加房间
|
| | | var listRoom = this.GetAllListRooms();
|
| | | foreach (var room in listRoom)
|
| | | {
|
| | | if (room.IsLove == true) { continue; }
|
| | |
|
| | | var roomInfo = new AreaSpaceInfo();
|
| | | roomInfo.name = room.Name;
|
| | | roomInfo.uid = room.Id;
|
| | | if (Common.Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true)
|
| | | {
|
| | | roomInfo.parentId = room.FloorId;
|
| | | }
|
| | | else
|
| | | {
|
| | | roomInfo.parentId = Common.Config.Instance.Home.Id;
|
| | | }
|
| | | listAreaSpaceInfo.Add(roomInfo);
|
| | | }
|
| | | //然后添加网关房间信息
|
| | | var gatewayInfo = new GatewayAreaSpaceInfo();
|
| | |
|
| | | var loaclGateway = HdlGatewayLogic.Current.GetLocalGateway(realMain.GwId);
|
| | | if (loaclGateway == null || loaclGateway.GwMac == string.Empty)
|
| | | {
|
| | | //没有mac,或者找不到对象,则不上传
|
| | | return;
|
| | | }
|
| | | string gwMac = loaclGateway.GwMac.Replace(":", string.Empty);
|
| | | gatewayInfo.uid = "000101" + gwMac.Substring(2) + "07";
|
| | | gatewayInfo.name = HdlGatewayLogic.Current.GetGatewayName(loaclGateway);
|
| | |
|
| | | var roomGateway = HdlRoomLogic.Current.GetRoomByGateway(loaclGateway);
|
| | | if (roomGateway != null)
|
| | | {
|
| | | gatewayInfo.parentId = roomGateway.Id;
|
| | | }
|
| | | gatewayInfo.hwInfo = new GatewayHwInfo();
|
| | | gatewayInfo.pkgInfo = new GatewayPkgInfo { version = loaclGateway.LinuxFirmwareVersion.ToString() };
|
| | | gatewayInfo.swInfo = new List<GatewaySwInfo> { new GatewaySwInfo { ver = loaclGateway.LinuxFirmwareVersion.ToString() } };
|
| | | gatewayInfo.ip = loaclGateway.GwIP;
|
| | | gatewayInfo.mac = loaclGateway.GwMac;
|
| | |
|
| | | var data = new { spaces = listAreaSpaceInfo, gateway = gatewayInfo };
|
| | | string strSendRoomInfo = Newtonsoft.Json.JsonConvert.SerializeObject(data);
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | //发送设备区域信息
|
| | | if (strSendDeviceRoomInfo != string.Empty)
|
| | | {
|
| | | //创建文件对象
|
| | | var result0 = await realMain.CreateFileAsync("DeviceRoomInfo.json");
|
| | | if (result0 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result0.Result != 0 && result0.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | | //发送数据流
|
| | | var byteData = ASCIIEncoding.UTF8.GetBytes(strSendDeviceRoomInfo);
|
| | | var result1 = await realMain.SendFileAsync(byteData);
|
| | | if (result1 == null || result1.Result != 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | //创建文件对象
|
| | | var result3 = await realMain.CreateFileAsync("space.json");
|
| | | if (result3 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result3.Result != 0 && result3.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | |
|
| | | //发送区域信息
|
| | | var byteData2 = ASCIIEncoding.UTF8.GetBytes(strSendRoomInfo);
|
| | | var result4 = await realMain.SendFileAsync(byteData2);
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置双引号
|
| | | /// </summary>
|
| | | /// <param name="i_text"></param>
|
| | | /// <returns></returns>
|
| | | private string SetDoublMark(string i_text)
|
| | | {
|
| | | return UserCenterResourse.douMarks + i_text + UserCenterResourse.douMarks;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 空间区域信息
|
| | | /// </summary>
|
| | | private class AreaSpaceInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 住宅ID 或者 楼层ID 或者 房间ID
|
| | | /// </summary>
|
| | | public string uid = string.Empty;
|
| | | /// <summary>
|
| | | /// 住宅名称 或者 楼层名称 或者 房间名称
|
| | | /// </summary>
|
| | | public string name = string.Empty;
|
| | | /// <summary>
|
| | | /// 当前ID的父ID,如果没有,则为带双引号的"null" 比如 楼层ID就填住宅ID 房间ID就填楼层ID
|
| | | /// </summary>
|
| | | public string parentId = string.Empty;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关空间区域信息
|
| | | /// </summary>
|
| | | private class GatewayAreaSpaceInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 【000101】+绑定网关的时间戳转16进制+【07】
|
| | | /// </summary>
|
| | | public string uid = string.Empty;
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public string name = "hdl_bus_gatway";
|
| | | /// <summary>
|
| | | /// 网关所在的房间ID
|
| | | /// </summary>
|
| | | public string parentId = string.Empty;
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public int deviceType = 61184;
|
| | | /// <summary>
|
| | | /// 网关硬件信息
|
| | | /// </summary>
|
| | | public GatewayHwInfo hwInfo = null;
|
| | | /// <summary>
|
| | | /// 网关标准信息
|
| | | /// </summary>
|
| | | public GatewayPkgInfo pkgInfo = null;
|
| | | /// <summary>
|
| | | /// 网关固件版本
|
| | | /// </summary>
|
| | | public List<GatewaySwInfo> swInfo = null;
|
| | | /// <summary>
|
| | | /// 网关IP
|
| | | /// </summary>
|
| | | public string ip = string.Empty;
|
| | | /// <summary>
|
| | | /// 网关的Mac
|
| | | /// </summary>
|
| | | public string mac = string.Empty;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关硬件信息
|
| | | /// </summary>
|
| | | private class GatewayHwInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public string brand = "MIPS";
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public string model = "MT7688";
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关标准信息
|
| | | /// </summary>
|
| | | private class GatewayPkgInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 这个是Linux的固件版本
|
| | | /// </summary>
|
| | | public string version = string.Empty;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 网关固件版本
|
| | | /// </summary>
|
| | | private class GatewaySwInfo
|
| | | {
|
| | | /// <summary>
|
| | | /// 这个固定
|
| | | /// </summary>
|
| | | public string name = "HDL";
|
| | | /// <summary>
|
| | | /// 这个是Linux的固件版本
|
| | | /// </summary>
|
| | | public string ver = string.Empty;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | newRoom.Id = i_room.Id;
|
| | | newRoom.FloorId = i_room.FloorId;
|
| | | newRoom.TemperatrueDevice = i_room.TemperatrueDevice;
|
| | | newRoom.Temperatrue = i_room.Temperatrue;
|
| | | newRoom.HumidityDevice = i_room.HumidityDevice;
|
| | | newRoom.Humidity = i_room.Humidity;
|
| | | newRoom.Name = i_room.Name;
|
| | | newRoom.BackgroundImage = i_room.BackgroundImage;
|
| | | newRoom.BackgroundImageType = i_room.BackgroundImageType;
|
| | |
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取房间总数
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public int GetRoomCount()
|
| | | {
|
| | | return this.dicRooms.Count;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测我的喜爱这个房间对象
|
| | | /// </summary>
|
| | | private void CheckLoveRoom()
|
| | | {
|
| | | if (Config.Instance.Home.ListRooms.Contains("Favorite") == false)
|
| | | if (this.dicRooms.ContainsKey("Favorite") == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //读取本地我的喜爱文件
|
| | | string favoriteFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, "Room_Favorite.json");
|
| | | var fileContent = HdlFileLogic.Current.ReadFileTextContent(favoriteFile);
|
| | | if (fileContent != null)
|
| | | {
|
| | | var love = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(fileContent);
|
| | | this.dicRooms["Favorite"] = love;
|
| | | }
|
| | | else
|
| | | {
|
| | | //默认添加喜爱的房间--禁止修改房间名
|
| | | var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "RoomIcon/0.jpg", Id = "Favorite" };
|
| | | love.Save(false);
|
| | | //添加到house 房间路径列表
|
| | | var currentHome = Config.Instance.Home;
|
| | | currentHome.ListRooms.Insert(0, love.Id);
|
| | | currentHome.Save(false);
|
| | |
|
| | | this.dicRooms["Favorite"] = love;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从一堆文字中,获取这一堆文字里面数字字符串的最长长度
|
| | | /// </summary>
|
| | | /// <param name="listText"></param>
|
| | | /// <returns></returns>
|
| | | private int GetNumberMaxLength(List<string> listText)
|
| | | {
|
| | | int maxLength = 0;
|
| | | foreach (var text in listText)
|
| | | {
|
| | | string value = string.Empty;
|
| | | foreach (var c in text)
|
| | | {
|
| | | if (char.IsNumber(c) == true)
|
| | | {
|
| | | //数字
|
| | | value += c.ToString();
|
| | | continue;
|
| | | }
|
| | | else if (value != string.Empty)
|
| | | {
|
| | | //判断数字长度
|
| | | if (maxLength <= value.Length)
|
| | | {
|
| | | maxLength = value.Length;
|
| | | }
|
| | | value = string.Empty;
|
| | | }
|
| | | }
|
| | | //判断数字长度
|
| | | if (maxLength <= value.Length)
|
| | | {
|
| | | maxLength = value.Length;
|
| | | }
|
| | | }
|
| | | return maxLength;
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|