gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Common/Room.cs
@@ -75,11 +75,36 @@
        /// 湿度传感器(设备主键)
        /// </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>
        public static Room CurrentRoom;
        [Newtonsoft.Json.JsonIgnore]
        public static Room CurrentRoom
        {
            get
            {
                if (m_CurrentRoom == null && Lists.Count > 0)
                {
                    if (m_CurrentRoom == null) { m_CurrentRoom = Lists[0]; }
                    return Lists[0];
                }
                return m_CurrentRoom;
            }
            set { m_CurrentRoom = value; }
        }
        /// <summary>
        /// 房间里所有的设备列表
@@ -114,12 +139,6 @@
        /// 注:分享过来的房间不能删除,不能编辑该房间,不能对设备(功能)、场景进行增删改
        /// </summary>
        public bool IsSharedRoom = false;
        /// <summary>
        /// 是否可以刷新房间数据了
        /// 需要等初始化本地设备数据后在可以初始化房间数据
        /// </summary>
        public static bool CanInitAllRoom;
        /// <summary>
        /// 获取喜爱房间的所有设备路径
@@ -175,6 +194,10 @@
                var sceneList = new List<SceneUI> { };
                foreach (var r in Shared.Common.Room.Lists)
                {
                    if(r.IsLove)
                    {
                        continue;
                    }
                    if (r.SceneUIList.Count == 0)
                    {
                        continue;
@@ -191,6 +214,37 @@
                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.IsLove)
                    {
                        continue;
                    }
                    if (r.SceneUIFilePathList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var path in r.SceneUIFilePathList)
                    {
                        pathList.Add(path);
                    }
                }
                return pathList;
            }
        }
        /// <summary>
        /// 场景列表---不再序列化
        /// </summary>
@@ -216,9 +270,10 @@
            get
            {
                List<DeviceUI> deviceList = new List<DeviceUI>();
                foreach (var room in Lists)
                {
                    if (room.IsSharedRoom)
                for (int i = 0; i < Lists.Count; i++)
                {
                    var room = Lists[i];
                    if (room.IsSharedRoom || room.IsLove)
                    {
                        continue;
                    }
@@ -226,8 +281,9 @@
                    {
                        continue;
                    }
                    foreach (var device in room.DeviceUIList)
                    for (int j = 0; j < room.DeviceUIList.Count; j++)
                    {
                        var device = room.DeviceUIList[j];
                        if (device == null || device.CommonDevice == null)
                        {
                            continue;
@@ -264,20 +320,16 @@
        /// </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 = LoveRoomId };
                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)
            {
@@ -287,11 +339,27 @@
                {
                    if (room.IsSharedRoom)
                    {
                        room.Name = $"({Language.StringByID(R.MyInternationalizationString.Shared)}){room.Name}";
                        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();
            });
        }
        /// <summary>
@@ -299,7 +367,6 @@
        /// </summary>
        public static void RefreshAllRoomByLocation()
        {
            Lists.Clear();
            var homeTemp = Config.Instance.Home;
            homeTemp.RoomFilePathList.Clear();
@@ -310,19 +377,48 @@
            if (listFile.Contains(fRoom) == true)
            {
                listFile.Remove(fRoom);
                homeTemp.AddRoomListFilePath(fRoom);
                homeTemp.RoomFilePathList.Add(fRoom);
            }
            var listRoomFile = new List<string>();
            foreach (string fileName in listFile)
            {
                if (fileName.StartsWith("Room_"))
                {
                    homeTemp.AddRoomListFilePath(fileName);
                    homeTemp.RoomFilePathList.Add(fileName);
                    listRoomFile.Add(fileName);
                }
            }
            //检测楼层数据的合法性
            CheckFloorData(listRoomFile);
            homeTemp.Save(false);
            CanInitAllRoom = true;
            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
@@ -352,6 +448,7 @@
            }
            Save();
            HdlAutoBackupLogic.AddOrEditorFile(room.FileName);
            CurrentRoom.RefreshRoomListView();
            return true;
        }
@@ -372,8 +469,33 @@
            //删除来自拍照或者系统图库的房间背景图片
            if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2)
            {
                DeleteBackGroundIamageFilebyHomeId(room.BackgroundImage);
                //删除掉原来的自定义图片
                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;
@@ -383,6 +505,9 @@
            Global.DeleteFilebyHomeId(roomFilePath);
            Lists.Remove(room);
            HdlAutoBackupLogic.DeleteFile(roomFilePath);
            CurrentRoom.RefreshRoomListView();
            return true;
        }
@@ -394,7 +519,7 @@
        /// 获取喜爱房间
        /// </summary>
        /// <returns></returns>
        public  Room GetLoveRoom()
        public Room GetLoveRoom()
        {
            return CurrentRoom.GetRoomById(LoveRoomId);
        }
@@ -504,6 +629,10 @@
        /// <param name="roomId">房间ID</param>
        public Room GetRoomById(string roomId)
        {
            if (string.IsNullOrEmpty(roomId))
            {
                return null;
            }
            return Lists.Find((obj) => obj.Id == roomId);
        }
@@ -545,11 +674,8 @@
        /// <param name="device">设备对象</param>
        public Room GetRoomByDevice(CommonDevice device)
        {
            var deviceUI = new DeviceUI { };
            deviceUI.DeviceAddr = device.DeviceAddr;
            deviceUI.DeviceEpoint = device.DeviceEpoint;
            return Lists.Find((obj) => obj.DeviceUIFilePathList.Contains(deviceUI.FileName));
            string deviceFile = device.FilePath;
            return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile));
        }
        /// <summary>
