old mode 100755
new mode 100644
| | |
| | | /// 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> |
| | | public Dictionary<string, string> FloorList = new Dictionary<string, string> { }; |
| | | |
| | | /// <summary>
|
| | | /// 温度传感器(设备主键)
|
| | | /// </summary> |
| | | public string TemperatrueDevice = string.Empty; |
| | | /// <summary>
|
| | | /// 湿度传感器(设备主键)
|
| | | /// </summary> |
| | | public string HumidityDevice = string.Empty; |
| | | /// <summary> |
| | | /// 温度 |
| | | /// </summary> |
| | | public double Temperatrue; |
| | | /// <summary> |
| | | /// 湿度 |
| | | /// </summary> |
| | | public double Humidity; |
| | | |
| | | /// <summary>
|
| | | /// 当前选择的房间
|
| | | /// </summary> |
| | | private static Room m_CurrentRoom = null; |
| | | /// <summary> |
| | | /// 当前选择的房间 |
| | | /// </summary> |
| | | public static Room CurrentRoom; |
| | | [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> |
| | | /// 房间里所有的设备列表 |
| | |
| | | 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> |
| | |
| | | { |
| | | get |
| | | { |
| | | return Id == "Favorite"; |
| | | return Id == LoveRoomId; |
| | | } |
| | | } |
| | | |
| | |
| | | /// 注:分享过来的房间不能删除,不能编辑该房间,不能对设备(功能)、场景进行增删改 |
| | | /// </summary> |
| | | public bool IsSharedRoom = false; |
| | | |
| | | /// <summary> |
| | | /// 是否可以刷新房间数据了 |
| | | /// 需要等初始化本地设备数据后在可以初始化房间数据 |
| | | /// </summary> |
| | | public static bool canInitAllRoom; |
| | | |
| | | /// <summary> |
| | | /// 获取喜爱房间的所有设备路径 |
| | |
| | | { |
| | | return new List<string> { }; |
| | | } |
| | | var loveRoom = Lists[0]; |
| | | return loveRoom.DeviceUIFilePathList; |
| | | return CurrentRoom.GetLoveRoom().DeviceUIFilePathList; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 所有房间的所有设备类型 |
| | | /// 先调用 GetAllRoomDeviceTypeList() |
| | | /// </summary> |
| | | /// <value>All room device type list.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<DeviceType> AllRoomDeviceTypeList = new List<DeviceType> { }; |
| | | 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> |
| | | /// 获取所有房间的所有场景 |
| | |
| | | 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> |
| | |
| | | |
| | | /// <summary> |
| | | /// 获取所有房间的所有设备 |
| | | /// 请先调用 GetAllRoomDeviceUIList()方法 |
| | | /// </summary> |
| | | /// <value>All room device UIL ist.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<DeviceUI> AllRoomDeviceUIList = new List<DeviceUI> { }; |
| | | 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 |
| | | |
| | |
| | | /// </summary> |
| | | public static void InitAllRoom() |
| | | { |
| | | if (canInitAllRoom == false) |
| | | { |
| | | return; |
| | | } |
| | | Lists.Clear(); |
| | | if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false) |
| | | { |
| | | //默认添加喜爱的房间--禁止修改房间名 |
| | | var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = "Favorite" }; |
| | | love.Save(true); |
| | | 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(); |
| | | currentHome.Save(false); |
| | | } |
| | | foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList) |
| | | { |
| | |
| | | { |
| | | if (room.IsSharedRoom) |
| | | { |
| | | room.Name = $"({Language.StringByID(R.MyInternationalizationString.Shared)}){room.Name}"; |
| | | room.Name = $"{room.Name}"; |
| | | } |
| | | Lists.Add(room); |
| | | |
| | | } |
| | | } |
| | | Config.Instance.Home.InitFloor(); |
| | | |
| | | RefreshRoomListView(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新房间视图列表 |
| | | /// </summary> |
| | | public static void RefreshRoomListView() |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | Phone.Device.Room.RoomManagement.Instance.Show(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | }
|
| | | }
|
| | | homeTemp.Save(false);
|
| | | canInitAllRoom = true;
|
| | | InitAllRoom();
|
| | | } |
| | | |
| | |
| | | #endregion |
| | | |
| | | #region ◆ 获取房间________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取喜爱房间 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Room GetLoveRoom() |
| | | { |
| | | return CurrentRoom.GetRoomById(LoveRoomId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过路径获取房间 |
| | |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备获取房间名字 |
| | | /// </summary> |
| | | /// <returns>房间名</returns> |
| | | /// <param name="device">设备对象</param> |
| | | public List<string> GetRoomListNameByDevice(CommonDevice device) |
| | | { |
| | | var listName = new List<string>(); |
| | | var listroom = this.GetRoomByDevice(device); |
| | | foreach (var room in listroom) |
| | | { |
| | | listName.Add(room.Name); |
| | | } |
| | | |
| | | return listName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备获取房间名字(多个房间的时候,用“,”分割) |
| | | /// 根据设备获取房间名字(楼层+房间名) |
| | | /// </summary> |
| | | /// <returns>房间名</returns> |
| | | /// <param name="device">设备对象</param> |
| | | public string GetRoomNameByDevice(CommonDevice device) |
| | | { |
| | | var listName = this.GetRoomListNameByDevice(device); |
| | | |
| | | return this.GetRoomName(listName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取多个房间的连接起来的名字 |
| | | /// </summary> |
| | | /// <param name="listName"></param> |
| | | /// <returns></returns> |
| | | public string GetRoomName(List<string> listName) |
| | | { |
| | | if (listName.Count == 0) |
| | | { |
| | | //未分配区域 |
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | } |
| | | return string.Join(",", listName); |
| | | 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 List<Room> GetRoomByDevice(CommonDevice device) |
| | | public Room GetRoomByDevice(CommonDevice device) |
| | | { |
| | | var deviceUI = new DeviceUI { };
|
| | | deviceUI.DeviceAddr = device.DeviceAddr;
|
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | return Lists.FindAll((obj) => obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); |
| | | string deviceFile = device.FilePath; |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile)); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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 |
| | | |
| | |
| | | /// 设备的房间变更 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="listnewName">新房间名字列表</param> |
| | | public void ChangedRoom(CommonDevice device, List<string> listnewName) |
| | | /// <param name="roomId">新房间Id</param> |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true) |
| | | { |
| | | //房间是否修改 |
| | | if (this.IsRoomChanged(device, listnewName) == false) |
| | | if (this.IsRoomChanged(device, roomId) == false) |
| | | { |
| | | return; |
| | | } |
| | | var list = new List<string>(); |
| | | list.AddRange(listnewName); |
| | | |
| | | //从原来的房间移除设备,但是不删除UI文件 |
| | | this.DeleteDevice(device, ref list, false); |
| | | //从原来的房间移除设备 |
| | | this.DeleteDevice(device); |
| | | |
| | | //添加到新的房间 |
| | | foreach (string newRoom in list) |
| | | { |
| | | var room = this.GetRoomByName(newRoom); |
| | | if (room != null) |
| | | { |
| | | //不覆盖UI文件 |
| | | room.AddDevice(device, false); |
| | | } |
| | | var room = this.GetRoomById(roomId); |
| | | if (room != null)
|
| | | {
|
| | | room.AddDevice(device, saveRealRoom);
|
| | | } |
| | | } |
| | | |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 房间名字是否有修改 |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="listnewName">新房间名字列表</param> |
| | | /// <param name="roomId">新房间Id</param> |
| | | /// <returns></returns> |
| | | public bool IsRoomChanged(CommonDevice device, List<string> listnewName) |
| | | public bool IsRoomChanged(CommonDevice device, string roomId) |
| | | { |
| | | var listOld = this.GetRoomListNameByDevice(device); |
| | | if (listOld.Count != listnewName.Count) |
| | | { |
| | | return true; |
| | | } |
| | | //个数一样时,比较内容 |
| | | foreach (string newstring in listnewName) |
| | | { |
| | | if (listOld.Contains(newstring) == false) |
| | | { |
| | | return true; |
| | | } |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null || room.Id != roomId)
|
| | | {
|
| | | return true;
|
| | | } |
| | | return false; |
| | | } |
| | |
| | | #region ◆ 添加设备________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加设备 |
| | | /// 添加设备(此方法目前只给【我的喜爱】使用) |
| | | /// </summary> |
| | | /// <param name="deviceUIFilePath">Device UIF ile path.</param> |
| | | public void AddDevice(string deviceUIFilePath) |
| | |
| | | { |
| | | return; |
| | | } |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUIFilePath)); |
| | | var deviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); |
| | | if (null == deviceUI || null == deviceUI.CommonDevice) |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath); |
| | | if (null == deviceUI.CommonDevice) |
| | | { |
| | | //当前对象数据无效 |
| | | return; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加设备 |
| | | /// 添加设备(此方法目前只给Room里面使用) |
| | | /// </summary> |
| | | /// <param name="device">要添加的设备对象</param> |
| | | /// <param name="backUpUI">是否要覆盖UI文件</param> |
| | | public void AddDevice(CommonDevice device, bool backUpUI = true) |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void AddDevice(CommonDevice device, bool saveRealRoom) |
| | | { |
| | | if (device == null) |
| | | { |
| | |
| | | //设备信息保存到本地 |
| | | device.Save(); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | |
| | | DeviceUI deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | DeviceUIFilePathList.Add(deviceUI.FileName); |
| | |
| | | |
| | | //添加自动备份 |
| | | 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> |
| | |
| | | public void DeleteDevice(string deviceUIFilePath) |
| | | { |
| | | if (deviceUIFilePath == null) return; |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath) && Global.IsExistsByHomeId(deviceUIFilePath)) |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath)) |
| | | { |
| | | DeviceUIFilePathList.Remove(deviceUIFilePath); |
| | | DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath); |
| | | HdlAutoBackupLogic.DeleteFile(deviceUIFilePath); |
| | | Save(); |
| | | } |
| | | } |
| | |
| | | /// 删除设备 |
| | | /// </summary> |
| | | /// <param name="device">要删除的设备对象</param> |
| | | /// <param name="DeleteUi">是否删除UI文件</param> |
| | | public void DeleteDevice(CommonDevice device, bool DeleteUi = true) |
| | | { |
| | | List<string> listNotDelRoom = new List<string>(); |
| | | //删除设备 |
| | | this.DeleteDevice(device, ref listNotDelRoom, DeleteUi); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除设备(特殊函数,现阶段是给设备变更房间使用的) |
| | | /// </summary> |
| | | /// <param name="device">要删除的设备对象</param> |
| | | /// <param name="listNotDelRoom">不执行删除的房间,当指定的不能删除的房间存在时,会从这个列表中移除,最终只剩下新的房间</param> |
| | | /// <param name="DeleteUi">是否删除UI文件</param> |
| | | public void DeleteDevice(CommonDevice device, ref List<string> listNotDelRoom, bool DeleteUi) |
| | | public void DeleteDevice(CommonDevice device) |
| | | { |
| | | if (device == null) |
| | | { |
| | | return; |
| | | } |
| | | DeviceUI deviceUI = new DeviceUI(); |
| | | deviceUI.DeviceAddr = device.DeviceAddr;
|
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | //根据设备,获取所在的房间,因为它删的不一定是当前房间 |
| | | List<Room> listroom = this.GetRoomByDevice(device); |
| | | |
| | | //删除UI文件 |
| | | if (DeleteUi == true && Global.IsExistsByHomeId(deviceUI.FileName) == true) |
| | | { |
| | | Global.DeleteFilebyHomeId(deviceUI.FileName); |
| | | //删除自动备份 |
| | | Phone.UserCenter.HdlAutoBackupLogic.DeleteFile(deviceUI.FileName); |
| | | } |
| | | |
| | | foreach (Room room in listroom) |
| | | { |
| | | if (listNotDelRoom.Contains(room.Name) == true) |
| | | { |
| | | listNotDelRoom.Remove(room.Name); |
| | | continue; |
| | | } |
| | | //移除缓存 |
| | | if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | return; |
| | | } |
| | | room.DeviceUIFilePathList.Remove(deviceUI.FileName); |
| | | |
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName); |
| | | room.Save(); |
| | | //更改自动备份 |
| | | Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(room.FileName); |
| | | } |
| | | //根据设备,获取所在的房间 |
| | | 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); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 获取设备_________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取所有房间的所有设备 |
| | | /// </summary> |
| | | public static void GetAllRoomDeviceUIList() |
| | | { |
| | | List<string> devicePathList = new List<string>(); |
| | | //所有房间的所有设备 |
| | | AllRoomDeviceUIList.Clear(); |
| | | foreach (var room in Shared.Common.Room.Lists) |
| | | { |
| | | if(room.IsSharedRoom) |
| | | { |
| | | continue; |
| | | } |
| | | if (room.DeviceUIList.Count == 0) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var device in room.DeviceUIList) |
| | | { |
| | | if (device == null || device.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (!devicePathList.Contains(device.FileName)) |
| | | { |
| | | AllRoomDeviceUIList.Add(device); |
| | | devicePathList.Add(device.FileName); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备获取它的UI对象,如果不存在则新建 |
| | |
| | | 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> |
| | | public static void GetAllRoomDeviceTypeList() |
| | | /// <param name="room"></param> |
| | | /// <returns></returns> |
| | | public static List<DeviceType> GetdeviceTypes(Room room) |
| | | { |
| | | AllRoomDeviceTypeList.Clear(); |
| | | foreach (var deviceUI in AllRoomDeviceUIList) |
| | | List<DeviceType> typeList = new List<DeviceType> { }; |
| | | foreach (var deviceUI in room.DeviceUIList) |
| | | { |
| | | if (deviceUI == null || deviceUI.CommonDevice == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (!AllRoomDeviceTypeList.Contains(deviceUI.CommonDevice.Type)) |
| | | if (!typeList.Contains(deviceUI.CommonDevice.Type)) |
| | | { |
| | | AllRoomDeviceTypeList.Add(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 |
| | | |
| | |
| | | /// <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 = 0) |
| | | { |
| | | if (AllRoomSceneUIList.Find(s => s.Name == sceneName) != null) |
| | | var scenes = GetSceneUIsByFloorId(FloorId); |
| | | if(scenes!=null && scenes.Count>0) |
| | | { |
| | | return -1; |
| | | 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; |
| | | //循环相同报错 |
| | | foreach (var tempSceneUI in AllRoomSceneUIList) |
| | | { |
| | | if (tempSceneUI.Id == getSceneIdAllData.getSceneIdData.NewScenesId) |
| | | { |
| | | //场景已存在 |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | bool result = true; |
| | | foreach (var common in commons) |
| | |
| | | //添加新成员 |
| | | var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData |
| | | { |
| | | DeviceAddr = common.DeviceAddr, |
| | | 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; |
| | |
| | | /// <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(sceneUI); |
| | | SceneUIFilePathList.Add(sceneUI.FileName); |
| | | sceneUI.Save(); |
| | | //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="room"></param> |
| | | /// <param name="filePath"></param> |
| | | /// <returns></returns> |
| | | public bool IsCollectInRoom(Room room,string filePath) |
| | | { |
| | | if(room.IsLove) |
| | | { |
| | | return true; |
| | | } |
| | | if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | #endregion |
| | | |
| | | #region ◆ 修改场景________________________ |
| | |
| | | ScenesId = sceneUI.Id, |
| | | TaskList = addCommon.TaskList, |
| | | DelayTime = addCommon.DelayTime, |
| | | ElseScenesId = addCommon.ElseScenesId |
| | | ElseScenesId = addCommon.ElseScenesId, |
| | | MemberNumber=addCommon.MemberNumber |
| | | }; |
| | | //添加新成员 返回结果 |
| | | var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData); |
| | |
| | | Save(); |
| | | Global.DeleteFilebyHomeId(sceneUI.FileName); |
| | | HdlAutoBackupLogic.DeleteFile(sceneUI.FileName); |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | } |
| | | } |
| | | 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 |
| | |
| | |
|
| | | #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);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ◆ 克隆房间对象_____________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | 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;
|
| | |
| | | }
|
| | |
|
| | | #endregion |
| | | |
| | | } |
| | | } |