gxc
2020-01-08 e7a71b8318fa26b8a85eac86e4c0a129f453d44f
ZigbeeApp/Shared/Common/Room.cs
old mode 100755 new mode 100644
@@ -69,7 +69,7 @@
        /// <summary>
        /// 温度传感器(设备主键)
        /// </summary>
        /// </summary>
        public string TemperatrueDevice = string.Empty;
        /// <summary>
        /// 湿度传感器(设备主键)
@@ -78,11 +78,11 @@
        /// <summary>
        /// 温度
        /// </summary>
        public double Temperatrue;
        public decimal Temperatrue;
        /// <summary>
        /// 湿度
        /// </summary>
        public double Humidity;
        public decimal Humidity;
        /// <summary>
        /// 当前选择的房间
@@ -332,18 +332,18 @@
                        room.Name = $"{room.Name}";
                    }
                    Lists.Add(room);
                }
            }
            Config.Instance.Home.InitFloor();
            RefreshRoomListView();
            CurrentRoom.RefreshRoomListView();
        }
        /// <summary>
        /// 刷新房间视图列表
        /// </summary>
        public static void RefreshRoomListView()
        public void RefreshRoomListView()
        {
            Application.RunOnMainThread(() =>
            {
@@ -494,6 +494,9 @@
            Global.DeleteFilebyHomeId(roomFilePath);
            Lists.Remove(room);
            HdlAutoBackupLogic.DeleteFile(roomFilePath);
            CurrentRoom.RefreshRoomListView();
            return true;
        }
@@ -538,8 +541,21 @@
                    //设备(deviceUI)
                    beforeRoom.DeviceUIList.Clear();
                    foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList)
                    {
                        beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath));
                    {
                        var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceFilePath));
                        var tempDeviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo);
                        if (tempDeviceUI != null)
                        {
                            var delCommon = tempDeviceUIList.Find((obj) => obj.CommonDevice != null && tempDeviceUI.CommonDevice != null && obj.CommonDevice.Type == tempDeviceUI.CommonDevice.Type && obj.CommonDevice.CommonDeviceAddrEpoint == tempDeviceUI.CommonDevice.CommonDeviceAddrEpoint);
                            if (delCommon != null)
                            {
                                beforeRoom.DeviceUIList.Add(delCommon);
                            }
                            else
                            {
                                beforeRoom.AddDevice(deviceFilePath);
                            }
                        }
                    }
                    //场景(SceneUI)
                    beforeRoom.SceneUIList.Clear();
@@ -790,6 +806,25 @@
                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
@@ -1091,16 +1126,16 @@
        /// <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)
@@ -1140,26 +1175,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;
@@ -1205,15 +1232,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;
@@ -1233,10 +1255,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;
            //移除成员 返回结果
@@ -1310,6 +1332,13 @@
            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);
        }