@@ -576,6 +702,10 @@
        {
            foreach (var r in Lists)
            {
                if(r.IsLove)
                {
                    continue;
                }
                foreach (var scene in r.SceneUIList)
                {
                    if (scene.Id == sceneId)
@@ -592,21 +722,38 @@
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorId(string id)
        public List<Room> GetRoomsByFloorId(string id)
        {
            return Lists.FindAll((obj) => obj.FloorId==id);
            try
            {
                if (Lists == null || Lists.Count == 0 || Lists.Count == 1)
                {
                    return null;
                }
                if (Config.Instance.Home.FloorDics.Count == 0)
                {
                    return Lists;
                }
                return Lists.FindAll((obj) => obj.FloorId == id);
            }
            catch(Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                return null;
            }
        }
        /// <summary>
        /// 获取当前楼层的房间名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<string> GetRoomNamesByFloorId(string id)
        public List<string> GetRoomNamesByFloorId(string id)
        {
            List<string> names = new List<string> { };
            foreach(var r in Lists)
            foreach (var r in Lists)
            {
                if(r.FloorId==id)
                if (r.FloorId == id)
                {
                    names.Add(r.Name);
                }
@@ -621,6 +768,10 @@
        /// <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;
@@ -632,6 +783,10 @@
        /// <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;
@@ -646,7 +801,8 @@
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="roomId">新房间Id</param>
        public void ChangedRoom(CommonDevice device, string roomId)
        /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param>
        public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true)
        {
            //房间是否修改
            if (this.IsRoomChanged(device, roomId) == false)
@@ -660,7 +816,7 @@
            var room = this.GetRoomById(roomId);
            if (room != null)
            {
                room.AddDevice(device);
                room.AddDevice(device, saveRealRoom);
            }
        }
@@ -680,6 +836,25 @@
            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 ◆ 更新房间_________________________
@@ -696,31 +871,6 @@
        #endregion
        #region ◆ 房间背景图的相关___________________
        /// <summary>
        /// 删除背景图片
        /// </summary>
        /// <param name="fileName">fileName实际上包含了住宅路劲 如 住宅/文件名.</param>
        public static void DeleteBackGroundIamageFilebyHomeId(string fileName)
        {
            if (fileName == null)
            {
                return;
            }
            var pathLists = fileName.Split('/');
            if (pathLists == null || pathLists.Count() < 9 || pathLists[8] == null)
            {
                return;
            }
            var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
            if (!Global.IsExistsByHomeId(pathLists[8]))
            {
                return;
            }
            //删除本地图片
            System.IO.File.Delete(path);
            //删除备份
            Phone.UserCenter.HdlAutoBackupLogic.DeleteFile(pathLists[8]);
        }
        /// <summary>
        /// 移动背景图片到住宅目录下
@@ -749,19 +899,17 @@
        #region ◆ 添加设备________________________
        /// <summary>
        /// 添加设备
        /// 添加设备(此方法目前只给【我的喜爱】使用)
        /// </summary>
        /// <param name="deviceUIFilePath">Device UIF ile path.</param>
        public void AddDevice(string deviceUIFilePath)
        {
            if (string.IsNullOrEmpty(deviceUIFilePath))
             {
                 return;
            {
                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;
@@ -776,10 +924,11 @@
        }
        /// <summary>
        /// 添加设备
        /// 添加设备(此方法目前只给Room里面使用)
        /// </summary>
        /// <param name="device">要添加的设备对象</param>
        public void AddDevice(CommonDevice device)
        /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param>
        public void AddDevice(CommonDevice device, bool saveRealRoom)
        {
            if (device == null)
            {
@@ -788,10 +937,7 @@
            //设备信息保存到本地
            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);
@@ -799,8 +945,11 @@
                //保存到本地
                Save();
                //添加自动备份
                HdlAutoBackupLogic.AddOrEditorFile(FileName);
                if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
                {
                    //如果只有一个回路,则修改真实物理设备的房间
                    LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, this.Id, false);
                }
            }
        }
@@ -814,11 +963,10 @@
        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();
            }
        }
@@ -833,27 +981,52 @@
            {
                return;
            }
            DeviceUI deviceUI = new DeviceUI();
            deviceUI.DeviceAddr = device.DeviceAddr;
            deviceUI.DeviceEpoint = device.DeviceEpoint;
            //根据设备,获取所在的房间
            var room = this.GetRoomByDevice(device);
            if (room == null)
            {
                return;
            }
            string deviceFile = device.FilePath;
            //移除缓存
            if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false)
            if (room.DeviceUIFilePathList.Contains(deviceFile) == false)
            {
                return;
            }
            room.DeviceUIFilePathList.Remove(deviceUI.FileName);
            room.DeviceUIFilePathList.Remove(deviceFile);
            room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName);
            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
