| | |
| | |
|
| | | //不允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = false;
|
| | |
|
| | | for (int i = 0; i < listDistributedMark.Count; i++)
|
| | | {
|
| | |
| | | {
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = true;
|
| | | return null;
|
| | | }
|
| | | var dataResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetShardInfoResult>(result);
|
| | |
| | |
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = true;
|
| | |
|
| | | return listFile;
|
| | | }
|
| | |
| | | if (fileName.StartsWith("Room_") == true)
|
| | | {
|
| | | //房间文件特殊处理
|
| | | Config.Instance.Home.AddRoomListFilePath(fileName);
|
| | | Config.Instance.Home.AddRoomId(fileName.Replace("Room_", string.Empty).Replace(".json", string.Empty));
|
| | | }
|
| | | }
|
| | | //清空共享文件夹
|
| | |
| | | //删除掉这个房间文件
|
| | | Global.DeleteFilebyHomeId(fileName);
|
| | | dicUpdateTime.Remove(fileName);
|
| | | if (Config.Instance.Home.RoomFilePathList.Contains(fileName) == true)
|
| | | {
|
| | | Config.Instance.Home.RemoveRoomListFilePath(fileName);
|
| | | }
|
| | |
|
| | | Config.Instance.Home.RemoveRoomId(nowRoom.Id);
|
| | | }
|
| | | //检测本地场景文件,是否存在已经取消了共享了的
|
| | | else if (fileName.StartsWith("Scene_") == true)
|
| | |
| | | memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
|
| | | this.dicShardDeviceFile.Clear();
|
| | |
|
| | | var listDeviceFile = new HashSet<string>();
|
| | | var listSceneFile = new HashSet<string>();
|
| | | //keys:主键 value:文件名
|
| | | var dicDeviceFile = new Dictionary<string, string>();
|
| | | //keys:场景id value:文件名
|
| | | var dicSceneFile = new Dictionary<int, string>();
|
| | |
|
| | | var listFile = this.GetLocalAllShardFile();
|
| | | //先初始化房间
|
| | |
| | | this.dicShardDeviceFile[mainKeys] = fileName;
|
| | |
|
| | | //设备文件
|
| | | listDeviceFile.Add(fileName);
|
| | | dicDeviceFile[mainKeys] = fileName;
|
| | | }
|
| | | else if (fileName.StartsWith("Scene_") == true)
|
| | | {
|
| | | //场景文件
|
| | | listSceneFile.Add(fileName);
|
| | | dicSceneFile[(Convert.ToInt32(fileName.Replace("Scene_", string.Empty).Replace(".json", string.Empty)))] = fileName;
|
| | | }
|
| | | }
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | | }
|
| | |
|
| | | //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
|
| | | //检查设备的匹配情况
|
| | | foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //还原设备对象
|
| | | tempRoom.DeviceUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.DeviceUIFilePathList.Count; i++)
|
| | | //检查设备
|
| | | for (int i = 0; i < tempRoom.ListDevice.Count; i++)
|
| | | {
|
| | | string deviceFile = tempRoom.DeviceUIFilePathList[i];
|
| | | //这个设备文件匹配得到房间
|
| | | listDeviceFile.Remove(deviceFile);
|
| | | if (this.IsFileExists(deviceFile) == false)
|
| | | string deviceKeys = tempRoom.ListDevice[i];
|
| | | if (dicDeviceFile.ContainsKey(deviceKeys) == false)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.DeviceUIFilePathList.RemoveAt(i);
|
| | | tempRoom.ListDevice.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | //这个设备文件匹配得到房间
|
| | | dicDeviceFile.Remove(deviceKeys);
|
| | | }
|
| | | //还原场景对象
|
| | | tempRoom.SceneUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.SceneUIFilePathList.Count; i++)
|
| | | //检查场景
|
| | | for (int i = 0; i < tempRoom.ListSceneId.Count; i++)
|
| | | {
|
| | | string uiPath = tempRoom.SceneUIFilePathList[i];
|
| | | int intId = tempRoom.ListSceneId[i];
|
| | | if (dicSceneFile.ContainsKey(intId) == false)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.ListSceneId.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | var byteData = this.GetShardFileContent(dicSceneFile[intId]);
|
| | | //这个场景文件匹配得到房间
|
| | | listSceneFile.Remove(uiPath);
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | dicSceneFile.Remove(intId);
|
| | | if (byteData == null)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.SceneUIFilePathList.RemoveAt(i);
|
| | | tempRoom.ListSceneId.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | tempRoom.SceneUIList.Add(tempUi);
|
| | |
|
| | | //获取场景里面的全部目标(2019.11.05追加操作,有可能那个设备是由场景嵌套来的,所以它有可能不属于任何房间)
|
| | | foreach (var data in tempUi.AddSceneMemberDataList)
|
| | |
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true )
|
| | | {
|
| | | //这个设备文件匹配得到
|
| | | listDeviceFile.Remove(dicShardDeviceFile[mainkey]);
|
| | | dicDeviceFile.Remove(mainkey);
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | | {
|
| | | var temp = new SceneUI();
|
| | | temp.Id = data.ElseScenesId;
|
| | | //这个场景文件匹配得到
|
| | | listSceneFile.Remove(temp.FileName);
|
| | | dicSceneFile.Remove(data.ElseScenesId);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | //如果存在匹配不上的文件
|
| | | if (listDeviceFile.Count != 0 || listSceneFile.Count != 0)
|
| | | if (dicDeviceFile.Count != 0 || dicSceneFile.Count != 0)
|
| | | {
|
| | | //创建一个临时房间来存储
|
| | | var roomTemp = new Room();
|
| | |
| | | memberShardInfo.dicShardRoom[roomTemp.FileName] = roomTemp;
|
| | | roomTemp.Name = Language.StringByID(R.MyInternationalizationString.uUnallocated);
|
| | | //还原设备对象
|
| | | foreach (string deviceFile in listDeviceFile)
|
| | | foreach (string deviceKeys in dicDeviceFile.Keys)
|
| | | {
|
| | | roomTemp.DeviceUIFilePathList.Add(deviceFile);
|
| | | roomTemp.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | roomTemp.ListDevice.Add(deviceKeys);
|
| | | }
|
| | | //还原场景对象
|
| | | foreach (string uiPath in listSceneFile)
|
| | | foreach (int intId in dicSceneFile.Keys)
|
| | | {
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | roomTemp.SceneUIList.Add(tempUi);
|
| | | roomTemp.ListSceneId.Add(intId);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取设备文件名_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取设备文件名,不存在时,返回空字符串(仅限分享了的设备)
|
| | | /// </summary>
|
| | | /// <param name="deviceKeys">设备主键</param>
|
| | | /// <returns></returns>
|
| | | public string GetShardDeviceFileName(string deviceKeys)
|
| | | {
|
| | | if (this.dicShardDeviceFile.ContainsKey(deviceKeys) == true)
|
| | | {
|
| | | return this.dicShardDeviceFile[deviceKeys];
|
| | | }
|
| | | return string.Empty;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | }
|
| | | //防止出现错误,暂时保存两个列表(虽然没那么麻烦,不过既然已经这样写了就这样了)
|
| | | var dicBackDevice = new Dictionary<string, List<string>>();
|
| | | var dicBackScene = new Dictionary<string, List<string>>();
|
| | | var dicBackScene = new Dictionary<string, List<int>>();
|
| | | //临时备份房间设备列表
|
| | | this.BackupRoomDevicelistTemporary(memberShardInfo, dicBackDevice, dicBackScene);
|
| | |
|
| | |
| | |
|
| | | //不允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = false;
|
| | |
|
| | | if (BarMaxValue == -1)
|
| | | {
|
| | |
| | |
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = true;
|
| | |
|
| | | if (result == false)
|
| | | {
|
| | |
| | | if (memberShardInfo.dicShardRoom.ContainsKey(nowRoom.FileName) == false)
|
| | | {
|
| | | //克隆一个对象
|
| | | roomTemp = nowRoom.CloneRoomClass();
|
| | | roomTemp = HdlRoomLogic.Current.CloneRoomClass(nowRoom);
|
| | | memberShardInfo.TempRoom = roomTemp;
|
| | | //新分享的房间,如果图片是自定义的,并且这个图片是存在的,则上传图片
|
| | | if (roomTemp.BackgroundImageType != 0 && Common.Global.IsExistsByHomeId(roomTemp.BackgroundImage) == true)
|
| | |
| | | this.AddShardFile(device.FilePath);
|
| | |
|
| | | //加点缓存
|
| | | this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
|
| | | string mainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | this.dicShardDeviceFile[mainKeys] = device.FilePath;
|
| | |
|
| | | //设备的UI
|
| | | var deviceUi = device.FilePath;
|
| | | if (roomTemp.DeviceUIFilePathList.Contains(deviceUi) == false)
|
| | | if (roomTemp.ListDevice.Contains(mainKeys) == false)
|
| | | {
|
| | | roomTemp.DeviceUIFilePathList.Add(deviceUi);
|
| | | roomTemp.ListDevice.Add(mainKeys);
|
| | | }
|
| | | }
|
| | | //递归获取的设备不需要加入到房间
|
| | |
| | | listFile.Add(secene.FileName);
|
| | | this.AddShardFile(secene);
|
| | |
|
| | | if (roomTemp.SceneUIFilePathList.Contains(secene.FileName) == false)
|
| | | if (roomTemp.ListSceneId.Contains(secene.Id) == false)
|
| | | {
|
| | | roomTemp.SceneUIFilePathList.Add(secene.FileName);
|
| | | roomTemp.ListSceneId.Add(secene.Id);
|
| | | }
|
| | | }
|
| | | //递归获取的场景不需要加入到房间
|
| | |
| | | //反正楼层文件很小,一起给过去吧
|
| | | if (roomTemp.FloorId != string.Empty)
|
| | | {
|
| | | memberShardInfo.dicShardFloor[roomTemp.FloorId] = roomTemp.FloorName; ;
|
| | | memberShardInfo.dicShardFloor[roomTemp.FloorId] = HdlResidenceLogic.Current.GetFloorNameById(roomTemp.FloorId);
|
| | | }
|
| | | this.AddShardFile(memberShardInfo.dicShardFloor);
|
| | | listFile.Add(DirNameResourse.ShardFloorFile);
|
| | |
| | | listCheck.Add(mainKeys);
|
| | |
|
| | | //获取场景对象
|
| | | var sceneUi = Room.CurrentRoom.GetSceneUIBySceneId(data.ElseScenesId);
|
| | | var sceneUi = HdlSceneLogic.Current.GetSceneUIBySceneId(data.ElseScenesId);
|
| | | if (sceneUi != null)
|
| | | {
|
| | | listSceneUI.Add(sceneUi);
|
| | |
| | | /// <param name="dicBackDevice">空的设备备份列表</param>
|
| | | /// <param name="dicBackScene">空的场景备份列表</param>
|
| | | private void BackupRoomDevicelistTemporary(MemberShardInfoData memberShardInfo, Dictionary<string, List<string>> dicBackDevice,
|
| | | Dictionary<string, List<string>> dicBackScene)
|
| | | Dictionary<string, List<int>> dicBackScene)
|
| | | {
|
| | | foreach (var roomKeys in memberShardInfo.dicShardRoom.Keys)
|
| | | {
|
| | | dicBackDevice[roomKeys] = new List<string>();
|
| | | dicBackScene[roomKeys] = new List<string>();
|
| | | dicBackScene[roomKeys] = new List<int>();
|
| | |
|
| | | dicBackDevice[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].DeviceUIFilePathList);
|
| | | dicBackScene[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].SceneUIFilePathList);
|
| | | dicBackDevice[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].ListDevice);
|
| | | dicBackScene[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].ListSceneId);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// <param name="dicBackScene">临时备份的场景备份列表</param>
|
| | | /// <param name="listFile">上传的文件名</param>
|
| | | private void RecoverRoomDevicelistTemporary(MemberShardInfoData memberShardInfo, Dictionary<string, List<string>> dicBackDevice,
|
| | | Dictionary<string, List<string>> dicBackScene, List<string> listFile)
|
| | | Dictionary<string, List<int>> dicBackScene, List<string> listFile)
|
| | | {
|
| | | foreach (string fileName in listFile)
|
| | | {
|
| | |
| | | {
|
| | | continue;
|
| | | }
|
| | | memberShardInfo.dicShardRoom[roomKeys].DeviceUIFilePathList.Clear();
|
| | | memberShardInfo.dicShardRoom[roomKeys].DeviceUIFilePathList.AddRange(dicBackDevice[roomKeys]);
|
| | | memberShardInfo.dicShardRoom[roomKeys].ListDevice.Clear();
|
| | | memberShardInfo.dicShardRoom[roomKeys].ListDevice.AddRange(dicBackDevice[roomKeys]);
|
| | |
|
| | | memberShardInfo.dicShardRoom[roomKeys].SceneUIFilePathList.Clear();
|
| | | memberShardInfo.dicShardRoom[roomKeys].SceneUIFilePathList.AddRange(dicBackScene[roomKeys]);
|
| | | memberShardInfo.dicShardRoom[roomKeys].ListSceneId.Clear();
|
| | | memberShardInfo.dicShardRoom[roomKeys].ListSceneId.AddRange(dicBackScene[roomKeys]);
|
| | |
|
| | | //覆盖房间文件
|
| | | this.AddShardFile(memberShardInfo.dicShardRoom[roomKeys]);
|
| | |
| | | var roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName];
|
| | | //防止出错,先备份列表
|
| | | var listBackDevice = new List<string>();
|
| | | listBackDevice.AddRange(roomTemp.DeviceUIFilePathList);
|
| | | var listBackScene = new List<string>();
|
| | | listBackScene.AddRange(roomTemp.SceneUIFilePathList);
|
| | | listBackDevice.AddRange(roomTemp.ListDevice);
|
| | | var listBackScene = new List<int>();
|
| | | listBackScene.AddRange(roomTemp.ListSceneId);
|
| | |
|
| | | var listMark = new List<string>();
|
| | | //要删除的文件名字
|
| | | var listDeleteFile = new List<string>();
|
| | |
|
| | | //除了要删除的目标外,还分享的数据
|
| | | var listHadShard = this.GetAllShardedFileNameFromDictionary(memberShardInfo, nowRoom, listDevice, listSceneUI);
|
| | | var listHadShardKeys = this.GetAllShardedKeysFromDictionary(memberShardInfo, nowRoom, listDevice, listSceneUI);
|
| | |
|
| | | //先弄设备
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | string deviceFileName = device.FilePath;
|
| | |
|
| | | string mainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | //移除路径列表
|
| | | roomTemp.DeviceUIFilePathList.Remove(device.FilePath);
|
| | | if (listHadShard.Contains(deviceFileName) == true)
|
| | | roomTemp.ListDevice.Remove(mainKeys);
|
| | | if (listHadShardKeys.Contains(mainKeys) == true)
|
| | | {
|
| | | //其他场景分享有这个设备,所以不删除这个设备的根源文件,只是把房间的设备列表路径移除
|
| | | continue;
|
| | |
| | | foreach (var sceneUI in listSceneUI)
|
| | | {
|
| | | //移除缓存
|
| | | roomTemp.SceneUIFilePathList.Remove(sceneUI.FileName);
|
| | | roomTemp.ListSceneId.Remove(sceneUI.Id);
|
| | |
|
| | | //其他场景还嵌套着这个场景,所以不删除这个场景的根源文件,只是把房间的场景列表路径移除
|
| | | //但是它绑定的设备目标要删除
|
| | | if (listHadShard.Contains(sceneUI.FileName) == true)
|
| | | if (listHadShardKeys.Contains(sceneUI.Id.ToString()) == true)
|
| | | {
|
| | | continue;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | //执行删除嵌套的设备
|
| | | var listTemp = new HashSet<string>();
|
| | | var dicBindScene = new Dictionary<string, SceneUI>();
|
| | | this.GetSceneBindFileName(sceneUI, ref listTemp, ref dicBindScene);
|
| | | foreach (var fileName in listTemp)
|
| | | var dicDeviceKeys = new Dictionary<string, string>();
|
| | | var listBindScene = new List<SceneUI>();
|
| | | this.GetSceneBindListKeys(sceneUI, ref dicDeviceKeys, ref listBindScene);
|
| | | //设备的
|
| | | foreach (var myKeys in dicDeviceKeys.Keys)
|
| | | {
|
| | | if (listHadShard.Contains(fileName) == true)
|
| | | if (listHadShardKeys.Contains(myKeys) == true)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | //获取要删除的分享主键
|
| | | string fileName = dicDeviceKeys[myKeys];
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == true)
|
| | | {
|
| | | listMark.Add(memberShardInfo.dicAllShardKeys[fileName]);
|
| | | }
|
| | | listDeleteFile.Add(fileName);
|
| | |
|
| | | if (dicBindScene.ContainsKey(fileName) == true && dicBindScene[fileName].IconPathType != 0)
|
| | | }
|
| | | //场景的
|
| | | foreach (var seceUi in listBindScene)
|
| | | {
|
| | | if (seceUi.IconPathType != 0)
|
| | | {
|
| | | //删除自定义场景图片,它存在于本地,但是它是全路径
|
| | | string[] Arry = dicBindScene[fileName].IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | string[] Arry = seceUi.IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | string sceneFile = Arry[Arry.Length - 1];
|
| | | listDeleteFile.Add(sceneFile);
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(sceneFile) == true)
|
| | |
| | | }
|
| | |
|
| | | //如果这个房间的分享设备和场景全部删除的话,把分享房间文件也一起删除
|
| | | if (roomTemp.DeviceUIFilePathList.Count == 0 && roomTemp.SceneUIFilePathList.Count == 0)
|
| | | if (roomTemp.ListDevice.Count == 0 && roomTemp.ListSceneId.Count == 0)
|
| | | {
|
| | | //房间删除
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(nowRoom.FileName) == true)
|
| | |
| | | if (result == false)
|
| | | {
|
| | | //恢复
|
| | | roomTemp.DeviceUIFilePathList.Clear();
|
| | | roomTemp.DeviceUIFilePathList.AddRange(listBackDevice);
|
| | | roomTemp.ListDevice.Clear();
|
| | | roomTemp.ListDevice.AddRange(listBackDevice);
|
| | |
|
| | | roomTemp.SceneUIFilePathList.Clear();
|
| | | roomTemp.SceneUIFilePathList.AddRange(listBackScene);
|
| | | roomTemp.ListSceneId.Clear();
|
| | | roomTemp.ListSceneId.AddRange(listBackScene);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | #region ■ 移除共享的一般方法_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 从缓存字典中获取已经分享了的全部设备文件和场景的文件名字
|
| | | /// 从缓存字典中获取已经分享了的全部设备主键和场景的ID
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享信息</param>
|
| | | /// <param name="nowRoom">当前房间</param>
|
| | | /// <param name="listDeleteDevice">要删除的设备列表</param>
|
| | | /// <param name="listDeleteScene">要删除的场景列表</param>
|
| | | /// <returns></returns>
|
| | | private HashSet<string> GetAllShardedFileNameFromDictionary(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
|
| | | private HashSet<string> GetAllShardedKeysFromDictionary(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
|
| | | List<CommonDevice> listDeleteDevice, List<Common.SceneUI> listDeleteScene)
|
| | | {
|
| | | //获取全部要删除的文件名字
|
| | | var listDeleteFile = new HashSet<string>();
|
| | | var dicDeleteDeviceFile = new Dictionary<string, string>();
|
| | | foreach (var device in listDeleteDevice)
|
| | | {
|
| | | listDeleteFile.Add(device.FilePath);
|
| | | dicDeleteDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
|
| | | }
|
| | | var dicDeleteSceneFile = new Dictionary<int, string>();
|
| | | foreach (var scene in listDeleteScene)
|
| | | {
|
| | | listDeleteFile.Add(scene.FileName);
|
| | | dicDeleteSceneFile[scene.Id] = scene.FileName;
|
| | | }
|
| | |
|
| | | var listShardFile = new HashSet<string>();
|
| | | //获取还处于分享状态的文件
|
| | | var listShardKeys = new HashSet<string>();
|
| | | //获取还处于分享状态的主键
|
| | | foreach (var roomTemp in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //设备
|
| | | foreach (var deviceUi in roomTemp.DeviceUIFilePathList)
|
| | | foreach (var deviceKeys in roomTemp.ListDevice)
|
| | | {
|
| | | string deviceFile = deviceUi;
|
| | | if (listDeleteFile.Contains(deviceFile) == true)
|
| | | if (dicDeleteDeviceFile.ContainsKey(deviceKeys) == true)
|
| | | {
|
| | | //因为一个回路只能分配一个区域,所以可以直接判断
|
| | | continue;
|
| | | }
|
| | | if (listShardFile.Contains(deviceFile) == false)
|
| | | if (listShardKeys.Contains(deviceKeys) == false)
|
| | | {
|
| | | //这个文件还分享着
|
| | | listShardFile.Add(deviceFile);
|
| | | listShardKeys.Add(deviceKeys);
|
| | | }
|
| | |
|
| | | }
|
| | | //场景
|
| | | foreach (var scene in roomTemp.SceneUIList)
|
| | | foreach (var sceneId in roomTemp.ListSceneId)
|
| | | {
|
| | | if (roomTemp.SceneUIFilePathList.Contains(scene.FileName) == false)
|
| | | {
|
| | | //这个场景已经被删除
|
| | | continue;
|
| | | }
|
| | | if (roomTemp.FileName == nowRoom.FileName)
|
| | | {
|
| | | //如果循环到了当前房间
|
| | | if (listDeleteFile.Contains(scene.FileName) == true)
|
| | | if (dicDeleteSceneFile.ContainsKey(sceneId) == true)
|
| | | {
|
| | | //如果是删除目标,则不添加
|
| | | continue;
|
| | | }
|
| | | }
|
| | | //获取场景里面的全部目标
|
| | | var listTemp = new HashSet<string>();
|
| | | var dicTemp = new Dictionary<string, SceneUI>();
|
| | | this.GetSceneBindFileName(scene, ref listTemp, ref dicTemp);
|
| | |
|
| | | if (listShardFile.Contains(scene.FileName) == false)
|
| | | var byteData = this.GetShardFileContent($"Scene_{sceneId}.json");
|
| | | if (byteData == null)
|
| | | {
|
| | | //场景自身的文件
|
| | | listShardFile.Add(scene.FileName);
|
| | | continue;
|
| | | }
|
| | | foreach (string file in listTemp)
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var sceneTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | |
|
| | | //获取场景里面的全部目标
|
| | | var listTempKeys = new HashSet<string>();
|
| | | //从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取)
|
| | | this.GetSceneBindListKeys(sceneTemp, ref listTempKeys);
|
| | |
|
| | | if (listShardKeys.Contains(sceneId.ToString()) == false)
|
| | | {
|
| | | if (listShardFile.Contains(file) == false)
|
| | | //场景自身
|
| | | listShardKeys.Add(sceneId.ToString());
|
| | | }
|
| | | foreach (string myKeys2 in listTempKeys)
|
| | | {
|
| | | if (listShardKeys.Contains(myKeys2) == false)
|
| | | {
|
| | | listShardFile.Add(file);
|
| | | listShardKeys.Add(myKeys2);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return listShardFile;
|
| | | return listShardKeys;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从场景对象里面获取全部的绑定目标的文件名字(这里面的东西必须从分享数据中获取)
|
| | | /// 从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取)
|
| | | /// </summary>
|
| | | /// <param name="scene">场景</param>
|
| | | /// <param name="listFile">文件列表(里面存的是设备UI文件和设备文件和场景文件)</param>
|
| | | /// <param name="dicBindScene">绑定的场景对象</param>
|
| | | private void GetSceneBindFileName(Common.SceneUI scene, ref HashSet<string> listFile,ref Dictionary<string, SceneUI> dicBindScene)
|
| | | /// <param name="dicDeviceKeys">设备主键列表(里面没有场景),keys:主键,value:文件名</param>
|
| | | /// <param name="listBindScene">绑定的场景对象</param>
|
| | | private void GetSceneBindListKeys(Common.SceneUI scene, ref Dictionary<string, string> dicDeviceKeys, ref List<SceneUI> listBindScene)
|
| | | {
|
| | | foreach (var data in scene.AddSceneMemberDataList)
|
| | | {
|
| | |
| | | if (data.Type == 0)
|
| | | {
|
| | | string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
|
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true && listFile.Contains(dicShardDeviceFile[mainkey]) == false)
|
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true && dicDeviceKeys.ContainsKey(mainkey) == false)
|
| | | {
|
| | | listFile.Add(dicShardDeviceFile[mainkey]);
|
| | | dicDeviceKeys[mainkey] = dicShardDeviceFile[mainkey];
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | | {
|
| | | var temp = new SceneUI();
|
| | | temp.Id = data.ElseScenesId;
|
| | | var byteData = this.GetShardFileContent(temp.FileName);
|
| | | var byteData = this.GetShardFileContent($"Scene_{data.ElseScenesId}.json");
|
| | | if (byteData != null)
|
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | dicBindScene[roomTemp.FileName] = roomTemp;
|
| | | if (listFile.Contains(roomTemp.FileName) == false)
|
| | | {
|
| | | listFile.Add(roomTemp.FileName);
|
| | | }
|
| | | var sceneTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | listBindScene.Add(sceneTemp);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取)
|
| | | /// </summary>
|
| | | /// <param name="scene">场景</param>
|
| | | /// <param name="listKeys">主键列表(设备和场景)</param>
|
| | | private void GetSceneBindListKeys(Common.SceneUI scene, ref HashSet<string> listKeys)
|
| | | {
|
| | | foreach (var data in scene.AddSceneMemberDataList)
|
| | | {
|
| | | //设备
|
| | | if (data.Type == 0)
|
| | | {
|
| | | string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
|
| | | if (listKeys.Contains(mainkey) == false)
|
| | | {
|
| | | listKeys.Add(mainkey);
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | | {
|
| | | if (listKeys.Contains(data.ElseScenesId.ToString()) == false)
|
| | | {
|
| | | listKeys.Add(data.ElseScenesId.ToString());
|
| | | }
|
| | | }
|
| | | }
|