| | |
| | | using System.Text; |
| | | using ZigBee.Device; |
| | | using System.Linq; |
| | | |
| | | using Shared.Phone;
|
| | |
|
| | | namespace Shared.Common |
| | | { |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class Room |
| | | { |
| | | #region ◆ 变量____________________________ |
| | | {
|
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 房间文件 |
| | | /// 是否是喜爱房间 |
| | | /// </summary> |
| | | /// <value>The name of the file.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string FileName |
| | | public bool IsLove |
| | | { |
| | | get |
| | | { |
| | | return $"Room_{Id}.json"; |
| | | return Id == "Favorite"; |
| | | } |
| | | }
|
| | | /// <summary>
|
| | | /// 房间文件
|
| | | /// </summary>
|
| | | [Newtonsoft.Json.JsonIgnore]
|
| | | public string FileName
|
| | | {
|
| | | get
|
| | | {
|
| | | return $"Room_{Id}.json";
|
| | | }
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 房间id--使用guid |
| | | /// Guid.NewGuid().ToString() |
| | | /// </summary> |
| | | public string Id = Guid.NewGuid().ToString(); |
| | | /// <summary> |
| | | /// 楼层Id |
| | | /// 新增时使用Guid |
| | | /// </summary> |
| | | public string FloorId = string.Empty; |
| | | /// <summary> |
| | | /// 楼层名称 |
| | | /// </summary> |
| | | public string FloorName |
| | | { |
| | | get |
| | | { |
| | | return Config.Instance.Home.GetFloorNameById(FloorId); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 房间名 |
| | | /// </summary> |
| | | public string Name = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 房间背景图 |
| | | /// </summary> |
| | | public string BackgroundImage = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 图片来源 0--本地图库 1--拍照 2--系统图库 |
| | | /// </summary> |
| | | public int BackgroundImageType = 0; |
| | | |
| | | /// <summary> |
| | | /// 楼层--备用 |
| | | /// </summary> |
| | | public Dictionary<string, string> FloorList = new Dictionary<string, string> { }; |
| | | |
| | | /// <summary>
|
| | | /// 温度传感器(设备主键)
|
| | | /// </summary> |
| | |
| | | /// <summary>
|
| | | /// 湿度传感器(设备主键)
|
| | | /// </summary> |
| | | public string HumidityDevice = string.Empty; |
| | | /// <summary> |
| | | /// 温度 |
| | | /// </summary> |
| | | public decimal Temperatrue; |
| | | /// <summary> |
| | | /// 湿度 |
| | | /// </summary> |
| | | public decimal Humidity; |
| | | |
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// </summary> |
| | | private static Room m_CurrentRoom = null; |
| | | /// <summary> |
| | | /// 当前选择的房间 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static Room CurrentRoom
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_CurrentRoom == null && Lists.Count > 0)
|
| | | {
|
| | | return Lists[0];
|
| | | }
|
| | | return m_CurrentRoom;
|
| | | }
|
| | | set { m_CurrentRoom = value; }
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 房间里所有的设备列表 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<DeviceUI> DeviceUIList = new List<DeviceUI> { }; |
| | | /// <summary> |
| | | ///设备文件路径列表 |
| | | /// </summary> |
| | | public readonly List<string> DeviceUIFilePathList = new List<string>(); |
| | | |
| | | /// <summary> |
| | | /// 喜爱房间id |
| | | /// </summary> |
| | | public const string LoveRoomId= "Favorite"; |
| | | |
| | | /// <summary> |
| | | /// 是否是默认喜爱房间 |
| | | /// </summary> |
| | | /// <value><c>true</c> if is love; otherwise, <c>false</c>.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool IsLove |
| | | { |
| | | get |
| | | { |
| | | return Id == LoveRoomId; |
| | | } |
| | | } |
| | | |
| | | public string HumidityDevice = string.Empty;
|
| | | /// <summary> |
| | | /// 是否是分享过来的房间 |
| | | /// 注:分享过来的房间不能删除,不能编辑该房间,不能对设备(功能)、场景进行增删改 |
| | | /// </summary> |
| | | public bool IsSharedRoom = false; |
| | | |
| | | public bool IsSharedRoom = false;
|
| | | /// <summary> |
| | | /// 获取喜爱房间的所有设备路径 |
| | | /// 楼层Id |
| | | /// </summary> |
| | | /// <value>The love room device list.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<string> LoveRoomDeviceUIFilePathList |
| | | { |
| | | get |
| | | { |
| | | if (Lists.Count == 0) |
| | | { |
| | | return new List<string> { }; |
| | | } |
| | | return CurrentRoom.GetLoveRoom().DeviceUIFilePathList; |
| | | } |
| | | } |
| | | |
| | | public string FloorId = string.Empty;
|
| | |
|
| | | /// <summary> |
| | | /// 所有房间的所有设备类型 |
| | | /// 房间里所有的设备列表(设备的主键:mac地址_端口) |
| | | /// </summary> |
| | | /// <value>All room device type list.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<DeviceType> AllRoomDeviceTypeList |
| | | { |
| | | get |
| | | { |
| | | var typeList = new List<DeviceType> { }; |
| | | foreach (var deviceUI in AllRoomDeviceUIList) |
| | | { |
| | | if (deviceUI == null || deviceUI.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (!typeList.Contains(deviceUI.CommonDevice.Type)) |
| | | { |
| | | typeList.Add(deviceUI.CommonDevice.Type); |
| | | } |
| | | } |
| | | return typeList; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取所有房间的所有场景 |
| | | /// </summary> |
| | | /// <value>All room scene UIL ist.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<SceneUI> AllRoomSceneUIList |
| | | { |
| | | get |
| | | { |
| | | var sceneList = new List<SceneUI> { }; |
| | | foreach (var r in Shared.Common.Room.Lists) |
| | | { |
| | | if (r.SceneUIList.Count == 0) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var sceneUI in r.SceneUIList) |
| | | { |
| | | if (sceneUI == null) |
| | | { |
| | | continue; |
| | | } |
| | | sceneList.Add(sceneUI); |
| | | } |
| | | } |
| | | return sceneList; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取所有房间的所有场景路径 |
| | | /// </summary> |
| | | /// <value>All room scene UIL ist.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<string> AllRoomSceneUIFilepathList |
| | | { |
| | | get |
| | | { |
| | | var pathList = new List<string> { }; |
| | | foreach (var r in Lists) |
| | | { |
| | | if (r.SceneUIFilePathList.Count == 0) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var path in r.SceneUIFilePathList) |
| | | { |
| | | pathList.Add(path); |
| | | } |
| | | } |
| | | return pathList; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 场景列表---不再序列化 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<SceneUI> SceneUIList = new List<SceneUI> { }; |
| | | /// <summary> |
| | | ///场景文件列表 |
| | | /// </summary> |
| | | public readonly List<string> SceneUIFilePathList = new List<string>(); |
| | | |
| | | /// <summary> |
| | | /// 所有的房间信息 |
| | | /// </summary> |
| | | public static List<Room> Lists = new List<Room>(); |
| | | |
| | | /// <summary> |
| | | /// 获取所有房间的所有设备 |
| | | /// </summary> |
| | | /// <value>All room device UIL ist.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<DeviceUI> AllRoomDeviceUIList |
| | | { |
| | | get |
| | | { |
| | | List<DeviceUI> deviceList = new List<DeviceUI>(); |
| | | for (int i = 0; i < Lists.Count; i++) |
| | | {
|
| | | var room = Lists[i]; |
| | | if (room.IsSharedRoom) |
| | | { |
| | | continue; |
| | | } |
| | | if (room.DeviceUIList.Count == 0) |
| | | { |
| | | continue; |
| | | } |
| | | for (int j = 0; j < room.DeviceUIList.Count; j++) |
| | | { |
| | | var device = room.DeviceUIList[j]; |
| | | if (device == null || device.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (deviceList.Find((obj) => obj.FileName == device.FileName) == null) |
| | | { |
| | | deviceList.Add(device); |
| | | } |
| | | } |
| | | } |
| | | return deviceList; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 构造方法________________________ |
| | | |
| | | /// <summary> |
| | | /// 构造方法 |
| | | /// </summary> |
| | | static Room() |
| | | { |
| | | InitAllRoom(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 初始化__________________________ |
| | | |
| | | /// <summary> |
| | | /// 初始化房间信息 |
| | | /// 从文件中全部读取所有的房间数据到内存 |
| | | /// </summary> |
| | | public static void InitAllRoom() |
| | | { |
| | | Lists.Clear(); |
| | | if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false) |
| | | { |
| | | //默认添加喜爱的房间--禁止修改房间名 |
| | | var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "RoomIcon/0.JPG", Id = LoveRoomId }; |
| | | love.Save(false); |
| | | //添加到house 房间路径列表 |
| | | var currentHome = Config.Instance.Home; |
| | | currentHome.RoomFilePathList.Insert(0, love.FileName); |
| | | currentHome.Save(false); |
| | | } |
| | | foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList) |
| | | { |
| | | var room = GetRoomByFilePath(roomFilePath); |
| | | |
| | | if (null != room) |
| | | { |
| | | if (room.IsSharedRoom) |
| | | { |
| | | room.Name = $"{room.Name}"; |
| | | } |
| | | Lists.Add(room); |
| | | |
| | | } |
| | | } |
| | | Config.Instance.Home.InitFloor(); |
| | | |
| | | CurrentRoom.RefreshRoomListView(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新房间视图列表 |
| | | /// </summary> |
| | | public void RefreshRoomListView() |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | Phone.Device.Room.RoomManagement.Instance.Show(); |
| | | }); |
| | | } |
| | | |
| | | public List<string> ListDevice = new List<string>(); |
| | | /// <summary>
|
| | | /// 从本地重新加载全部的房间
|
| | | /// 房间内所有设备的Mac列表(物理设备所在的区域专用,含网关)
|
| | | /// </summary> |
| | | public static void RefreshAllRoomByLocation()
|
| | | {
|
| | | Lists.Clear();
|
| | | var homeTemp = Config.Instance.Home;
|
| | | homeTemp.RoomFilePathList.Clear();
|
| | |
|
| | | var listFile = Global.FileListByHomeId();
|
| | |
|
| | | //我的喜爱的房间必须要在第0位才行
|
| | | string fRoom = "Room_Favorite.json";
|
| | | if (listFile.Contains(fRoom) == true)
|
| | | {
|
| | | listFile.Remove(fRoom);
|
| | | homeTemp.AddRoomListFilePath(fRoom);
|
| | | }
|
| | |
|
| | | var listRoomFile = new List<string>();
|
| | | foreach (string fileName in listFile)
|
| | | {
|
| | | if (fileName.StartsWith("Room_"))
|
| | | {
|
| | | homeTemp.AddRoomListFilePath(fileName);
|
| | | listRoomFile.Add(fileName);
|
| | | }
|
| | | }
|
| | | //检测楼层数据的合法性
|
| | | CheckFloorData(listRoomFile);
|
| | |
|
| | | homeTemp.Save(false);
|
| | | InitAllRoom();
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 检测楼层数据的合法性
|
| | | /// </summary>
|
| | | /// <param name="listRoomFile"></param> |
| | | private static void CheckFloorData(List<string> listRoomFile)
|
| | | {
|
| | | for (int i = 0; i < listRoomFile.Count; i++)
|
| | | {
|
| | | try
|
| | | {
|
| | | var byteData = Global.ReadFileByHomeId(listRoomFile[i]);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData);
|
| | |
|
| | | //检测多个手机来回创建,然后又删除之后,楼层数据不能保证100%同步的问题
|
| | | if (roomTemp.FloorId != string.Empty && Config.Instance.Home.FloorDics.ContainsKey(roomTemp.FloorId) == false)
|
| | | {
|
| | | //未知楼层
|
| | | Config.Instance.Home.FloorDics[roomTemp.FloorId] = Language.StringByID(R.MyInternationalizationString.uUnKnownFloor);
|
| | | }
|
| | | }
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | | }
|
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 添加房间_________________________ |
| | | |
| | | public List<string> ListDeviceMac = new List<string>(); |
| | | /// <summary> |
| | | /// 增加房间 |
| | | ///场景列表(场景的ID) |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if room was added, <c>false</c> otherwise.</returns> |
| | | /// <param name="room">Room.</param> |
| | | public bool AddRoom(Room room) |
| | | { |
| | | if (string.IsNullOrEmpty(room.FileName) || Global.IsExistsByHomeId(room.FileName)) |
| | | { |
| | | return false; |
| | | } |
| | | if (Config.Instance.Home.RoomFilePathList.Contains(room.FileName)) |
| | | { |
| | | return false; |
| | | } |
| | | Lists.Add(room); |
| | | var r = Config.Instance.Home.AddRoomListFilePath(room.FileName); |
| | | if (r == false) |
| | | { |
| | | return false; |
| | | } |
| | | Save(); |
| | | HdlAutoBackupLogic.AddOrEditorFile(room.FileName); |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 删除房间_________________________ |
| | | |
| | | /// <summary> |
| | | /// 删除房间 |
| | | /// </summary> |
| | | public bool Remove(string roomFilePath) |
| | | { |
| | | var room = GetRoomByFilePath(roomFilePath); |
| | | if (null == room) |
| | | { |
| | | return false; |
| | | } |
| | | //删除来自拍照或者系统图库的房间背景图片 |
| | | if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2) |
| | | { |
| | | //删除掉原来的自定义图片 |
| | | if (Global.IsExistsByHomeId(room.BackgroundImage) == true)
|
| | | {
|
| | | Global.DeleteFilebyHomeId(room.BackgroundImage);
|
| | | //删除备份
|
| | | HdlAutoBackupLogic.DeleteFile(room.BackgroundImage);
|
| | | } |
| | | } |
| | | //我的喜爱 |
| | | var loveRoom = this.GetLoveRoom(); |
| | | if (loveRoom != null)
|
| | | {
|
| | | //移除我的喜爱里面的设备
|
| | | for (int i = 0; i < room.DeviceUIFilePathList.Count; i++)
|
| | | {
|
| | | loveRoom.DeviceUIFilePathList.Remove(room.DeviceUIFilePathList[i]);
|
| | | loveRoom.DeviceUIList.RemoveAll((obj) => { return room.DeviceUIFilePathList[i] == obj.FileName; });
|
| | | }
|
| | | //移除我的喜爱里面的场景
|
| | | for (int i = 0; i < room.SceneUIFilePathList.Count; i++)
|
| | | {
|
| | | loveRoom.SceneUIFilePathList.Remove(room.SceneUIFilePathList[i]);
|
| | | loveRoom.SceneUIList.RemoveAll((obj) => { return room.SceneUIFilePathList[i] == obj.FileName; });
|
| | | }
|
| | | loveRoom.Save(false);
|
| | | } |
| | | |
| | | if (Global.IsExistsByHomeId(roomFilePath) == false) |
| | | { |
| | | return false; |
| | | } |
| | | Config.Instance.Home.RemoveRoomListFilePath(roomFilePath); |
| | | //删除文件 |
| | | Global.DeleteFilebyHomeId(roomFilePath); |
| | | Lists.Remove(room); |
| | | HdlAutoBackupLogic.DeleteFile(roomFilePath); |
| | | |
| | | CurrentRoom.RefreshRoomListView(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取房间________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取喜爱房间 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Room GetLoveRoom() |
| | | { |
| | | return CurrentRoom.GetRoomById(LoveRoomId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过路径获取房间 |
| | | /// </summary> |
| | | /// <returns>The room by file path.</returns> |
| | | /// <param name="roomFilePath">Room file path.</param> |
| | | public static Room GetRoomByFilePath(string roomFilePath) |
| | | { |
| | | try |
| | | { |
| | | var roomFile = Global.ReadFileByHomeId(roomFilePath); |
| | | var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(System.Text.Encoding.UTF8.GetString(roomFile)); |
| | | |
| | | if (null == nowRoom) |
| | | { |
| | | System.Console.WriteLine("房间文件路径不对,文件路径为:" + roomFilePath); |
| | | return null; |
| | | } |
| | | |
| | | var beforeRoom = Lists.Find((obj) => obj.Id == nowRoom.Id); |
| | | if (beforeRoom != null) |
| | | { |
| | | var tempDeviceUIList = new List<DeviceUI>(); |
| | | tempDeviceUIList.AddRange(beforeRoom.DeviceUIList); |
| | | var tempSceneUIList = new List<SceneUI>(); |
| | | tempSceneUIList.AddRange(beforeRoom.SceneUIList); |
| | | //设备(deviceUI) |
| | | beforeRoom.DeviceUIList.Clear(); |
| | | foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList) |
| | | {
|
| | | beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath)); |
| | | } |
| | | //场景(SceneUI) |
| | | beforeRoom.SceneUIList.Clear(); |
| | | foreach (var sceneFilePath in beforeRoom.SceneUIFilePathList) |
| | | { |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneFilePath)); |
| | | var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); |
| | | if (tempSceneUI != null) |
| | | { |
| | | var scene = tempSceneUIList.Find((obj) => obj.FileName == tempSceneUI.FileName); |
| | | if (scene != null) |
| | | { |
| | | beforeRoom.SceneUIList.Add(scene); |
| | | } |
| | | else |
| | | { |
| | | beforeRoom.AddScene(scene); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return beforeRoom; |
| | | } |
| | | |
| | | //设备(deviceUI) |
| | | nowRoom.DeviceUIList.Clear(); |
| | | foreach (var deviceFilePath in nowRoom.DeviceUIFilePathList) |
| | | { |
| | | var tempCommon = LocalDevice.Current.GetDeviceUI(deviceFilePath); |
| | | if (tempCommon == null || tempCommon.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | nowRoom.DeviceUIList.Add(tempCommon); |
| | | } |
| | | //场景(SceneUI) |
| | | nowRoom.SceneUIList.Clear(); |
| | | foreach (var sceneUIFilePath in nowRoom.SceneUIFilePathList) |
| | | { |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneUIFilePath)); |
| | | var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); |
| | | if (tempScene == null) |
| | | { |
| | | continue; |
| | | } |
| | | nowRoom.SceneUIList.Add(tempScene); |
| | | } |
| | | return nowRoom; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据房间Id,获取房间对象 |
| | | /// </summary> |
| | | /// <returns>The room by name.</returns> |
| | | /// <param name="roomId">房间ID</param> |
| | | public Room GetRoomById(string roomId) |
| | | { |
| | | if (string.IsNullOrEmpty(roomId)) |
| | | { |
| | | return null; |
| | | } |
| | | return Lists.Find((obj) => obj.Id == roomId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据房间名字,获取房间对象 |
| | | /// </summary> |
| | | /// <returns>The room by name.</returns> |
| | | /// <param name="roomName">房间名</param> |
| | | public Room GetRoomByName(string roomName) |
| | | { |
| | | return Lists.Find((obj) => obj.Name == roomName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备获取房间名字(楼层+房间名) |
| | | /// </summary> |
| | | /// <returns>房间名</returns> |
| | | /// <param name="device">设备对象</param> |
| | | public string GetRoomNameByDevice(CommonDevice device) |
| | | { |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | } |
| | | if (Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true)
|
| | | {
|
| | | //(楼层+房间名)
|
| | | return Config.Instance.Home.FloorDics[room.FloorId] + " " + room.Name;
|
| | | } |
| | | return room.Name; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备所在的房间 |
| | | /// </summary> |
| | | /// <returns>The room by device.</returns> |
| | | /// <param name="device">设备对象</param> |
| | | public Room GetRoomByDevice(CommonDevice device) |
| | | { |
| | | string deviceFile = device.FilePath; |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过场景id获取房间名 |
| | | /// </summary> |
| | | /// <returns>The room name by scene identifier.</returns> |
| | | /// <param name="sceneId">Scene identifier.</param> |
| | | public string GetRoomNameBySceneId(int sceneId) |
| | | { |
| | | var room = GetRoomBySceneId(sceneId); |
| | | if (room == null) |
| | | { |
| | | return null; |
| | | } |
| | | return room.Name; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过场景id获取房间对象 |
| | | /// </summary> |
| | | /// <returns>The room by scene identifier.</returns> |
| | | /// <param name="sceneId">Scene identifier.</param> |
| | | public Room GetRoomBySceneId(int sceneId) |
| | | { |
| | | foreach (var r in Lists) |
| | | { |
| | | foreach (var scene in r.SceneUIList) |
| | | { |
| | | if (scene.Id == sceneId) |
| | | { |
| | | return r; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前楼层的房间 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public List<Room> GetRoomsByFloorId(string id) |
| | | { |
| | | if (Config.Instance.Home.FloorDics.Count == 0) |
| | | { |
| | | return Lists; |
| | | } |
| | | return Lists.FindAll((obj) => obj.FloorId == id); |
| | | } |
| | | /// <summary> |
| | | /// 获取当前楼层的房间名称 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public List<string> GetRoomNamesByFloorId(string id) |
| | | { |
| | | List<string> names = new List<string> { }; |
| | | foreach (var r in Lists) |
| | | { |
| | | if (r.FloorId == id) |
| | | { |
| | | names.Add(r.Name); |
| | | } |
| | | } |
| | | return names; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前楼层的房间(拼接了【常用】在第一位) |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public List<Room> GetRoomsByFloorIdAppendLoveRoom(string id) |
| | | { |
| | | if (Config.Instance.Home.FloorDics.Count == 0) |
| | | { |
| | | return Lists; |
| | | } |
| | | var r= Lists.FindAll((obj) => obj.FloorId == id); |
| | | r.Insert(0, GetLoveRoom()); |
| | | return r; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前楼层的房间(拼接了【常用】在第一位) |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom() |
| | | { |
| | | if(Config.Instance.Home.FloorDics.Count==0) |
| | | { |
| | | return Lists; |
| | | } |
| | | var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId); |
| | | r.Insert(0, GetLoveRoom()); |
| | | return r; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 房间方法________________________ |
| | | |
| | | /// <summary> |
| | | /// 设备的房间变更 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="roomId">新房间Id</param> |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true) |
| | | { |
| | | //房间是否修改 |
| | | if (this.IsRoomChanged(device, roomId) == false) |
| | | { |
| | | return; |
| | | } |
| | | //从原来的房间移除设备 |
| | | this.DeleteDevice(device); |
| | | |
| | | //添加到新的房间 |
| | | var room = this.GetRoomById(roomId); |
| | | if (room != null)
|
| | | {
|
| | | room.AddDevice(device, saveRealRoom);
|
| | | } |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 房间名字是否有修改 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="roomId">新房间Id</param> |
| | | /// <returns></returns> |
| | | public bool IsRoomChanged(CommonDevice device, string roomId) |
| | | { |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null || room.Id != roomId)
|
| | | {
|
| | | return true;
|
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取房间所在区域 |
| | | /// 楼层,房间名 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string GetZoneName() |
| | | { |
| | | if (string.IsNullOrEmpty(FloorId)) |
| | | { |
| | | return Name; |
| | | } |
| | | var floorName = Config.Instance.Home.GetFloorNameById(FloorId); |
| | | if (floorName == null) |
| | | { |
| | | return Name; |
| | | } |
| | | return $"{floorName},{Name}"; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 更新房间_________________________ |
| | | |
| | | /// <summary> |
| | | /// Updates the memorry. |
| | | /// </summary> |
| | | /// <param name="roomFilePath">Room file path.</param> |
| | | public static void UpdateMemorry(string roomFilePath) |
| | | { |
| | | GetRoomByFilePath(roomFilePath); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 房间背景图的相关___________________ |
| | | |
| | | /// <summary> |
| | | /// 移动背景图片到住宅目录下 |
| | | /// </summary> |
| | | /// <param name="oldFile">需要移动的文件(直接文件名)</param> |
| | | /// <param name="newFile">要移动到的位置-(包含住宅路径:住宅/文件名)</param> |
| | | public void MoveBackGroundIamageFileToDirectory(string oldFile, string newFile) |
| | | { |
| | | try |
| | | { |
| | | var newPath = System.IO.Path.Combine(Config.Instance.FullPath, newFile); |
| | | var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath,oldFile); |
| | | Global.MoveFileToDirectory(path, newPath); |
| | | //备份 |
| | | Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(oldFile); |
| | | //Save(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine("移动图片异常 " + ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 添加设备________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加设备(此方法目前只给【我的喜爱】使用) |
| | | /// </summary> |
| | | /// <param name="deviceUIFilePath">Device UIF ile path.</param> |
| | | public void AddDevice(string deviceUIFilePath) |
| | | { |
| | | if (string.IsNullOrEmpty(deviceUIFilePath)) |
| | | { |
| | | return; |
| | | } |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath); |
| | | if (null == deviceUI.CommonDevice) |
| | | { |
| | | //当前对象数据无效 |
| | | return; |
| | | } |
| | | if (!DeviceUIFilePathList.Contains(deviceUIFilePath) && !DeviceUIList.Contains(deviceUI)) |
| | | { |
| | | DeviceUIFilePathList.Add(deviceUIFilePath); |
| | | DeviceUIList.Add(deviceUI); |
| | | } |
| | | //保存到本地 |
| | | Save(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加设备(此方法目前只给Room里面使用) |
| | | /// </summary> |
| | | /// <param name="device">要添加的设备对象</param> |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void AddDevice(CommonDevice device, bool saveRealRoom) |
| | | { |
| | | if (device == null) |
| | | { |
| | | return; |
| | | } |
| | | //设备信息保存到本地 |
| | | device.Save(); |
| | | |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | DeviceUIFilePathList.Add(deviceUI.FileName); |
| | | DeviceUIList.Add(deviceUI); |
| | | //保存到本地 |
| | | Save(); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //如果只有一个回路,则修改真实物理设备的房间
|
| | | LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, this.Id, false);
|
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 删除设备_________________________ |
| | | /// <summary> |
| | | /// 删除功能-设备 |
| | | /// </summary> |
| | | /// <param name="deviceUIFilePath">Device UIF ile path.</param> |
| | | public void DeleteDevice(string deviceUIFilePath) |
| | | { |
| | | if (deviceUIFilePath == null) return; |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath)) |
| | | { |
| | | DeviceUIFilePathList.Remove(deviceUIFilePath); |
| | | DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath); |
| | | Save(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除设备 |
| | | /// </summary> |
| | | /// <param name="device">要删除的设备对象</param> |
| | | public void DeleteDevice(CommonDevice device) |
| | | { |
| | | if (device == null) |
| | | { |
| | | return; |
| | | } |
| | | //根据设备,获取所在的房间 |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | string deviceFile = device.FilePath;
|
| | | //移除缓存
|
| | | if (room.DeviceUIFilePathList.Contains(deviceFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | room.DeviceUIFilePathList.Remove(deviceFile);
|
| | |
|
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
|
| | | room.Save();
|
| | | //更改自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(room.FileName); |
| | | |
| | | //递归:删除掉以前的旧数据导致的多个房间的问题 |
| | | this.DeleteDevice(device); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除我的喜爱的设备 |
| | | /// </summary> |
| | | /// <param name="device">要删除的设备对象</param> |
| | | public void DeleteLoveDevice(CommonDevice device) |
| | | { |
| | | if (device == null) |
| | | { |
| | | return; |
| | | } |
| | | //我的喜爱 |
| | | var loveRoom = this.GetLoveRoom();
|
| | | if (loveRoom != null)
|
| | | {
|
| | | string deviceFile = device.FilePath;
|
| | | //移除缓存
|
| | | if (loveRoom.DeviceUIFilePathList.Contains(deviceFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | loveRoom.DeviceUIFilePathList.Remove(deviceFile);
|
| | | loveRoom.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
|
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取设备_________________________ |
| | | |
| | | /// <summary> |
| | | /// 根据设备获取它的UI对象,如果不存在则新建 |
| | | /// </summary> |
| | | /// <returns>The device user interface.</returns> |
| | | /// <param name="device">设备对象</param> |
| | | public DeviceUI GetDeviceUI(CommonDevice device) |
| | | { |
| | | return Common.LocalDevice.Current.GetDeviceUI(device); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 获取当前房间下的全部设备
|
| | | /// </summary>
|
| | | /// <returns></returns> |
| | | public List<CommonDevice> GetRoomListDevice()
|
| | | {
|
| | | var listDevice = new List<CommonDevice>();
|
| | | foreach (var device in this.DeviceUIList)
|
| | | {
|
| | | if (device == null || device.CommonDevice == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | listDevice.Add(device.CommonDevice);
|
| | | }
|
| | | return listDevice;
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取房间设备类型 |
| | | /// </summary> |
| | | /// <param name="room"></param> |
| | | /// <returns></returns> |
| | | public static List<DeviceType> GetdeviceTypes(Room room) |
| | | { |
| | | List<DeviceType> typeList = new List<DeviceType> { }; |
| | | foreach (var deviceUI in room.DeviceUIList) |
| | | { |
| | | if (deviceUI == null || deviceUI.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (!typeList.Contains(deviceUI.CommonDevice.Type)) |
| | | { |
| | | typeList.Add(deviceUI.CommonDevice.Type); |
| | | } |
| | | } |
| | | return typeList; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取该类型的设备 |
| | | /// </summary> |
| | | /// <param name="room"></param> |
| | | /// <param name="deviceType"></param> |
| | | /// <returns></returns> |
| | | public static List<DeviceUI> GetDeviceUIs(Room room ,DeviceType deviceType) |
| | | { |
| | | List<DeviceUI> typeList = new List<DeviceUI> { }; |
| | | foreach (var deviceUI in room.DeviceUIList) |
| | | { |
| | | if (deviceUI == null || deviceUI.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if(deviceUI.CommonDevice.Type!=deviceType) |
| | | { |
| | | continue; |
| | | } |
| | | if (!typeList.Contains(deviceUI)) |
| | | { |
| | | typeList.Add(deviceUI); |
| | | } |
| | | } |
| | | return typeList; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取未分配区域设备 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<DeviceUI> GetUnalloctedDeviceUIs() |
| | | { |
| | | List<DeviceUI> deviceUIs = new List<DeviceUI> { }; |
| | | var dList = AllRoomDeviceUIList; |
| | | var commonDeviceList = Common.LocalDevice.Current.listAllDevice; |
| | | |
| | | if (dList.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | foreach (var device in commonDeviceList) |
| | | { |
| | | if (dList.Find((obj) => obj.CommonDevice == device) == null) |
| | | { |
| | | deviceUIs.Add(Common.LocalDevice.Current.GetDeviceUI(device)); |
| | | } |
| | | } |
| | | if (deviceUIs.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | return deviceUIs; |
| | | } |
| | | |
| | | //public List<DeviceUI> GetUnalloctedDeviceUITypes |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 添加场景_________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加场景 0失败 1成功 -1已经存在 |
| | | /// </summary> |
| | | /// <returns>The scene.</returns> |
| | | /// <param name="sceneName">Scene name.</param> |
| | | /// <param name="sceneIconPath">背景图片,不包含住宅路径 如果iconPathType=1或者2 需要拼接住宅 变成 住宅/sceneIconPath</param> |
| | | /// <param name="commons">Commons.</param> |
| | | /// <param name="iconPathType">I场景背景图片来源类型 图片来源 0--本地图库 1--拍照 2--系统图库 默认0</param> |
| | | public async System.Threading.Tasks.Task<int> AddScene(string sceneName, string sceneIconPath, List<ZigBee.Device.Scene.AddSceneMemberData> commons, int iconPathType) |
| | | { |
| | | //var scenes = GetSceneUIsByFloorId(FloorId); |
| | | //if(scenes!=null && scenes.Count>0) |
| | | //{ |
| | | // if (scenes.Find(s => s.Name == sceneName) != null) |
| | | // { |
| | | // return -1; |
| | | // } |
| | | //} |
| | | |
| | | var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName); |
| | | if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null) |
| | | { |
| | | return 0; |
| | | } |
| | | var getSceneIdData = getSceneIdAllData.getSceneIdData; |
| | | |
| | | bool result = true; |
| | | foreach (var common in commons) |
| | | { |
| | | //添加新成员 |
| | | var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData |
| | | { |
| | | Type = common.Type, |
| | | DeviceAddr = common.DeviceAddr, |
| | | Epoint = common.Epoint, |
| | | ScenesId = getSceneIdData.NewScenesId, |
| | | TaskList = common.TaskList, |
| | | DelayTime = common.DelayTime, |
| | | MemberNumber=common.MemberNumber, |
| | | ElseScenesId = common.ElseScenesId |
| | | }; |
| | | //common.ScenesId = getSceneIdData.NewScenesId; |
| | | //添加新成员 返回结果 |
| | | var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); |
| | | if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null) |
| | | { |
| | | continue; |
| | | } |
| | | var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData; |
| | | if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1) |
| | | { |
| | | result = false; |
| | | } |
| | | } |
| | | //加入成功 |
| | | if (result) |
| | | { |
| | | var sceneUI = new SceneUI |
| | | { |
| | | Name = sceneName, |
| | | Id = getSceneIdData.NewScenesId, |
| | | IconPath = sceneIconPath, |
| | | IconPathType = iconPathType, |
| | | AddSceneMemberDataList= commons |
| | | }; |
| | | sceneUI.Save(); |
| | | SceneUIList.Add(sceneUI); |
| | | SceneUIFilePathList.Add(sceneUI.FileName); |
| | | Save(); |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加场景 |
| | | /// </summary> |
| | | /// <param name="scene">Scene.</param> |
| | | public void AddScene(SceneUI scene) |
| | | { |
| | | //var sceneUI = new SceneUI |
| | | //{ |
| | | // Name = scene.Name, |
| | | // Id = scene.Id, |
| | | // IconPath = scene.IconPath, |
| | | // IconPathType = scene.IconPathType, |
| | | // AddSceneMemberDataList = scene.AddSceneMemberDataList |
| | | //}; |
| | | SceneUIList.Add(scene); |
| | | SceneUIFilePathList.Add(scene.FileName); |
| | | scene.Save(); |
| | | Save(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除场景 |
| | | /// </summary> |
| | | /// <param name="scene"></param> |
| | | public void DeleteScene(SceneUI scene) |
| | | { |
| | | //scene.IsCollected = false; |
| | | scene.Save(); |
| | | SceneUIList.Remove(scene); |
| | | SceneUIFilePathList.Remove(scene.FileName); |
| | | Save(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 设备是否收藏______________________ |
| | | |
| | | /// <summary> |
| | | /// 是否是收藏设备 |
| | | /// </summary> |
| | | /// <param name="filePath"></param> |
| | | /// <returns></returns> |
| | | public bool IsCollectInRoom(string filePath) |
| | | { |
| | | if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | #endregion |
| | | |
| | | #region ◆ 修改场景________________________ |
| | | |
| | | /// <summary> |
| | | /// 修改场景设备 0失败 1成功 |
| | | /// </summary> |
| | | /// <returns>The scene.</returns> |
| | | /// <param name="sceneUI">Scene user interface.</param> |
| | | /// <param name="sceneRemoveMemberData">Scene remove member data.</param> |
| | | /// <param name="addCommons">Add commons.</param> |
| | | public async System.Threading.Tasks.Task<int> ModifyScene(SceneUI sceneUI, Scene.SceneRemoveMemberData sceneRemoveMemberData, List<Scene.AddSceneMemberData> addCommons) |
| | | { |
| | | //if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null) |
| | | //{ |
| | | // return 0; |
| | | //} |
| | | |
| | | bool result = true; |
| | | //移除成员 返回结果 |
| | | var removeSceneMemberResponseAllData = await ZigBee.Device.Scene.RemoveSceneMemberAsync(sceneRemoveMemberData); |
| | | if (removeSceneMemberResponseAllData == null || removeSceneMemberResponseAllData.removeSceneMemberResponseData == null) |
| | | { |
| | | return 0; |
| | | } |
| | | var removeSceneMemberResponseData = removeSceneMemberResponseAllData.removeSceneMemberResponseData; |
| | | if (removeSceneMemberResponseData == null) |
| | | { |
| | | return 0; |
| | | } |
| | | if (removeSceneMemberResponseData.Result != 0) |
| | | { |
| | | result = false; |
| | | } |
| | | //添加 |
| | | foreach (var addCommon in addCommons) |
| | | { |
| | | //添加新成员 |
| | | var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData |
| | | { |
| | | DeviceAddr = addCommon.DeviceAddr, |
| | | Type = addCommon.Type, |
| | | Epoint = addCommon.Epoint, |
| | | ScenesId = sceneUI.Id, |
| | | TaskList = addCommon.TaskList, |
| | | DelayTime = addCommon.DelayTime, |
| | | ElseScenesId = addCommon.ElseScenesId, |
| | | MemberNumber=addCommon.MemberNumber |
| | | }; |
| | | //添加新成员 返回结果 |
| | | var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); |
| | | if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null) |
| | | { |
| | | result = false; |
| | | System.Console.WriteLine("添加场景失败"); |
| | | continue; |
| | | } |
| | | var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData; |
| | | if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1) |
| | | { |
| | | result = false; |
| | | } |
| | | } |
| | | //加入成功 |
| | | if (result) |
| | | { |
| | | sceneUI.AddSceneMemberDataList = addCommons; |
| | | sceneUI.Save(); |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 删除场景________________________ |
| | | |
| | | /// <summary> |
| | | /// 移除场景--该仅进行了对本地场景数据的删除 |
| | | /// </summary> |
| | | /// <param name="sceneUI">Scene user interface.</param> |
| | | public void RemoveScene(SceneUI sceneUI) |
| | | { |
| | | if(Global.IsExistsByHomeId(sceneUI.FileName)==false) |
| | | { |
| | | return; |
| | | } |
| | | SceneUIList.Remove(sceneUI); |
| | | SceneUIFilePathList.Remove(sceneUI.FileName); |
| | | Save(); |
| | | if (IsLove == false) |
| | | { |
| | | if (CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id) != null) |
| | | { |
| | | CurrentRoom.GetLoveRoom().DeleteScene(sceneUI); |
| | | } |
| | | } |
| | | Global.DeleteFilebyHomeId(sceneUI.FileName); |
| | | HdlAutoBackupLogic.DeleteFile(sceneUI.FileName); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取场景________________________ |
| | | |
| | | /// <summary> |
| | | /// 通过场景id获取场景 |
| | | /// </summary> |
| | | /// <returns>The scene UIB y scene identifier.</returns> |
| | | /// <param name="sceneId">Scene identifier.</param> |
| | | public SceneUI GetSceneUIBySceneId(int sceneId) |
| | | { |
| | | foreach (var r in Lists) |
| | | { |
| | | foreach (var sceneUI in r.SceneUIList) |
| | | { |
| | | if (sceneUI.Id == sceneId) |
| | | { |
| | | return sceneUI; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取该楼层所有场景 |
| | | /// </summary> |
| | | /// <param name="floorId"></param> |
| | | /// <returns></returns> |
| | | public List<SceneUI> GetSameFloorScenes(string floorId) |
| | | { |
| | | List<SceneUI> sceneUIs = new List<SceneUI> { }; |
| | | var rooms= CurrentRoom.GetRoomsByFloorId(floorId); |
| | | foreach(var r in rooms) |
| | | { |
| | | sceneUIs.AddRange(r.SceneUIList); |
| | | } |
| | | return sceneUIs; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取该楼层的场景 |
| | | /// </summary> |
| | | /// <param name="floorId"></param> |
| | | /// <returns></returns> |
| | | public List<SceneUI> GetSceneUIsByFloorId(string floorId) |
| | | { |
| | | var rooms = GetRoomsByFloorId(floorId); |
| | | if (rooms == null) |
| | | { |
| | | return null; |
| | | } |
| | | var sceneList = new List<SceneUI> { }; |
| | | foreach (var r in rooms) |
| | | { |
| | | if (r.SceneUIList.Count == 0) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var sceneUI in r.SceneUIList) |
| | | { |
| | | if (sceneUI == null) |
| | | { |
| | | continue; |
| | | } |
| | | sceneList.Add(sceneUI); |
| | | } |
| | | } |
| | | return sceneList; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取未分配区域场景 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<SceneUI> GetUnalloctedScenes() |
| | | { |
| | | List<SceneUI> sceneUIs = new List<SceneUI> { }; |
| | | var sList = AllRoomSceneUIFilepathList; |
| | | |
| | | List<string> sfile = new List<string> { }; |
| | | foreach (var path in Global.FileListByHomeId()) |
| | | { |
| | | if (path.StartsWith("Scene_", StringComparison.Ordinal)) |
| | | { |
| | | sfile.Add(path); |
| | | } |
| | | } |
| | | foreach (var path in sfile) |
| | | { |
| | | if (sList.Find((obj) => obj == path) == null) |
| | | { |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(path)); |
| | | var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo); |
| | | if (tempSceneUI != null) |
| | | { |
| | | sceneUIs.Add(tempSceneUI); |
| | | } |
| | | } |
| | | } |
| | | if (sceneUIs.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | return sceneUIs; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 刷新场景_________________________ |
| | | |
| | | /// <summary> |
| | | /// 刷新房间的场景列表 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<bool> RefreshSceneUIList() |
| | | { |
| | | return false; |
| | | //System.Console.WriteLine($"开始请求网关场景****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); |
| | | //bool result = true; |
| | | //var sceneList = await ZigBee.Device.Scene.GetSceneListAsync(); |
| | | //System.Console.WriteLine($"结束请求网关场景****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); |
| | | //if (sceneList == null) |
| | | //{ |
| | | // return false; |
| | | //} |
| | | //List<int> sceneIDList = new List<int> { }; |
| | | //System.Console.WriteLine($"开始本地场景****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); |
| | | //foreach (var scene in sceneList) |
| | | //{ |
| | | // if (scene == null) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // sceneIDList.Add(scene.ScenesId); |
| | | //} |
| | | //foreach(var r in Lists) |
| | | //{ |
| | | // if(r.SceneUIList==null || r.SceneUIList.Count==0) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // foreach(var rScene in r.SceneUIList) |
| | | // { |
| | | // if(rScene==null) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // //var scene = sceneList.Find((obj) => rScene.ScenesId == obj.ScenesId); |
| | | // if(sceneIDList.Contains(rScene.ScenesId)==false) |
| | | // { |
| | | // var removeResult = r.SceneUIList.Remove(rScene); |
| | | // r.Save(); |
| | | // if (removeResult == false) |
| | | // { |
| | | // result = false; |
| | | // } |
| | | // } |
| | | // } |
| | | //} |
| | | //System.Console.WriteLine($"结束本地场景****{DateTime.Now.ToString("yyMMdd hhmmss fff")}*****"); |
| | | //return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 保存____________________________ |
| | | |
| | | /// <summary> |
| | | /// 保存 |
| | | /// </summary> |
| | | /// <param name="autoBackup">是否自动备份,默认true</param> |
| | | public void Save(bool autoBackup = true) |
| | | { |
| | | //保存房间信息 |
| | | Global.WriteFileByBytesByHomeId(FileName, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | if (autoBackup == true) |
| | | { |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | } |
| | | }
|
| | |
|
| | | #endregion |
| | |
|
| | | #region ◆ 楼层和房间顺序相关_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据楼层的主键获取排序后的房间列表
|
| | | /// </summary>
|
| | | /// <param name="i_floorKeys">楼层的主键</param>
|
| | | /// <param name="getShard">分享的房间是否也获取</param>
|
| | | /// <returns></returns>
|
| | | public List<Room> GetFloorSortRoom(string i_floorKeys, bool getShard = true)
|
| | | {
|
| | | 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>();
|
| | | foreach (var room in Common.Room.Lists)
|
| | | {
|
| | | if (room.FloorId != i_floorKeys || 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;
|
| | | }
|
| | |
|
| | | 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;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存房间的顺序
|
| | | /// </summary>
|
| | | /// <param name="i_floorKeys">楼层主键</param>
|
| | | /// <param name="listSort">房间顺序(房间的主键)</param>
|
| | | public void SaveRoomSort(string i_floorKeys, List<string> listSort)
|
| | | {
|
| | | 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);
|
| | | }
|
| | |
|
| | | //保存顺序
|
| | | dicAllSort[i_floorKeys] = listSort;
|
| | | UserCenterLogic.SaveFileContent(fullName, dicAllSort);
|
| | | dicAllSort.Clear();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取排序后的楼层
|
| | | /// </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)
|
| | | {
|
| | | listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData);
|
| | | }
|
| | | foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys)
|
| | | {
|
| | | if (listFloorSort.Contains(keys) == false)
|
| | | {
|
| | | //新添加的楼层
|
| | | listFloorSort.Add(keys);
|
| | | }
|
| | | }
|
| | |
|
| | | var dic = new Dictionary<string, string>();
|
| | | for (int i = 0; i < listFloorSort.Count; i++)
|
| | | {
|
| | | if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true)
|
| | | {
|
| | | dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]];
|
| | | }
|
| | | }
|
| | |
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, listFloorSort);
|
| | | return dic;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存楼层的顺序
|
| | | /// </summary>
|
| | | /// <param name="listSort">楼层的主键</param>
|
| | | public void SaveFloorSort(List<string> listSort)
|
| | | {
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile);
|
| | | //保存顺序
|
| | | UserCenterLogic.SaveFileContent(fullName, listSort);
|
| | | }
|
| | | public List<int> ListSceneId = new List<int>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ◆ 克隆房间对象_____________________
|
| | | #region ■ 保存_______________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 克隆房间对象
|
| | | /// 保存
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public Room CloneRoomClass()
|
| | | /// <param name="autoBackup">是否自动备份,默认true</param>
|
| | | public void Save(bool autoBackup = true)
|
| | | {
|
| | | var newRoom = new Room();
|
| | | //克隆属性
|
| | | newRoom.Id = this.Id;
|
| | | newRoom.FloorId = this.FloorId;
|
| | | newRoom.TemperatrueDevice = this.TemperatrueDevice;
|
| | | newRoom.HumidityDevice = this.HumidityDevice;
|
| | | newRoom.Name = this.Name;
|
| | | newRoom.BackgroundImage = this.BackgroundImage;
|
| | | newRoom.BackgroundImageType = this.BackgroundImageType;
|
| | |
|
| | | return newRoom;
|
| | | //保存房间信息
|
| | | Global.WriteFileByBytesByHomeId(FileName, Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
|
| | | if (autoBackup == true)
|
| | | {
|
| | | HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(FileName);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion |
| | | |
| | | } |
| | | } |