@@ -885,11 +1058,7 @@
                }
                listDevice.Add(device.CommonDevice);
            }
            if (listDevice.Count == 0)
            {
                return listDevice;
            }
            return Common.LocalDevice.Current.SortDevice(listDevice);
            return listDevice;
        }
        /// <summary>
@@ -942,35 +1111,30 @@
        }
        /// <summary>
        /// 获取该楼层的场景
        /// 获取未分配区域设备
        /// </summary>
        /// <param name="floorId"></param>
        /// <returns></returns>
        public List<SceneUI> GetSceneUIsByFloorId(string floorId)
        public List<DeviceUI> GetUnalloctedDeviceUIs()
        {
            var rooms = GetRoomsByFloorId(floorId);
            if (rooms == null)
            List<DeviceUI> deviceUIs = new List<DeviceUI> { };
            var dList = AllRoomDeviceUIList;
            var commonDeviceList = Common.LocalDevice.Current.listAllDevice;
            foreach (var device in commonDeviceList)
            {
                if (dList.Find((obj) => obj.CommonDevice.DeviceEpoint == device.DeviceEpoint && obj.CommonDevice.DeviceAddr == device.DeviceAddr) == null)
                {
                    deviceUIs.Add(Common.LocalDevice.Current.GetDeviceUI(device));
                }
            }
            if (deviceUIs.Count == 0)
            {
                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;
            return deviceUIs;
        }
        //public List<DeviceUI> GetUnalloctedDeviceUITypes
        #endregion
@@ -984,17 +1148,17 @@
        /// <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 = 0)
        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 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)
            {
@@ -1033,26 +1197,18 @@
            //加入成功
            if (result)
            {
                //iconPathType=0 直接传值, iconPathType=1和iconPathType=2需要拼接住宅路径
                var fullPath = sceneIconPath;
                if (iconPathType == 1 || iconPathType == 2)
                {
                    Common.Room.CurrentRoom.MoveBackGroundIamageFileToDirectory(sceneIconPath, $"{Config.Instance.FullPath}/{sceneIconPath}");
                    fullPath = $"{Config.Instance.FullPath}/{sceneIconPath}";
                }
                var sceneUI = new SceneUI
                {
                    Name = sceneName,
                    Id = getSceneIdData.NewScenesId,
                    IconPath = fullPath,
                    IconPath = sceneIconPath,
                    IconPathType = iconPathType,
                    AddSceneMemberDataList= commons
                };
                sceneUI.Save();
                SceneUIList.Add(sceneUI);
                SceneUIFilePathList.Add(sceneUI.FileName);
                sceneUI.Save();
                Save();
                HdlAutoBackupLogic.AddOrEditorFile(sceneUI.FileName);
                return 1;
            }
            return 0;
@@ -1064,17 +1220,8 @@
        /// <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();
        }
@@ -1084,10 +1231,13 @@
        /// <param name="scene"></param>
        public void DeleteScene(SceneUI scene)
        {
            //scene.IsCollected = false;
            scene.Save();
            SceneUIList.Remove(scene);
            SceneUIFilePathList.Remove(scene.FileName);
            var curScene = SceneUIList.Find((obj) => obj.Id == scene.Id);
            if (curScene == null)
            {
                return;
            }
            SceneUIList.Remove(curScene);
            SceneUIFilePathList.Remove(curScene.FileName);
            Save();
        }
