| | |
| | | public SpatialInfo(string spatialType) |
| | | { |
| | | roomType = "FLOOR"; |
| | | parentId = UserInfo.Current.CurReginID; |
| | | parentId = DB_ResidenceData.Instance.CurrentRegion.id; |
| | | } |
| | | |
| | | public string homeId = ""; |
| | | public string roomId = ""; |
| | | public string roomName = ""; |
| | | //public string roomImage = ""; |
| | |
| | | public string roomType = ""; |
| | | public string parentId = ""; |
| | | public string uid = Guid.NewGuid().ToString(); |
| | | public string floorRoomName = ""; |
| | | public string createTime = ""; |
| | | public string modifyTime = ""; |
| | | ///// <summary> |
| | |
| | | ///// </summary> |
| | | //public bool DeleteSign = false; |
| | | |
| | | |
| | | protected ResponsePackNew SaveSpatialInfo() |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var revPack = new ResponsePackNew(); |
| | | if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) |
| | | { |
| | | revPack = pm.AddRoom(new List<SpatialInfo>() { this }); |
| | | } |
| | | else if (string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) |
| | | { |
| | | revPack = pm.DeleteRoom(new List<string>() { roomId }); |
| | | } |
| | | else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) |
| | | { |
| | | revPack = pm.UpdateRoom(new List<SpatialInfo>() { this }); |
| | | } |
| | | return revPack; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载云端房间数据 |
| | | /// </summary> |
| | | public void DownloadRoomList() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.GetRoomList(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(pack.Data.ToString()); |
| | | if (revData != null) |
| | | { |
| | | CurrentSpatial.UpdateSpatialList(revData.list, OptionType.Cover); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"读取房间数据失败:\r\nCode:{pack.Code}; msg:{pack.message}"); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新空间信息 |
| | | /// </summary> |
| | | /// <param name="spatials">空间信息</param> |
| | | /// <param name="optionType">操作类型:ADD/UPDATE/DELETE</param> |
| | | public void UpdateSpatialList(List<SpatialInfo> spatials,OptionType optionType) |
| | | public void UpdateSpatialList(List<SpatialInfo> spatials) |
| | | { |
| | | var roomUpdateList = spatials.FindAll((obj) => obj.roomType == "ROOM"); |
| | | var floorUpdateList = spatials.FindAll((obj) => obj.roomType == "FLOOR"); |
| | | CurrentSpatial.DeleteAllRoom(); |
| | | FloorList.Clear(); |
| | | //处理房间列表 |
| | | if (roomUpdateList != null && roomUpdateList.Count > 0) |
| | | { |
| | | if (optionType == OptionType.Update) |
| | | foreach (var newRoom in roomUpdateList) |
| | | { |
| | | foreach (var updateTemp in roomUpdateList) |
| | | { |
| | | var localRoom = CurrentSpatial.RoomList.Find((obj) => obj.roomId == updateTemp.roomId); |
| | | if (localRoom != null) |
| | | { |
| | | if (localRoom.modifyTime != updateTemp.modifyTime) |
| | | { |
| | | localRoom.roomName = updateTemp.roomName; |
| | | localRoom.roomImage = updateTemp.roomImage; |
| | | localRoom.parentId = updateTemp.parentId; |
| | | localRoom.createTime = updateTemp.createTime; |
| | | localRoom.modifyTime = updateTemp.modifyTime; |
| | | localRoom.SaveRoomData(false); |
| | | } |
| | | }else |
| | | { |
| | | updateTemp.SaveRoomData(false); |
| | | } |
| | | } |
| | | } |
| | | else if (optionType == OptionType.Cover) |
| | | { |
| | | CurrentSpatial.DeleteAllRoom(); |
| | | foreach(var newRoom in roomUpdateList) |
| | | { |
| | | newRoom.SaveRoomData(false); |
| | | RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>( |
| | | Newtonsoft.Json.JsonConvert.SerializeObject(newRoom))); |
| | | } |
| | | newRoom.SaveRoomFile(); |
| | | RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>( |
| | | Newtonsoft.Json.JsonConvert.SerializeObject(newRoom))); |
| | | } |
| | | } |
| | | //楼层房间列表 |
| | | if (floorUpdateList != null && floorUpdateList.Count > 0) |
| | | { |
| | | if (optionType == OptionType.Update) |
| | | foreach (var updateTemp in floorUpdateList) |
| | | { |
| | | foreach(var updateTemp in floorUpdateList) |
| | | { |
| | | var localFloor = FloorList.Find((obj) => obj.roomId == updateTemp.roomId); |
| | | if (localFloor == null) |
| | | { |
| | | FloorList.Add(updateTemp); |
| | | } |
| | | else |
| | | { |
| | | localFloor = updateTemp; |
| | | } |
| | | } |
| | | } |
| | | if(optionType == OptionType.Cover) |
| | | { |
| | | FloorList.Clear(); |
| | | foreach (var updateTemp in floorUpdateList) |
| | | { |
| | | FloorList.Add(updateTemp); |
| | | } |
| | | FloorList.Add(updateTemp); |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | |
| | | { |
| | | get |
| | | { |
| | | if (MainPage.NoLoginMode) |
| | | { |
| | | if (floors == null) |
| | | { |
| | | floors = new List<SpatialInfo>(); |
| | | } |
| | | return floors; |
| | | } |
| | | |
| | | if (floors == null) |
| | | { |
| | | try |
| | |
| | | MainPage.Log(floorsDataString); |
| | | floors = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(floorsDataString); |
| | | } |
| | | if (floors == null) |
| | | if(floors == null) |
| | | { |
| | | floors = new List<SpatialInfo>(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | floors = new List<SpatialInfo>(); |
| | | MainPage.Log($"楼层数据初始化失败:{ex.Message}"); |
| | | } |
| | | } |
| | |
| | | { |
| | | get |
| | | { |
| | | if(MainPage.NoLoginMode ) |
| | | { |
| | | if (rooms == null) |
| | | { |
| | | rooms = new List<Room>(); |
| | | } |
| | | return rooms; |
| | | } |
| | | if (rooms == null) |
| | | { |
| | | try |
| | |
| | | /// </summary> |
| | | public void DeleteAllRoom() |
| | | { |
| | | foreach(var localRoom in RoomList) |
| | | for(int i=0;i< RoomList.Count;) |
| | | { |
| | | Common.FileUtlis.Files.DeleteFile(localRoom.dataSavePath); |
| | | Common.FileUtlis.Files.DeleteFile(RoomList[i].dataSavePath); |
| | | RoomList.RemoveAt(i); |
| | | } |
| | | rooms = null; |
| | | } |
| | | |
| | | public void ClearRooms() |
| | | public void Clear() |
| | | { |
| | | if (floors != null) |
| | | if (_currentSpatial != null) |
| | | { |
| | | floors.Clear(); |
| | | } |
| | | if (rooms != null) |
| | | { |
| | | rooms.Clear(); |
| | | if (_currentSpatial.floors != null) |
| | | { |
| | | _currentSpatial.floors.Clear(); |
| | | } |
| | | if (_currentSpatial.rooms != null) |
| | | { |
| | | _currentSpatial.rooms.Clear(); |
| | | } |
| | | _currentSpatial = null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化每个房间的功能数据 |
| | | /// </summary> |
| | | public void InitRoomFunction() |
| | | public void InitRoomListFunctions() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | |
| | | //初始化住宅所有房间功能数据 |
| | | foreach (var r in RoomList) |
| | | { |
| | | r.GetRoomFunctions(true); |
| | | r.GetRoomScenes(true); |
| | | InitRoomFuntion(r); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 初始化房间功能 |
| | | /// </summary> |
| | | /// <param name="tempRoom"></param> |
| | | public void InitRoomFuntion(Room tempRoom) |
| | | { |
| | | tempRoom.GetRoomFunctions(true); |
| | | tempRoom.GetRoomScenes(true); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存房间数据 |
| | | /// 保存房间数据文件 |
| | | /// </summary> |
| | | public string SaveRoomData(bool upServer = true) |
| | | public void SaveRoomFile() |
| | | { |
| | | var packCode = StateCode.SUCCESS; |
| | | bool needSave = true; |
| | | if (upServer) |
| | | { |
| | | packCode = SaveSpatialInfo().Code; |
| | | } |
| | | if (needSave) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | return packCode; |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); |
| | | } |
| | | /// <summary> |
| | | /// 更新房间数据 |
| | | /// </summary> |
| | | public void UpdataRoomInfo() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.UpdateRoom(new List<SpatialInfo>() { this }); |
| | | this.SaveRoomFile(); |
| | | if (pack.Code != StateCode.SUCCESS) |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | |
| | | { |
| | | if (CurrentSpatial.FloorList.Count > 0) |
| | | { |
| | | var f = CurrentSpatial.FloorList.Find((obj) => obj.roomId == parentId); |
| | | var f = CurrentSpatial.FloorList.Find((obj) => obj.uid == parentId); |
| | | if (f != null) |
| | | { |
| | | return f.roomName + " "; |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 房间功能列表 |
| | | /// </summary> |
| | | List<Function> functions = new List<Function>(); |
| | | ///// <summary> |
| | | ///// 房间功能列表 |
| | | ///// </summary> |
| | | //List<Function> functions = new List<Function>(); |
| | | /// <summary> |
| | | /// 获取房间功能列表 |
| | | /// </summary> |
| | |
| | | { |
| | | if (needRefresh) |
| | | { |
| | | functions = new List<Function>(); |
| | | } |
| | | var functions = new List<Function>(); |
| | | if (functions.Count == 0) |
| | | { |
| | | foreach (var f in FunctionList.List.GetDeviceFunctionList()) |
| | |
| | | } |
| | | return functions; |
| | | } |
| | | /// <summary> |
| | | /// 增加房间功能 |
| | | /// 操作的是缓存数据,不用保存 |
| | | /// </summary> |
| | | public void AddRoomFunction(Function function) |
| | | { |
| | | functions.Add(function); |
| | | } |
| | | /// <summary> |
| | | /// 删除房间功能 |
| | | /// 操作的是缓存数据,不用保存 |
| | | /// </summary> |
| | | public void RemoveRoomFunction(Function function) |
| | | { |
| | | functions.Remove(functions.Find((obj) => obj.sid == function.sid)); |
| | | } |
| | | ///// <summary> |
| | | ///// 增加房间功能 |
| | | ///// 操作的是缓存数据,不用保存 |
| | | ///// </summary> |
| | | //public void AddRoomFunction(Function function) |
| | | //{ |
| | | // functions.Add(function); |
| | | //} |
| | | ///// <summary> |
| | | ///// 删除房间功能 |
| | | ///// 操作的是缓存数据,不用保存 |
| | | ///// </summary> |
| | | //public void RemoveRoomFunction(Function function) |
| | | //{ |
| | | // functions.Remove(functions.Find((obj) => obj.sid == function.sid)); |
| | | //} |
| | | /// <summary> |
| | | /// 房间场景列表 |
| | | /// </summary> |