| | |
| | | public SpatialInfo(string spatialType) |
| | | { |
| | | roomType = "FLOOR"; |
| | | parentId = DB_ResidenceData.residenceData.CurReginID; |
| | | parentId = DB_ResidenceData.Instance.CurrentRegion.RegionID; |
| | | } |
| | | |
| | | public string roomId = ""; |
| | |
| | | } |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); |
| | | FileUtils.WriteFileByBytes(dataSavePath, ssd); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | var floorsDataBytes = FileUtils.ReadFile("FloorsData"); |
| | | var floorsDataBytes = Common.FileUtlis.Files.ReadFile("FloorsData"); |
| | | if (floorsDataBytes != null) |
| | | { |
| | | var floorsDataString = System.Text.Encoding.UTF8.GetString(floorsDataBytes); |
| | | MainPage.Log(floorsDataString); |
| | | floors = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(floorsDataString); |
| | | if (floors == null) |
| | | { |
| | | floors = new List<SpatialInfo>(); |
| | | } |
| | | } |
| | | if (floors == null) |
| | | { |
| | | floors = new List<SpatialInfo>(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | /// 增加楼层 |
| | | /// </summary> |
| | | /// <param name="floor"></param> |
| | | public void AddFloor(SpatialInfo floor) |
| | | public string AddFloor(SpatialInfo floor, out SpatialInfo newFloor) |
| | | { |
| | | if (floor.SaveFloorData() == StateCode.SUCCESS) |
| | | var pm = new HttpServerRequest(); |
| | | var revPack = new ResponsePackNew(); |
| | | revPack = pm.AddRoom(new List<SpatialInfo>() { floor }); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | FloorList.Add(floor); |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(revPack.Data.ToString()); |
| | | if (revData.Count > 0) |
| | | { |
| | | var addFloor = revData.Find((obj) => obj.uid == floor.uid); |
| | | if (addFloor != null) |
| | | { |
| | | CurrentSpatial.FloorList.Add(addFloor); |
| | | floor = addFloor; |
| | | } |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(CurrentSpatial.FloorList)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | else |
| | | { |
| | | Utlis.ShowTip(Language.StringByID(StringId.AddFloorFail) + "\r\nCode:" + revPack.Code); |
| | | } |
| | | newFloor = floor; |
| | | return revPack.Code; |
| | | } |
| | | /// <summary> |
| | | /// 更新楼层信息 |
| | | /// </summary> |
| | | /// <param name="floor"></param> |
| | | public void UpdateFloor() |
| | | public string UpdateFloor(SpatialInfo floor) |
| | | { |
| | | SaveFloorData(); |
| | | var pm = new HttpServerRequest(); |
| | | var revPack = pm.UpdateRoom(new List<SpatialInfo>() { floor }); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | return revPack.Code; |
| | | } |
| | | /// <summary> |
| | | /// 删除楼层 |
| | | /// </summary> |
| | | /// <param name="floor"></param> |
| | | public void DelFloor(SpatialInfo floor) |
| | | public string DelFloor(string floorId) |
| | | { |
| | | if (floor == null) |
| | | return; |
| | | if (string.IsNullOrEmpty( floorId)) |
| | | return ""; |
| | | var pm = new HttpServerRequest(); |
| | | var code = pm.DeleteRoom(new List<string>() { floor.roomId }).Code; |
| | | var code = pm.DeleteRoom(new List<string>() { floorId }).Code; |
| | | if (code == StateCode.SUCCESS) |
| | | { |
| | | var tRoom = FloorList.Find((obj) => obj.uid == floor.uid); |
| | | var tRoom = CurrentSpatial.FloorList.Find((obj) => obj.roomId == floorId); |
| | | if (tRoom != null) |
| | | { |
| | | FloorList.Remove(floor); |
| | | CurrentSpatial.FloorList.Remove(tRoom); |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); |
| | | FileUtils.WriteFileByBytes(dataSavePath, ssd); |
| | | MainPage.Log($"Save floor Data"); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | else |
| | | { |
| | | Utlis.ShowTip(Language.StringByID(StringId.DeleteFloorFail) + "Code:" + code); |
| | | Utlis.ShowTip(Language.StringByID(StringId.DeleteFloorFail) + "\r\nCode:" + code); |
| | | } |
| | | return code; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存楼层数据 |
| | | /// </summary> |
| | | string SaveFloorData() |
| | | { |
| | | var pack = SaveSpatialInfo(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); |
| | | FileUtils.WriteFileByBytes(dataSavePath, ssd); |
| | | MainPage.Log($"Save floor Data"); |
| | | } |
| | | else |
| | | { |
| | | Utlis.ShowTip(Language.StringByID(StringId.EditRoomInfoFail) + "Code:" + pack.Code); |
| | | } |
| | | return pack.Code; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | try |
| | | { |
| | | rooms = new List<Room> { }; |
| | | var filePathList = FileUtils.ReadFiles(); |
| | | var filePathList = Common.FileUtlis.Files.ReadFiles(); |
| | | |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | if (filePath.StartsWith("RoomData_")) |
| | | { |
| | | var roomDataBytes = FileUtils.ReadFile(filePath); |
| | | var roomDataBytes = Common.FileUtlis.Files.ReadFile(filePath); |
| | | var roomDataString = System.Text.Encoding.UTF8.GetString(roomDataBytes); |
| | | var room = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(roomDataString); |
| | | if (room != null) |
| | |
| | | /// 增加房间 |
| | | /// </summary> |
| | | /// <param name="room"></param> |
| | | public void AddRoom(Room room) |
| | | public string AddRoom(Room room,out Room newRoom) |
| | | { |
| | | if (room.SaveRoomData() == StateCode.SUCCESS) |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.AddRoom(new List<SpatialInfo>() { room }); |
| | | |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | RoomList.Add(room); |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); |
| | | if (revData != null) |
| | | { |
| | | if (revData.Count > 0) |
| | | { |
| | | var tempRoom = revData.Find((obj) => obj.uid == room.uid); |
| | | if (tempRoom != null) |
| | | { |
| | | room.roomId = tempRoom.roomId; |
| | | CurrentSpatial.RoomList.Add(room); |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(room)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | newRoom = room; |
| | | return pack.Code; |
| | | } |
| | | /// <summary> |
| | | /// 删除房间 |
| | | /// </summary> |
| | | /// <param name="room"></param> |
| | | public void DelRoom(Room room) |
| | | public string DelRoom(Room room) |
| | | { |
| | | new System.Threading.Thread(() => |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.DeleteRoom(new List<string>() { room.roomId }); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.DeleteRoom(new List<string>() { room.roomId }); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | var tRoom = RoomList.Find((obj) => obj.roomId == room.roomId); |
| | | if (tRoom != null) |
| | | { |
| | | var tRoom = RoomList.Find((obj) => obj.uid == room.uid); |
| | | if (tRoom != null) |
| | | { |
| | | RoomList.Remove(room); |
| | | } |
| | | FileUtils.DeleteFile(room.dataSavePath); |
| | | CurrentSpatial.RoomList.Remove(room); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | Common.FileUtlis.Files.DeleteFile(room.dataSavePath); |
| | | } |
| | | return pack.Code; |
| | | } |
| | | /// <summary> |
| | | /// 删除所有房间 |
| | |
| | | { |
| | | foreach(var localRoom in RoomList) |
| | | { |
| | | FileUtils.DeleteFile(localRoom.dataSavePath); |
| | | Common.FileUtlis.Files.DeleteFile(localRoom.dataSavePath); |
| | | } |
| | | RoomList.Clear(); |
| | | rooms = null; |
| | | } |
| | | |
| | | public void Clear() |
| | | { |
| | | if (_currentSpatial != null) |
| | | { |
| | | if (_currentSpatial.floors != null) |
| | | { |
| | | _currentSpatial.floors.Clear(); |
| | | } |
| | | if (_currentSpatial.rooms != null) |
| | | { |
| | | _currentSpatial.rooms.Clear(); |
| | | } |
| | | _currentSpatial = null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化每个房间的功能数据 |
| | | /// </summary> |
| | |
| | | if (needSave) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtils.WriteFileByBytes(dataSavePath, ssd); |
| | | MainPage.Log($"Save Room Data {roomName} : {uid}"); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | return packCode; |
| | | } |
| | |
| | | { |
| | | get |
| | | { |
| | | if (FloorList.Count > 0) |
| | | if (CurrentSpatial.FloorList.Count > 0) |
| | | { |
| | | var f = FloorList.Find((obj) => obj.uid == parentId); |
| | | var f = CurrentSpatial.FloorList.Find((obj) => obj.roomId == parentId); |
| | | if (f != null) |
| | | { |
| | | return f.roomName + " "; |
| | |
| | | } |
| | | if (functions.Count == 0) |
| | | { |
| | | foreach (var f in DB_ResidenceData.functionList.GetAllFunction()) |
| | | foreach (var f in FunctionList.List.GetDeviceFunctionList()) |
| | | { |
| | | if (f.roomIds.Contains(uid) && uid != null) |
| | | if (f.roomIds.Contains(roomId) && roomId != null) |
| | | { |
| | | functions.Add(f); |
| | | } |
| | |
| | | } |
| | | if (scenes.Count == 0) |
| | | { |
| | | foreach (var s in DB_ResidenceData.functionList.scenes) |
| | | foreach (var s in FunctionList.List.scenes) |
| | | { |
| | | if (s.roomIds.Contains(uid) && uid != null) |
| | | if (s.roomIds.Contains(roomId) && roomId != null) |
| | | { |
| | | scenes.Add(s); |
| | | } |