@@ -1098,15 +1248,10 @@
        /// <summary>
        /// 是否是收藏设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool IsCollectInRoom(Room room,string filePath)
        public bool IsCollectInRoom(string filePath)
        {
            if(room.IsLove)
            {
                return true;
            }
            if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null)
            {
                return false;
@@ -1126,10 +1271,10 @@
        /// <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;
            }
            //if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null)
            //{
            //    return 0;
            //}
            bool result = true;
            //移除成员 返回结果
@@ -1181,9 +1326,61 @@
            {
                sceneUI.AddSceneMemberDataList = addCommons;
                sceneUI.Save();
                if (IsLove == false)
                {
                    var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id);
                    if (curScene != null)
                    {
                        curScene.Name = sceneUI.Name;
                        curScene.IconPath = sceneUI.IconPath;
                        curScene.IconPathType = sceneUI.IconPathType;
                        curScene.AddSceneMemberDataList = sceneUI.AddSceneMemberDataList;
                        curScene.SceneDelayTime = sceneUI.SceneDelayTime;
                        curScene.Save(false);
                        Common.Room.CurrentRoom.GetLoveRoom().Save();
                    }
                }
                return 1;
            }
            return 0;
        }
        /// <summary>
        /// 设置、同步延时时间
        /// </summary>
        /// <param name="scene"></param>
        public void ModifySceneDelayTime(SceneUI scene)
        {
            if (IsLove)
            {
                foreach (var r in Lists)
                {
                    if (r.IsLove || r.SceneUIList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var sce in r.SceneUIList)
                    {
                        if (sce.Id == scene.Id)
                        {
                            sce.SceneDelayTime = scene.SceneDelayTime;
                            sce.Save(false);
                            r.Save(false);
                            break;
                        }
                    }
                }
            }
            else
            {
                var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == scene.Id);
                if (curScene != null)
                {
                    curScene.SceneDelayTime = scene.SceneDelayTime;
                    curScene.Save(false);
                    Common.Room.CurrentRoom.GetLoveRoom().Save(false);
                }
            }
        }
        #endregion
@@ -1200,12 +1397,30 @@
            {
                return;
            }
            if (sceneUI.IconPathType == 1 || sceneUI.IconPathType == 2)
            {
                if (Global.IsExistsByHomeId(sceneUI.IconPath))
                {
                    Global.DeleteFilebyHomeId(sceneUI.IconPath);
                    HdlAutoBackupLogic.DeleteFile(sceneUI.IconPath);
                }
            }
            if (IsLove == false)
            {
                if (CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id) != null)
                {
                    CurrentRoom.GetLoveRoom().DeleteScene(sceneUI);
                }
            }
            SceneUIList.Remove(sceneUI);
            SceneUIFilePathList.Remove(sceneUI.FileName);
            Save();
            Global.DeleteFilebyHomeId(sceneUI.FileName);
            HdlAutoBackupLogic.DeleteFile(sceneUI.FileName);
            HdlAutoBackupLogic.AddOrEditorFile(FileName);
        }
        #endregion
@@ -1221,6 +1436,10 @@
        {
            foreach (var r in Lists)
            {
                if (r.IsLove)
                {
                    continue;
                }
                foreach (var sceneUI in r.SceneUIList)
                {
                    if (sceneUI.Id == sceneId)
@@ -1231,6 +1450,7 @@
            }
            return null;
        }
        /// <summary>
        /// 获取该楼层所有场景
        /// </summary>
@@ -1246,6 +1466,74 @@
            }
            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 ◆ 刷新场景_________________________
@@ -1255,51 +1543,45 @@
        /// </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;
            bool result = true;
            var sceneList = await ZigBee.Device.Scene.GetSceneListAsync();
            if (sceneList == null)
            {
                return false;
            }
            List<int> sceneIDList = new List<int> { };
            foreach (var scene in sceneList)
            {
                if (scene == null)
                {
                    continue;
                }
                sceneIDList.Add(scene.ScenesId);
            }
            foreach (var r in Lists)
            {
                if(r.IsLove)
                {
                    continue;
                }
                if (r.SceneUIList == null || r.SceneUIList.Count == 0)
                {
                    continue;
                }
                foreach (var rScene in r.SceneUIList)
                {
                    if (rScene == null)
                    {
                        continue;
                    }
                    if (sceneIDList.Contains(rScene.Id) == false)
                    {
                        r.RemoveScene(rScene);
                        result = true;
                    }
                }
            }
            return result;
        }
        #endregion
@@ -1480,6 +1762,6 @@
        }
        #endregion
    }
}