| | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 分享的设备文件(key:设备主键,value:设备文件) |
| | | /// 分享压缩文件的名字 |
| | | /// </summary> |
| | | private Dictionary<string, string> dicShardDeviceFile = new Dictionary<string, string>(); |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取分享文件_______________________ |
| | | |
| | | private const string SHARED_BIN_FILE = "SharedData.bin"; |
| | | /// <summary> |
| | | /// 将分享的数据存入本地,返回的是文件名字(异常时返回null),调用 GetShardFileContent 可以获取文件内的内容 |
| | | /// 分享的设备对象 |
| | | /// </summary> |
| | | /// <param name="dicFileKeys">key:文件的主键 value:文件名称</param> |
| | | /// <returns></returns> |
| | | private List<string> SetShardFileToLocation(Dictionary<string, string> dicFileKeys) |
| | | { |
| | | if (dicFileKeys.Count == 0) |
| | | { |
| | | return new List<string>(); |
| | | } |
| | | int listMarkCount = dicFileKeys.Count; |
| | | |
| | | List<string> listFile = new List<string>(); |
| | | //文件夹 |
| | | string strDir = HdlFileNameResourse.DownLoadShardDirectory; |
| | | |
| | | //不允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = false; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = false; |
| | | |
| | | //计数 |
| | | int nowCount = 0; |
| | | foreach (var fileKey in dicFileKeys.Keys) |
| | | { |
| | | nowCount++; |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = fileKey }; |
| | | var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/home/share/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (result == null) |
| | | { |
| | | //允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = true; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = true; |
| | | return null; |
| | | } |
| | | //对应旧版本的设备文件 Device_OnoffOutput_abcdfrtgg_01 |
| | | string shareName = dicFileKeys[fileKey]; |
| | | if (shareName.StartsWith("Device_") == true) |
| | | { |
| | | var strArry = shareName.Split(new string[] { "_" }, StringSplitOptions.None); |
| | | if (strArry.Length == 4) |
| | | { |
| | | shareName = strArry[0] + "_" + strArry[2] + "_" + strArry[3]; |
| | | } |
| | | } |
| | | //文件名字 |
| | | listFile.Add(shareName); |
| | | //保存到指定文件夹下 |
| | | HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(strDir, shareName), result); |
| | | //设置进度值 |
| | | ProgressFormBar.Current.SetValue(nowCount, listMarkCount); |
| | | } |
| | | |
| | | //允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = true; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = true; |
| | | |
| | | return listFile; |
| | | } |
| | | |
| | | private Dictionary<string, CommonDevice> DicDevices = null; |
| | | /// <summary> |
| | | /// 获取分享文件的内容 |
| | | /// 分享的场景对象 |
| | | /// </summary> |
| | | /// <param name="fileName">文件名称(不是全路径)</param> |
| | | /// <returns></returns> |
| | | public byte[] GetShardFileContent(string fileName) |
| | | { |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | if (System.IO.File.Exists(fullName) == false) |
| | | { |
| | | return null; |
| | | } |
| | | string path = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | var varByte = HdlFileLogic.Current.ReadFileByteContent(path); |
| | | return varByte; |
| | | } |
| | | |
| | | private Dictionary<int, SceneUI> DicScenes = new Dictionary<int, SceneUI>(); |
| | | /// <summary> |
| | | /// 获取本地全部的共享文件 |
| | | /// 分享的房间信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<string> GetLocalAllShardFile() |
| | | { |
| | | return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.DownLoadShardDirectory); |
| | | } |
| | | |
| | | private Dictionary<string, Room> DicRooms = new Dictionary<string, Room>(); |
| | | /// <summary> |
| | | /// 文件是否存在 |
| | | /// 分享的楼层信息 |
| | | /// </summary> |
| | | /// <param name="fileName"></param> |
| | | /// <returns></returns> |
| | | public bool IsFileExists(string fileName) |
| | | { |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | if (System.IO.File.Exists(fullName) == false) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加分享文件_______________________ |
| | | |
| | | private Dictionary<string, string> DicFloor = new Dictionary<string, string>(); |
| | | /// <summary> |
| | | /// 添加分享文件到缓存 |
| | | /// 分享的文件的主键(key:文件名,value:主键) |
| | | /// </summary> |
| | | /// <param name="fileName">原根目录下的文件名</param> |
| | | public void AddShardFile(string fileName) |
| | | { |
| | | if (Global.IsExistsByHomeId(fileName) == false) |
| | | { |
| | | return; |
| | | } |
| | | string oldName = System.IO.Path.Combine(Config.Instance.FullPath, fileName); |
| | | string newName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | HdlFileLogic.Current.CopyFile(oldName, newName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加房间对象到缓存 |
| | | /// </summary> |
| | | /// <param name="room">房间对象</param> |
| | | public void AddShardFile(Common.Room room) |
| | | { |
| | | room.IsSharedRoom = true; |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, room.FileName); |
| | | //写入内容 |
| | | HdlFileLogic.Current.SaveFileContent(fullName, room); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加场景对象到缓存 |
| | | /// </summary> |
| | | /// <param name="scene">场景</param> |
| | | public void AddShardFile(Common.SceneUI scene) |
| | | { |
| | | scene.IsSharedScene = true; |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, scene.FileName); |
| | | //写入内容 |
| | | HdlFileLogic.Current.SaveFileContent(fullName, scene); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加楼层对象到缓存 |
| | | /// </summary> |
| | | /// <param name="dic">楼层</param> |
| | | public void AddShardFile(Dictionary<string, string> dic) |
| | | { |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, HdlFileNameResourse.ShardFloorFile); |
| | | //写入内容 |
| | | HdlFileLogic.Current.SaveFileContent(fullName, dic); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 删除分享文件_______________________ |
| | | |
| | | /// <summary> |
| | | /// 添加分享文件到缓存 |
| | | /// </summary> |
| | | /// <param name="fileName">指定文件名字</param> |
| | | public void DeleteShardFile(string fileName) |
| | | { |
| | | fileName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | HdlFileLogic.Current.DeleteFile(fileName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空共享文件夹 |
| | | /// </summary> |
| | | public void ClearShardDirectory() |
| | | { |
| | | this.dicShardDeviceFile.Clear(); |
| | | //创建文件夹 |
| | | HdlFileLogic.Current.CreateDirectory(HdlFileNameResourse.DownLoadShardDirectory, true); |
| | | } |
| | | private Dictionary<string, string> DicShardKeys = new Dictionary<string, string>(); |
| | | |
| | | #endregion |
| | | |
| | |
| | | //先看看这分享数据里面有什么鬼 |
| | | foreach (var info in listShardInfo) |
| | | { |
| | | //如果是压缩文件,需要特殊处理 |
| | | if (info.FileName == SHARED_BIN_FILE) |
| | | { |
| | | //判断Bin文件的更新日期 |
| | | if (dicUpdateTime.ContainsKey(info.FileName) == false |
| | | || info.CreateTime.CompareTo(dicUpdateTime[info.FileName]) > 0) |
| | | { |
| | | dicAddMark[info.Id] = info.FileName; |
| | | //更新日更新 |
| | | dicUpdateTime[info.FileName] = info.CreateTime; |
| | | } |
| | | continue; |
| | | } |
| | | dicShardFile[info.FileName] = info.Id; |
| | | |
| | | //如果本地没有,或者更新日期大于前回更新日期的时候 |
| | |
| | | } |
| | | } |
| | | |
| | | //不要忘记初始化这个东西 |
| | | this.DicDevices = new Dictionary<string, CommonDevice>(); |
| | | //从云端获取下来文件 |
| | | if (dicAddMark.Count > 0) |
| | | { |
| | |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing)); |
| | | |
| | | //将分享的数据存入本地(获取的是本地没有的) |
| | | this.ClearShardDirectory(); |
| | | var listDbFile = this.SetShardFileToLocation(dicAddMark); |
| | | if (listDbFile == null) |
| | | { |
| | |
| | | return false; |
| | | } |
| | | |
| | | //生成文件 |
| | | //转移文件 |
| | | foreach (string fileName in listDbFile) |
| | | { |
| | | var oldPath = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | var newPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName); |
| | | HdlFileLogic.Current.CopyFile(oldPath, newPath); |
| | | //不是bin文件,则移动文件到本地 |
| | | if (fileName != SHARED_BIN_FILE) |
| | | { |
| | | var oldPath = Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | var newPath = Path.Combine(Config.Instance.FullPath, fileName); |
| | | HdlFileLogic.Current.CopyFile(oldPath, newPath); |
| | | } |
| | | else |
| | | { |
| | | //读取bin文件的内容 |
| | | var dataContent = this.GetShardFileContent(fileName); |
| | | if (dataContent != null) |
| | | { |
| | | //解析bin文件 |
| | | this.AdjustBinFileContent(Encoding.UTF8.GetString(dataContent)); |
| | | } |
| | | } |
| | | } |
| | | //清空共享文件夹 |
| | | this.ClearShardDirectory(); |
| | | } |
| | | |
| | | //同步服务器的取消了的分享内容 |
| | | return this.SynchronizeDeleteSharedContent(dicShardFile, dicUpdateTime); |
| | | return this.SynchronizeSharedCancelContent(dicShardFile, dicUpdateTime); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 同步服务器的取消了的分享内容 |
| | | /// </summary> |
| | | /// <param name="dicShardFile">云端上面分享的文件,为Null时从新获取 key:文件名 value:主键</param> |
| | | /// <param name="dicUpdateTime">分享文件的更新时间,为Null时从新获取</param> |
| | | /// <param name="dicShardFile">云端上面分享的文件,key:文件名 value:主键</param> |
| | | /// <param name="dicUpdateTime">分享文件的更新时间,key:文件名 value:时间</param> |
| | | /// <returns></returns> |
| | | public bool SynchronizeDeleteSharedContent(Dictionary<string, string> dicShardFile = null, Dictionary<string, string> dicUpdateTime = null) |
| | | private bool SynchronizeSharedCancelContent(Dictionary<string, string> dicShardFile, Dictionary<string, string> dicUpdateTime) |
| | | { |
| | | if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3) |
| | | { |
| | | //只有成员才有这个概念 |
| | | return true; |
| | | } |
| | | //开启进度条 共享数据同步中 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing)); |
| | | |
| | | if (dicUpdateTime == null) |
| | | //重新设置楼层 |
| | | Config.Instance.Home.FloorDics.Clear(); |
| | | foreach (var key in this.DicFloor.Keys) |
| | | { |
| | | //获取前回共享文件的更新日期(keys: 文件名字, value: 更新日期) |
| | | dicUpdateTime = this.GetAllShardFileAgoUpdateTime(); |
| | | Config.Instance.Home.FloorDics[key] = this.DicFloor[key]; |
| | | } |
| | | |
| | | //重新获取 |
| | | if (dicShardFile == null) |
| | | //获取分享的设备的文件名 |
| | | var listShardDeviceFile = new HashSet<string>(); |
| | | foreach (var device in this.DicDevices.Values) |
| | | { |
| | | dicShardFile = new Dictionary<string, string>(); |
| | | //获取主人分享给成员的文件列表 |
| | | var listShardData = this.GetShardFileListFromDb(Config.Instance.Guid); |
| | | if (listShardData == null) |
| | | { |
| | | //关闭 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | } |
| | | //先看看这分享数据里面有什么鬼 |
| | | foreach (var info in listShardData) |
| | | { |
| | | dicShardFile[info.FileName] = info.Id; |
| | | } |
| | | listShardDeviceFile.Add(device.FilePath); |
| | | } |
| | | //住宅的根目录 |
| | | var localPath = Config.Instance.FullPath; |
| | | |
| | | //清空楼层数据 |
| | | Common.Config.Instance.Home.FloorDics.Clear(); |
| | | //然后检测本地的文件 |
| | | var listLocalFile = HdlFileLogic.Current.GetRootPathListFile(); |
| | | foreach (string fileName in listLocalFile) |
| | | { |
| | | if (fileName == HdlFileNameResourse.ShardFloorFile) |
| | | try |
| | | { |
| | | //楼层文件 |
| | | var varData = Global.ReadFileByHomeId(fileName); |
| | | var dicFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(Encoding.UTF8.GetString(varData)); |
| | | Common.Config.Instance.Home.FloorDics = dicFloor; |
| | | //暂时不保存,留在最后面才保存 |
| | | Global.DeleteFilebyHomeId(fileName); |
| | | } |
| | | |
| | | if (dicShardFile.ContainsKey(fileName) == true) |
| | | { |
| | | //本地的这个文件还分享着,没有问题 |
| | | continue; |
| | | } |
| | | |
| | | //检测本地设备文件,是否存在已经取消了共享了的 |
| | | if (fileName.StartsWith("Device_") == true) |
| | | { |
| | | //删除掉这个设备文件 |
| | | Global.DeleteFilebyHomeId(fileName); |
| | | dicUpdateTime.Remove(fileName); |
| | | } |
| | | //检测本地房间文件,是否存在已经取消了共享了的 |
| | | else if (fileName.StartsWith("Room_") == true) |
| | | { |
| | | var roomData = Global.ReadFileByHomeId(fileName); |
| | | var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(Encoding.UTF8.GetString(roomData)); |
| | | if (nowRoom.IsSharedRoom == false) |
| | | if (dicShardFile.ContainsKey(fileName) == true) |
| | | { |
| | | //这个房间是他自己创建的 |
| | | //本地的这个文件还分享着,没有问题,或许应该只有分享图片 |
| | | continue; |
| | | } |
| | | |
| | | //删除掉这个房间文件 |
| | | Global.DeleteFilebyHomeId(fileName); |
| | | dicUpdateTime.Remove(fileName); |
| | | } |
| | | //检测本地场景文件,是否存在已经取消了共享了的 |
| | | else if (fileName.StartsWith("Scene_") == true) |
| | | { |
| | | var sceneData = Global.ReadFileByHomeId(fileName); |
| | | var nowScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(Encoding.UTF8.GetString(sceneData)); |
| | | if (nowScene.IsSharedScene == false) |
| | | //检测本地设备文件,是否存在已经取消了共享了的 |
| | | if (fileName.StartsWith("Device_") == true) |
| | | { |
| | | //这个场景是他自己创建的 |
| | | continue; |
| | | //判断是否还在分享的bin文件里面 |
| | | if (listShardDeviceFile.Contains(fileName) == false) |
| | | { |
| | | //删除掉这个设备文件 |
| | | HdlFileLogic.Current.DeleteFile(Path.Combine(localPath, fileName)); |
| | | dicUpdateTime.Remove(fileName); |
| | | } |
| | | } |
| | | //删除掉这个场景文件 |
| | | Global.DeleteFilebyHomeId(fileName); |
| | | dicUpdateTime.Remove(fileName); |
| | | //检测本地房间文件,是否存在已经取消了共享了的 |
| | | else if (fileName.StartsWith("Room_") == true) |
| | | { |
| | | var fullFile = Path.Combine(localPath, fileName); |
| | | var roomData = HdlFileLogic.Current.ReadFileTextContent(fullFile); |
| | | if (roomData != null) |
| | | { |
| | | var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(roomData); |
| | | if (nowRoom.IsSharedRoom == false || this.DicRooms.ContainsKey(nowRoom.Id) == true) |
| | | { |
| | | //这个房间是他自己创建的,或者还在分享着 |
| | | continue; |
| | | } |
| | | //删除掉这个房间文件 |
| | | HdlFileLogic.Current.DeleteFile(fullFile); |
| | | dicUpdateTime.Remove(fileName); |
| | | } |
| | | } |
| | | //检测本地场景文件,是否存在已经取消了共享了的 |
| | | else if (fileName.StartsWith("Scene_") == true) |
| | | { |
| | | var fullFile = Path.Combine(localPath, fileName); |
| | | var sceneData = HdlFileLogic.Current.ReadFileTextContent(fullFile); |
| | | var nowScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(sceneData); |
| | | if (nowScene != null) |
| | | { |
| | | if (nowScene.IsSharedScene == false || this.DicScenes.ContainsKey(nowScene.Id) == true) |
| | | { |
| | | //这个场景是他自己创建的,或者还在分享着 |
| | | continue; |
| | | } |
| | | //删除掉这个场景文件 |
| | | HdlFileLogic.Current.DeleteFile(fullFile); |
| | | dicUpdateTime.Remove(fileName); |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | //保存楼层数据 |
| | | Common.Config.Instance.Home.Save(false); |
| | | Config.Instance.Home.Save(false); |
| | | |
| | | //网关文件非合法性是刷新设备列表的函数里面实现 |
| | | |
| | |
| | | //关闭 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | //释放缓存 |
| | | this.Dispone(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从云端获取分享的文件列表 |
| | | /// </summary> |
| | | /// <param name="i_childAccountId">账号的id,成员登陆的话,直接传账号密码登陆之后,云端返回的那个id</param> |
| | | /// <returns></returns> |
| | | private List<ReceiveShardInfoResult> GetShardFileListFromDb(string i_childAccountId) |
| | | { |
| | | //获取主人分享给成员的文件列表 |
| | | var pra = new { homeId = Config.Instance.HomeId, childAccountId = i_childAccountId }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/share/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | { |
| | | return null; |
| | | } |
| | | var listShardInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result.Data.ToString()); |
| | | |
| | | return listShardInfo; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | |
| | | #endregion |
| | | |
| | | //----------------------------------分割线(数据预备)------------------------------------------------- |
| | | |
| | | #region ■ 数据预备___________________________ |
| | | #region ■ 获取分享数据列表___________________ |
| | | |
| | | /// <summary> |
| | | /// 获取成员共享列表然后保存到本地(用完之后最好调用清空 ClearShardDirectory函数清空) |
| | | /// 从云端获取分享的文件列表 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo"> |
| | | /// <para>成员的分享数据</para> |
| | | /// <para>如果不知道这是什么东西,就New一个,然后缓存起来,调用其他函数都需要这个东西</para> |
| | | /// <para>New的时候记得对SubAccountDistributedMark赋值,它是成员列表接口返回的SubAccountDistributedMark</para> |
| | | /// </param> |
| | | /// <param name="i_childAccountId">账号的id,成员登陆的话,直接传账号密码登陆之后,云端返回的那个id</param> |
| | | /// <returns></returns> |
| | | public bool GetMemberShardContentListAndSetToLocation(MemberShardInfoData memberShardInfo) |
| | | private List<ReceiveShardInfoResult> GetShardFileListFromDb(string i_childAccountId) |
| | | { |
| | | if (memberShardInfo.Refresh == false) |
| | | //获取主人分享给成员的文件列表 |
| | | var pra = new { homeId = Config.Instance.HomeId, childAccountId = i_childAccountId }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/share/findAll", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | { |
| | | //从本地获取成员的分享列表 |
| | | this.GetMemberShardContentListFromLocal(memberShardInfo); |
| | | return true; |
| | | return null; |
| | | } |
| | | memberShardInfo.Refresh = false; |
| | | var listShardInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result.Data.ToString()); |
| | | |
| | | //正在获取分享数据 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting)); |
| | | |
| | | //从云端获取分享的文件列表 |
| | | var listData = this.GetShardFileListFromDb(memberShardInfo.ChildAccountId); |
| | | if (listData == null) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | } |
| | | //先清空共享文件夹 |
| | | this.ClearShardDirectory(); |
| | | |
| | | var dicFileKey = new Dictionary<string, string>(); |
| | | foreach (var data in listData) |
| | | { |
| | | //性能优化:如果本地拥有这个文件的话,直接使用那个文件 |
| | | string fileName = data.FileName; |
| | | if (fileName.StartsWith("Device_") == true) |
| | | { |
| | | string[] Arry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (Arry.Length == 4) |
| | | { |
| | | //对应旧数据:Device_OnOffOutput_abcjdffdfj_01 |
| | | fileName = Arry[0] + "_" + Arry[2] + "_" + Arry[3]; |
| | | } |
| | | } |
| | | //记录起它的主键 |
| | | memberShardInfo.dicAllShardKeys[fileName] = data.Id; |
| | | |
| | | if (fileName.StartsWith("Room_") == true || fileName.StartsWith("Scene_") == true) |
| | | { |
| | | //房间文件和场景文件需要重新反序列化 |
| | | dicFileKey[data.Id] = data.FileName; |
| | | continue; |
| | | } |
| | | if (Shared.Common.Global.IsExistsByHomeId(fileName) == true) |
| | | { |
| | | //其他文件的话,如果本地存在,则以本地文件为准 |
| | | this.AddShardFile(fileName); |
| | | continue; |
| | | } |
| | | dicFileKey[data.Id] = data.FileName; |
| | | } |
| | | |
| | | //将分享的数据存入本地,返回的是文件名字(异常时返回null) |
| | | var listFile = this.SetShardFileToLocation(dicFileKey); |
| | | if (listFile == null) |
| | | { |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | } |
| | | |
| | | //从本地获取成员的分享列表 |
| | | this.GetMemberShardContentListFromLocal(memberShardInfo); |
| | | |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return true; |
| | | return listShardInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从本地获取成员的分享列表 |
| | | /// 将分享的数据存入本地,返回的是文件名字(异常时返回null) |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据的缓存(调用这个函数会刷新这个变量的信息)</param> |
| | | private void GetMemberShardContentListFromLocal(MemberShardInfoData memberShardInfo) |
| | | { |
| | | memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>(); |
| | | this.dicShardDeviceFile.Clear(); |
| | | |
| | | //keys:主键 value:文件名 |
| | | var dicDeviceFile = new Dictionary<string, string>(); |
| | | //keys:场景id value:文件名 |
| | | var dicSceneFile = new Dictionary<int, string>(); |
| | | |
| | | var listFile = this.GetLocalAllShardFile(); |
| | | //先初始化房间 |
| | | foreach (string fileName in listFile) |
| | | { |
| | | try |
| | | { |
| | | if (fileName.StartsWith("Room_") == true) |
| | | { |
| | | //房间文件 |
| | | var byteData = this.GetShardFileContent(fileName); |
| | | if (byteData != null) |
| | | { |
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData); |
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData); |
| | | memberShardInfo.dicShardRoom[fileName] = roomTemp; |
| | | } |
| | | } |
| | | else if (fileName == HdlFileNameResourse.ShardFloorFile) |
| | | { |
| | | //楼层文件 |
| | | var byteData = this.GetShardFileContent(fileName); |
| | | if (byteData != null) |
| | | { |
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData); |
| | | memberShardInfo.dicShardFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(valueData); |
| | | } |
| | | } |
| | | else if (fileName.StartsWith("Device_") == true) |
| | | { |
| | | string[] Arry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (Arry.Length == 4) |
| | | { |
| | | //对应旧数据:Device_OnOffOutput_abcjdffdfj_01 |
| | | string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(Arry[2], Convert.ToInt32(Arry[3])); |
| | | this.dicShardDeviceFile[mainKeys] = Arry[0] + "_" + Arry[2] + "_" + Arry[3]; |
| | | //设备文件 |
| | | dicDeviceFile[mainKeys] = this.dicShardDeviceFile[mainKeys]; |
| | | } |
| | | else |
| | | { |
| | | string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(Arry[1], Convert.ToInt32(Arry[2])); |
| | | this.dicShardDeviceFile[mainKeys] = fileName; |
| | | //设备文件 |
| | | dicDeviceFile[mainKeys] = fileName; |
| | | } |
| | | } |
| | | else if (fileName.StartsWith("Scene_") == true) |
| | | { |
| | | //场景文件 |
| | | dicSceneFile[(Convert.ToInt32(fileName.Replace("Scene_", string.Empty).Replace(".json", string.Empty)))] = fileName; |
| | | } |
| | | } |
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } |
| | | } |
| | | |
| | | //检查设备的匹配情况 |
| | | foreach (var tempRoom in memberShardInfo.dicShardRoom.Values) |
| | | { |
| | | //检查设备 |
| | | for (int i = 0; i < tempRoom.ListDevice.Count; i++) |
| | | { |
| | | string deviceKeys = tempRoom.ListDevice[i]; |
| | | if (dicDeviceFile.ContainsKey(deviceKeys) == false) |
| | | { |
| | | //移除掉这个不对劲的路径 |
| | | tempRoom.ListDevice.RemoveAt(i); |
| | | i--; |
| | | continue; |
| | | } |
| | | //这个设备文件匹配得到房间 |
| | | dicDeviceFile.Remove(deviceKeys); |
| | | } |
| | | //检查场景 |
| | | for (int i = 0; i < tempRoom.ListSceneId.Count; i++) |
| | | { |
| | | int intId = tempRoom.ListSceneId[i]; |
| | | if (dicSceneFile.ContainsKey(intId) == false) |
| | | { |
| | | //移除掉这个不对劲的路径 |
| | | tempRoom.ListSceneId.RemoveAt(i); |
| | | i--; |
| | | continue; |
| | | } |
| | | var byteData = this.GetShardFileContent(dicSceneFile[intId]); |
| | | //这个场景文件匹配得到房间 |
| | | dicSceneFile.Remove(intId); |
| | | if (byteData == null) |
| | | { |
| | | //移除掉这个不对劲的路径 |
| | | tempRoom.ListSceneId.RemoveAt(i); |
| | | i--; |
| | | continue; |
| | | } |
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData); |
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData); |
| | | |
| | | //获取场景里面的全部目标(2019.11.05追加操作,有可能那个设备是由场景嵌套来的,所以它有可能不属于任何房间) |
| | | foreach (var data in tempUi.AdjustTargetList) |
| | | { |
| | | //设备 |
| | | if (data.Type == 0) |
| | | { |
| | | string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint); |
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true ) |
| | | { |
| | | //这个设备文件匹配得到 |
| | | dicDeviceFile.Remove(mainkey); |
| | | } |
| | | } |
| | | if (data.Type == 1) |
| | | { |
| | | //这个场景文件匹配得到 |
| | | dicSceneFile.Remove(data.ElseScenesId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //如果存在匹配不上的文件 |
| | | if (dicDeviceFile.Count != 0 || dicSceneFile.Count != 0) |
| | | { |
| | | //创建一个临时房间来存储 |
| | | var roomTemp = new Room(); |
| | | roomTemp.Id = "Other"; |
| | | roomTemp.FloorId = "Other"; |
| | | memberShardInfo.dicShardRoom[roomTemp.FileName] = roomTemp; |
| | | roomTemp.Name = Language.StringByID(R.MyInternationalizationString.uUnallocated); |
| | | //还原设备对象 |
| | | foreach (string deviceKeys in dicDeviceFile.Keys) |
| | | { |
| | | roomTemp.ListDevice.Add(deviceKeys); |
| | | } |
| | | //还原场景对象 |
| | | foreach (int intId in dicSceneFile.Keys) |
| | | { |
| | | roomTemp.ListSceneId.Add(intId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取设备文件名_____________________ |
| | | |
| | | /// <summary> |
| | | /// 获取设备文件名,不存在时,返回空字符串(仅限分享了的设备) |
| | | /// </summary> |
| | | /// <param name="deviceKeys">设备主键</param> |
| | | /// <param name="dicFileKeys">key:文件的主键 value:文件名称</param> |
| | | /// <returns></returns> |
| | | public string GetShardDeviceFileName(string deviceKeys) |
| | | private List<string> SetShardFileToLocation(Dictionary<string, string> dicFileKeys) |
| | | { |
| | | if (this.dicShardDeviceFile.ContainsKey(deviceKeys) == true) |
| | | if (dicFileKeys.Count == 0) |
| | | { |
| | | return this.dicShardDeviceFile[deviceKeys]; |
| | | return new List<string>(); |
| | | } |
| | | return string.Empty; |
| | | } |
| | | //创建文件夹 |
| | | string strDir = HdlFileNameResourse.DownLoadShardDirectory; |
| | | HdlFileLogic.Current.CreateDirectory(strDir, true); |
| | | |
| | | #endregion |
| | | int listMarkCount = dicFileKeys.Count; |
| | | |
| | | //----------------------------------分割线(上传新的分享)--------------------------------------------- |
| | | |
| | | #region ■ 执行上传新的分享___________________ |
| | | |
| | | /// <summary> |
| | | /// 执行上传新的分享 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据</param> |
| | | /// <param name="nowRoom">当前的房间对象</param> |
| | | /// <param name="listDevice">选择上传的设备</param> |
| | | /// <param name="listScene">选择上传的场景(不要获取它里面的绑定列表)</param> |
| | | /// <param name="BarMaxValue">进度条的最大值,如果不为-1,则内部不会自动弹出进度条</param> |
| | | /// <param name="listCheckFile">文件重复上传检测</param> |
| | | public bool DoUploadSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom, |
| | | List<CommonDevice> listDevice, List<Common.SceneUI> listScene, int BarMaxValue = -1, HashSet<string> listCheckFile = null) |
| | | { |
| | | if (listDevice.Count == 0 && listScene.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | var listCheck = new HashSet<string>(); |
| | | |
| | | //获取场景里面嵌套的子设备和子场景 |
| | | var listChirdDevice = new List<CommonDevice>(); |
| | | var listChirdScene = new List<Common.SceneUI>(); |
| | | foreach (var SceneTemp in listScene) |
| | | { |
| | | //从缓存获取场景的执行目标 |
| | | this.GetSceneDeviceList(SceneTemp, listCheck, listChirdScene, listChirdDevice); |
| | | } |
| | | |
| | | //这个也是备份 |
| | | int BackgroundImageType = 0; |
| | | string BackgroundImage = string.Empty; |
| | | if (memberShardInfo.dicShardRoom.ContainsKey(nowRoom.FileName) == true) |
| | | { |
| | | BackgroundImageType = memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImageType; |
| | | BackgroundImage = memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImage; |
| | | } |
| | | //防止出现错误,暂时保存两个列表(虽然没那么麻烦,不过既然已经这样写了就这样了) |
| | | var dicBackDevice = new Dictionary<string, List<string>>(); |
| | | var dicBackScene = new Dictionary<string, List<int>>(); |
| | | //临时备份房间设备列表 |
| | | this.BackupRoomDevicelistTemporary(memberShardInfo, dicBackDevice, dicBackScene); |
| | | |
| | | //获取上传的文件,然后将文件复制到指定文件夹 |
| | | var listDelPic = new List<string>(); |
| | | var listFile = this.GetUploadListFile(memberShardInfo, nowRoom, listDevice, listScene, listChirdDevice, listChirdScene, listDelPic); |
| | | List<string> listFile = new List<string>(); |
| | | |
| | | //不允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = false; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = false; |
| | | |
| | | if (BarMaxValue == -1) |
| | | //计数 |
| | | int nowCount = 0; |
| | | foreach (var fileKey in dicFileKeys.Keys) |
| | | { |
| | | //打开进度条 |
| | | ProgressBar.Show(); |
| | | //设置最大值 |
| | | ProgressBar.SetMaxValue(listFile.Count); |
| | | } |
| | | else |
| | | { |
| | | //设置最大值 |
| | | ProgressBar.SetMaxValue(BarMaxValue); |
| | | } |
| | | |
| | | //上传分享 |
| | | var result = this.DoUploadShardContent(memberShardInfo, listFile, listCheckFile); |
| | | if (result == true) |
| | | { |
| | | //删除指定自定义图片 |
| | | result = this.DoDeleteSharedContent(memberShardInfo, listDelPic); |
| | | } |
| | | if (BarMaxValue == -1) |
| | | { |
| | | //关闭进度条 |
| | | ProgressBar.Close(); |
| | | nowCount++; |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = fileKey }; |
| | | var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/app/home/share/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (result == null) |
| | | { |
| | | //允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = true; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = true; |
| | | return null; |
| | | } |
| | | string shareName = dicFileKeys[fileKey]; |
| | | //文件名字 |
| | | listFile.Add(shareName); |
| | | //保存到指定文件夹下 |
| | | HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(strDir, shareName), result); |
| | | //设置进度值 |
| | | ProgressFormBar.Current.SetValue(nowCount, listMarkCount); |
| | | } |
| | | |
| | | //允许按系统的返回键 |
| | | Config.Instance.BackKeyCanClick = true; |
| | | HdlUserCenterResourse.AccountOption.AppCanSignout = true; |
| | | |
| | | if (result == false) |
| | | return listFile; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region ■ 初始化成员分享数据_________________ |
| | | |
| | | /// <summary> |
| | | /// 初始化成员共享列表然后保存到本地 |
| | | /// </summary> |
| | | /// <param name="i_ChildAccountId">成员ID</param> |
| | | /// <returns></returns> |
| | | public bool InitMemberShardContentListAndSetToLocation(string i_ChildAccountId) |
| | | { |
| | | if (DicDevices != null) |
| | | { |
| | | //恢复原数据 |
| | | if (memberShardInfo.TempRoom == null) |
| | | { |
| | | memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImageType = BackgroundImageType; |
| | | memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImage = BackgroundImage; |
| | | } |
| | | this.RecoverRoomDevicelistTemporary(memberShardInfo, dicBackDevice, dicBackScene, listFile); |
| | | //已经获取了,则不再获取 |
| | | return true; |
| | | } |
| | | else |
| | | |
| | | //正在获取分享数据 |
| | | ProgressFormBar.Current.Start(); |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting)); |
| | | |
| | | //从云端获取分享的文件列表 |
| | | var listData = this.GetShardFileListFromDb(i_ChildAccountId); |
| | | if (listData == null) |
| | | { |
| | | //覆盖数据 |
| | | if (memberShardInfo.TempRoom != null) |
| | | { |
| | | memberShardInfo.dicShardRoom[nowRoom.FileName] = memberShardInfo.TempRoom; |
| | | } |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | return false; |
| | | } |
| | | memberShardInfo.TempRoom = null; |
| | | |
| | | //分享的压缩文件的主键 |
| | | string shardBinKey = string.Empty; |
| | | foreach (var data in listData) |
| | | { |
| | | //如果是这个压缩文件 |
| | | if (data.FileName == SHARED_BIN_FILE) |
| | | { |
| | | shardBinKey = data.Id; |
| | | } |
| | | //记录起它们的主键 |
| | | this.DicShardKeys[data.FileName] = data.Id; |
| | | } |
| | | |
| | | //下载压缩的bin文件,然后进行解析,其他文件不用理会 |
| | | bool result = this.DownloadBinFileAndAdjust(shardBinKey); |
| | | //关闭进度条 |
| | | ProgressFormBar.Current.Close(); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取上传的文件名 |
| | | /// 下载压缩的bin文件,然后进行解析 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据</param> |
| | | /// <param name="nowRoom">需要上传到云端的房间对象(注意,这个房间是主人的房间对象,而不是虚拟的)</param> |
| | | /// <param name="listDevice">分享的设备列表(注意,这个东西是主人的)</param> |
| | | /// <param name="listScene">分享的场景列表(注意,这个东西是主人的)</param> |
| | | /// <param name="listChirdDevice">场景里面递归获取的设备</param> |
| | | /// <param name="listChirdScene">场景里面递归获取的场景</param> |
| | | /// <param name="listDelPic">需要删除的图片</param> |
| | | /// <param name="i_binFileId">压缩文件的主键</param> |
| | | /// <returns></returns> |
| | | private List<string> GetUploadListFile(MemberShardInfoData memberShardInfo, Common.Room nowRoom, List<CommonDevice> listDevice, List<Common.SceneUI> listScene, |
| | | List<CommonDevice> listChirdDevice, List<Common.SceneUI> listChirdScene, List<string> listDelPic) |
| | | private bool DownloadBinFileAndAdjust(string i_binFileId) |
| | | { |
| | | var listFile = new List<string>(); |
| | | |
| | | Common.Room roomTemp = null; |
| | | if (memberShardInfo.dicShardRoom.ContainsKey(nowRoom.FileName) == false) |
| | | if (i_binFileId == string.Empty) |
| | | { |
| | | //克隆一个对象 |
| | | roomTemp = HdlRoomLogic.Current.CloneRoomClass(nowRoom); |
| | | memberShardInfo.TempRoom = roomTemp; |
| | | //新分享的房间,如果图片是自定义的,并且这个图片是存在的,则上传图片 |
| | | if (roomTemp.BackgroundImageType != 0 && Common.Global.IsExistsByHomeId(roomTemp.BackgroundImage) == true) |
| | | { |
| | | //自定义的图片,它存在于本地,但是它是全路径 |
| | | listFile.Add(roomTemp.BackgroundImage); |
| | | this.AddShardFile(roomTemp.BackgroundImage); |
| | | } |
| | | //不要忘记要初始化这个东西 |
| | | this.DicDevices = new Dictionary<string, CommonDevice>(); |
| | | return true; |
| | | } |
| | | else |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = i_binFileId }; |
| | | var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/app/home/share/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (result == null) |
| | | { |
| | | roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName]; |
| | | //如果云端分享的房间的图片和主人的不一样的时候 |
| | | if (roomTemp.BackgroundImage != nowRoom.BackgroundImage) |
| | | { |
| | | if (roomTemp.BackgroundImageType != 0) |
| | | { |
| | | //删除自定义图片 |
| | | listDelPic.Add(roomTemp.BackgroundImage); |
| | | } |
| | | if (nowRoom.BackgroundImageType != 0 && Common.Global.IsExistsByHomeId(nowRoom.BackgroundImage) == true) |
| | | { |
| | | //自定义的图片,它存在于本地,但是它是全路径 |
| | | listFile.Add(nowRoom.BackgroundImage); |
| | | this.AddShardFile(nowRoom.BackgroundImage); |
| | | } |
| | | //变更图片设置 |
| | | roomTemp.BackgroundImageType = nowRoom.BackgroundImageType; |
| | | roomTemp.BackgroundImage = nowRoom.BackgroundImage; |
| | | } |
| | | return false; |
| | | } |
| | | //不要忘记要初始化这个东西 |
| | | this.DicDevices = new Dictionary<string, CommonDevice>(); |
| | | |
| | | foreach (var device in listDevice) |
| | | { |
| | | //设备 |
| | | listFile.Add(device.FilePath); |
| | | this.AddShardFile(device.FilePath); |
| | | //直接飙到100% |
| | | ProgressFormBar.Current.SetValue(1); |
| | | |
| | | //加点缓存 |
| | | string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | this.dicShardDeviceFile[mainKeys] = device.FilePath; |
| | | var fileContent = Encoding.UTF8.GetString(result); |
| | | //解析压缩的bin文件 |
| | | this.AdjustBinFileContent(fileContent); |
| | | |
| | | if (roomTemp.ListDevice.Contains(mainKeys) == false) |
| | | { |
| | | roomTemp.ListDevice.Add(mainKeys); |
| | | } |
| | | } |
| | | //递归获取的设备不需要加入到房间 |
| | | foreach (var device in listChirdDevice) |
| | | { |
| | | //设备 |
| | | listFile.Add(device.FilePath); |
| | | this.AddShardFile(device.FilePath); |
| | | |
| | | //加点缓存 |
| | | this.dicShardDeviceFile[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device.FilePath; |
| | | } |
| | | |
| | | //场景 |
| | | foreach (var secene in listScene) |
| | | { |
| | | if (secene.IconPathType != 0 && Common.Global.IsExistsByHomeId(secene.IconPath) == true) |
| | | { |
| | | //自定义的图片,它存在于本地 |
| | | listFile.Add(secene.IconPath); |
| | | this.AddShardFile(secene.IconPath); |
| | | } |
| | | |
| | | listFile.Add(secene.FileName); |
| | | this.AddShardFile(secene); |
| | | |
| | | if (roomTemp.ListSceneId.Contains(secene.Id) == false) |
| | | { |
| | | roomTemp.ListSceneId.Add(secene.Id); |
| | | } |
| | | } |
| | | //递归获取的场景不需要加入到房间 |
| | | foreach (var secene in listChirdScene) |
| | | { |
| | | listFile.Add(secene.FileName); |
| | | this.AddShardFile(secene); |
| | | } |
| | | //房间文件也给过去 |
| | | listFile.Add(roomTemp.FileName); |
| | | this.AddShardFile(roomTemp); |
| | | |
| | | //反正楼层文件很小,一起给过去吧 |
| | | if (roomTemp.FloorId != string.Empty) |
| | | { |
| | | memberShardInfo.dicShardFloor[roomTemp.FloorId] = HdlResidenceLogic.Current.GetFloorNameById(roomTemp.FloorId); |
| | | } |
| | | this.AddShardFile(memberShardInfo.dicShardFloor); |
| | | listFile.Add(HdlFileNameResourse.ShardFloorFile); |
| | | |
| | | return listFile; |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取场景的目标设备列表(这个不能从分享数据中获取) |
| | | /// 解析压缩的bin文件 |
| | | /// </summary> |
| | | /// <param name="i_content"></param> |
| | | private void AdjustBinFileContent(string i_content) |
| | | { |
| | | var deviceType = string.Empty; |
| | | |
| | | //根据换行符切分数据文本 |
| | | string[] arryData = i_content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); |
| | | string strContentData = string.Empty; |
| | | foreach (string strData in arryData) |
| | | { |
| | | if (strData == "#START#") |
| | | { |
| | | //无附加数据的【数据标题】 |
| | | continue; |
| | | } |
| | | if (strData.StartsWith("#DeviceInfo START#") == true) |
| | | { |
| | | //附加数据:设备对象类型 |
| | | deviceType = strData.Substring(18); |
| | | continue; |
| | | } |
| | | //执行数据处理 |
| | | try |
| | | { |
| | | //场景对象 |
| | | if (strData == "#Scene END#") |
| | | { |
| | | var scene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(strContentData); |
| | | this.DicScenes[scene.Id] = scene; |
| | | |
| | | strContentData = string.Empty; |
| | | continue; |
| | | } |
| | | //楼层对象 |
| | | else if (strData == "#FloorInfo END#") |
| | | { |
| | | this.DicFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strContentData); |
| | | |
| | | strContentData = string.Empty; |
| | | continue; |
| | | } |
| | | //房间对象 |
| | | else if (strData == "#RoomInfo END#") |
| | | { |
| | | var room = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(strContentData); |
| | | this.DicRooms[room.Id] = room; |
| | | |
| | | strContentData = string.Empty; |
| | | continue; |
| | | } |
| | | //设备对象 |
| | | else if (strData == "#DeviceInfo END#") |
| | | { |
| | | //反序列化设备 |
| | | CommonDevice device = null; |
| | | if (HdlCheckLogic.Current.CheckIsNumber(deviceType) == true) |
| | | { |
| | | //数值型为新数据,直接转换 |
| | | device = CommonDevice.CommonDeviceByByteString(Convert.ToInt32(deviceType), strContentData); |
| | | } |
| | | else |
| | | { |
| | | //字符串型为旧数据,需要特殊处理 |
| | | var myType = (DeviceType)Enum.Parse(typeof(DeviceType), deviceType); |
| | | device = CommonDevice.CommonDeviceByByteString((int)myType, strContentData); |
| | | } |
| | | if (device != null) |
| | | { |
| | | this.DicDevices[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device; |
| | | } |
| | | strContentData = string.Empty; |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | strContentData += strData; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | HdlLogLogic.Current.WriteLog(ex, "分享bin文件出问题\r\n" + strContentData); |
| | | strContentData = string.Empty; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region ■ 上传分享内容_______________________ |
| | | |
| | | /// <summary> |
| | | /// 执行上传新的分享(设备和场景仅限同一个房间) |
| | | /// </summary> |
| | | /// <param name="i_ChildAccountId">成员的ID</param> |
| | | /// <param name="i_nowRoom">指定的房间</param> |
| | | /// <param name="i_listDevice">选择上传的设备(仅限一个房间)</param> |
| | | /// <param name="i_listScene">选择上传的场景(仅限一个房间,不要获取它里面的绑定列表)</param> |
| | | public bool UploadSharedContent(string i_ChildAccountId, Room i_nowRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene) |
| | | { |
| | | if (i_listDevice.Count == 0 && i_listScene.Count == 0) |
| | | { |
| | | return true; |
| | | } |
| | | //打开进度条 |
| | | ProgressBar.Show(); |
| | | |
| | | var listCheck = new HashSet<string>(); |
| | | |
| | | //获取场景里面嵌套的子设备和子场景(这几个东西不加到房间) |
| | | var listChirdDevice = new List<CommonDevice>(); |
| | | var listChirdScene = new List<SceneUI>(); |
| | | foreach (var SceneTemp in i_listScene) |
| | | { |
| | | //从缓存获取场景的执行目标 |
| | | this.GetSceneAdjustTargetListFromLocal(SceneTemp, listCheck, listChirdScene, listChirdDevice); |
| | | } |
| | | //克隆一个房间出来 |
| | | var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(i_nowRoom); |
| | | if (this.DicRooms.ContainsKey(cloneRoom.Id) == true) |
| | | { |
| | | //把原来的的东西也复制过来 |
| | | cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice); |
| | | cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac); |
| | | cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId); |
| | | } |
| | | else |
| | | { |
| | | //这里有点特殊,如果不存在的话,把真实设备的区域丢过去,因为只是主键而已 |
| | | cloneRoom.ListDeviceMac.AddRange(i_nowRoom.ListDeviceMac); |
| | | } |
| | | //然后把场景和设备丢到这个克隆的对象里面去 |
| | | foreach (var device in i_listDevice) |
| | | { |
| | | string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | if (cloneRoom.ListDevice.Contains(mainKey) == false) |
| | | { |
| | | //丢设备过去 |
| | | cloneRoom.ListDevice.Add(mainKey); |
| | | } |
| | | } |
| | | foreach (var secne in i_listScene) |
| | | { |
| | | if (cloneRoom.ListSceneId.Contains(secne.Id) == false) |
| | | { |
| | | //丢场景过去 |
| | | cloneRoom.ListSceneId.Add(secne.Id); |
| | | } |
| | | } |
| | | //获取需要上传的图片 |
| | | var listUploadPic = this.GetUploadPictrueFile(new List<Room> { cloneRoom }, i_listScene, listChirdScene); |
| | | //生成分享Bin文件内容 |
| | | var binfFileContent = this.CreatShardBinContentOnAdd(new List<Room> { cloneRoom }, i_listDevice, i_listScene, listChirdDevice, listChirdScene); |
| | | |
| | | //设置最大值 |
| | | ProgressBar.SetMaxValue(listUploadPic.Count + 1); |
| | | |
| | | //上传bin文件 |
| | | var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent)); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | binfFileContent = null; |
| | | |
| | | //上传图片 |
| | | foreach (var fileName in listUploadPic) |
| | | { |
| | | var byteData = HdlFileLogic.Current.ReadFileByteContent(Path.Combine(Config.Instance.FullPath, fileName)); |
| | | if (byteData != null) |
| | | { |
| | | fileKey = this.DoUploadShardContent(i_ChildAccountId, fileName, byteData); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | } |
| | | //如果全部成功了的话,覆盖缓存 |
| | | this.DicDevices.Clear(); |
| | | this.DicScenes.Clear(); |
| | | this.DicRooms.Clear(); |
| | | this.DicFloor.Clear(); |
| | | this.AdjustBinFileContent(binfFileContent); |
| | | |
| | | //删除已经不再分享的图片 |
| | | this.DeleteNotShardPictrue(); |
| | | |
| | | ProgressBar.Close(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行上传新的分享房间(整个房间分享) |
| | | /// </summary> |
| | | /// <param name="i_ChildAccountId">成员的ID</param> |
| | | /// <param name="i_listRoom">需要分享的房间</param> |
| | | public bool UploadSharedRoom(string i_ChildAccountId, List<Room> i_listRoom) |
| | | { |
| | | //打开进度条 |
| | | ProgressBar.Show(); |
| | | |
| | | //让设备和场景不重复的东西 |
| | | var listCheck = new HashSet<string>(); |
| | | //克隆房间 |
| | | var listCloneRoom = new List<Room>(); |
| | | //添加的设备 |
| | | var listDevice = new List<CommonDevice>(); |
| | | //添加的场景 |
| | | var listScene = new List<SceneUI>(); |
| | | |
| | | foreach (var room in i_listRoom) |
| | | { |
| | | //克隆一个房间出来 |
| | | var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(room); |
| | | if (this.DicRooms.ContainsKey(cloneRoom.Id) == true) |
| | | { |
| | | //把原来的的东西也复制过来 |
| | | cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice); |
| | | cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac); |
| | | cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId); |
| | | } |
| | | else |
| | | { |
| | | //这里有点特殊,如果不存在的话,把真实设备的区域丢过去,因为只是主键而已 |
| | | cloneRoom.ListDeviceMac.AddRange(room.ListDeviceMac); |
| | | } |
| | | listCloneRoom.Add(cloneRoom); |
| | | |
| | | //获取设备对象 |
| | | foreach (var mainkey in cloneRoom.ListDevice) |
| | | { |
| | | var device = HdlDeviceCommonLogic.Current.GetDevice(mainkey); |
| | | if (device != null) |
| | | { |
| | | listDevice.Add(device); |
| | | } |
| | | listCheck.Add(mainkey); |
| | | } |
| | | //获取场景对象 |
| | | foreach (var sceneId in cloneRoom.ListSceneId) |
| | | { |
| | | var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId); |
| | | if (scene != null) |
| | | { |
| | | listScene.Add(scene); |
| | | } |
| | | listCheck.Add(sceneId.ToString()); |
| | | //从缓存获取场景的执行目标 |
| | | this.GetSceneAdjustTargetListFromLocal(scene, listCheck, listScene, listDevice); |
| | | } |
| | | } |
| | | |
| | | //获取需要上传的图片 |
| | | var listUploadPic = this.GetUploadPictrueFile(listCloneRoom, listScene, new List<SceneUI>()); |
| | | //生成分享Bin文件内容 |
| | | var binfFileContent = this.CreatShardBinContentOnAdd(listCloneRoom, listDevice, listScene, new List<CommonDevice>(), new List<SceneUI>()); |
| | | |
| | | //设置最大值 |
| | | ProgressBar.SetMaxValue(listUploadPic.Count + 1); |
| | | |
| | | //上传bin文件 |
| | | var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent)); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | binfFileContent = null; |
| | | |
| | | //上传图片 |
| | | foreach (var fileName in listUploadPic) |
| | | { |
| | | var byteData = HdlFileLogic.Current.ReadFileByteContent(Path.Combine(Config.Instance.FullPath, fileName)); |
| | | if (byteData != null) |
| | | { |
| | | fileKey = this.DoUploadShardContent(i_ChildAccountId, fileName, byteData); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | } |
| | | //如果全部成功了的话,覆盖缓存 |
| | | this.DicDevices.Clear(); |
| | | this.DicScenes.Clear(); |
| | | this.DicRooms.Clear(); |
| | | this.DicFloor.Clear(); |
| | | this.AdjustBinFileContent(binfFileContent); |
| | | |
| | | //删除已经不再分享的图片 |
| | | this.DeleteNotShardPictrue(); |
| | | |
| | | ProgressBar.Close(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除已经不再分享的图片(不用管返回值,即使失败也没事) |
| | | /// </summary> |
| | | private void DeleteNotShardPictrue() |
| | | { |
| | | var listPictrue = new List<string>(); |
| | | foreach (var room in this.DicRooms.Values) |
| | | { |
| | | if (room.BackgroundImageType != 0) |
| | | { |
| | | //房间图片 |
| | | listPictrue.Add(room.BackgroundImage); |
| | | } |
| | | } |
| | | foreach (var scene in this.DicScenes.Values) |
| | | { |
| | | if (scene.IconPathType != 0) |
| | | { |
| | | //场景图片 |
| | | listPictrue.Add(scene.IconPath); |
| | | } |
| | | } |
| | | var listDeleteFile = new List<string>(); |
| | | foreach (var fileName in this.DicShardKeys.Keys) |
| | | { |
| | | //如果是房间或者场景的图片 |
| | | if (fileName.StartsWith("RoomIcon_") == true || fileName.StartsWith("SceneIcon_") == true) |
| | | { |
| | | if (listPictrue.Contains(fileName) == false) |
| | | { |
| | | //这个图片变更了,需要删除掉 |
| | | listDeleteFile.Add(fileName); |
| | | } |
| | | } |
| | | } |
| | | //删除图片 |
| | | this.DoDeleteSharedContent(listDeleteFile, ShowNetCodeMode.No); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传分享内容(返回主键) |
| | | /// </summary> |
| | | /// <param name="i_childAccountId">子账号的主键</param> |
| | | /// <param name="i_fileName">文件名字</param> |
| | | /// <param name="i_content">文件内容</param> |
| | | /// <returns></returns> |
| | | private string DoUploadShardContent(string i_childAccountId, string i_fileName, byte[] i_content) |
| | | { |
| | | var dicQuery = new Dictionary<string, object>(); |
| | | dicQuery["homeId"] = Config.Instance.Home.Id; |
| | | dicQuery["childAccountId"] = i_childAccountId; |
| | | dicQuery["fileName"] = i_fileName; |
| | | |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/share/add", RestSharp.Method.POST, i_content, dicQuery, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | { |
| | | return null; |
| | | } |
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveShardInfoResult>(result.Data.ToString()); |
| | | return info.Id; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 上传分享内容辅助方法_______________ |
| | | |
| | | /// <summary> |
| | | /// 从本地获取场景里面的执行目标列表 |
| | | /// </summary> |
| | | /// <param name="scene">场景</param> |
| | | /// <param name="listCheck">重复检测用</param> |
| | | /// <param name="listSceneUI">添加分享的场景列表</param> |
| | | /// <param name="listDevice">添加分享的设备列表</param> |
| | | /// <returns></returns> |
| | | public void GetSceneDeviceList(Common.SceneUI scene, HashSet<string> listCheck, List<Common.SceneUI> listSceneUI, List<CommonDevice> listDevice) |
| | | private void GetSceneAdjustTargetListFromLocal(SceneUI scene, HashSet<string> listCheck, List<SceneUI> listSceneUI, List<CommonDevice> listDevice) |
| | | { |
| | | foreach (var data in scene.AdjustTargetList) |
| | | { |
| | |
| | | if (sceneUi != null) |
| | | { |
| | | listSceneUI.Add(sceneUi); |
| | | //递归获取执行目标 |
| | | this.GetSceneAdjustTargetListFromLocal(sceneUi, listCheck, listSceneUI, listDevice); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取需要上传的图片名字 |
| | | /// </summary> |
| | | /// <param name="i_listRoom">房间对象</param> |
| | | /// <param name="i_listScene">场景对象</param> |
| | | /// <param name="i_listChirdScene">场景对象</param> |
| | | /// <returns></returns> |
| | | private List<string> GetUploadPictrueFile(List<Room> i_listRoom, List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene) |
| | | { |
| | | var listPic = new List<string>(); |
| | | foreach (var room in i_listRoom) |
| | | { |
| | | if (room.BackgroundImageType != 0 && this.DicShardKeys.ContainsKey(room.BackgroundImage) == false) |
| | | { |
| | | //自定义图片 |
| | | listPic.Add(room.BackgroundImage); |
| | | } |
| | | } |
| | | foreach (var scene in i_listScene) |
| | | { |
| | | if (scene.IconPathType != 0 && this.DicShardKeys.ContainsKey(scene.IconPath) == false) |
| | | { |
| | | //自定义图片 |
| | | listPic.Add(scene.IconPath); |
| | | } |
| | | } |
| | | foreach (var scene in i_listChirdScene) |
| | | { |
| | | if (scene.IconPathType != 0 && this.DicShardKeys.ContainsKey(scene.IconPath) == false) |
| | | { |
| | | //自定义图片 |
| | | listPic.Add(scene.IconPath); |
| | | } |
| | | } |
| | | return listPic; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 上传新的分享_______________________ |
| | | |
| | | #region ■ 删除分享内容_______________________ |
| | | |
| | | /// <summary> |
| | | /// 上传分享(返回云端分享文件的主键:DistributedMark) |
| | | /// 移除指定分享内容(设备和场景仅限同一个房间) |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据</param> |
| | | /// <param name="listFile">上传的文件名</param> |
| | | /// <param name="listCheckFile">重复文件上传检测</param> |
| | | /// <param name="i_ChildAccountId">成员ID</param> |
| | | /// <param name="i_nowRoom">指定的房间</param> |
| | | /// <param name="i_listDevice">选择上传的设备(仅限一个房间)</param> |
| | | /// <param name="i_listScene">选择上传的场景(仅限一个房间,不要获取它里面的绑定列表)</param> |
| | | /// <returns></returns> |
| | | private bool DoUploadShardContent(MemberShardInfoData memberShardInfo, List<string> listFile, HashSet<string> listCheckFile) |
| | | public bool DeleteSharedContent(string i_ChildAccountId, Room i_nowRoom, |
| | | List<CommonDevice> i_listDevice, List<SceneUI> i_listScene) |
| | | { |
| | | var dicKeys = new Dictionary<string, string>(); |
| | | for (int i = 0; i < listFile.Count; i++) |
| | | //克隆一个房间出来 |
| | | var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(i_nowRoom); |
| | | if (this.DicRooms.ContainsKey(cloneRoom.Id) == true) |
| | | { |
| | | string fileName = listFile[i]; |
| | | if (listCheckFile != null) |
| | | { |
| | | if (listCheckFile.Contains(fileName) == true) |
| | | { |
| | | //重复文件不再上传 |
| | | continue; |
| | | } |
| | | listCheckFile.Add(fileName); |
| | | } |
| | | var shareByte = this.GetShardFileContent(fileName); |
| | | //上传文件 |
| | | var shardId = this.DoUploadShardContent(memberShardInfo.ChildAccountId, fileName, shareByte); |
| | | if (shardId == null) |
| | | { |
| | | return false; |
| | | } |
| | | //收集主键 |
| | | dicKeys[fileName] = shardId; |
| | | //设置进度值 |
| | | ProgressBar.SetValue(1); |
| | | } |
| | | //如果没有错误,则添加临时缓存 |
| | | foreach (var keys in dicKeys.Keys) |
| | | { |
| | | memberShardInfo.dicAllShardKeys[keys] = dicKeys[keys]; |
| | | //把原来的的东西也复制过来 |
| | | cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice); |
| | | cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac); |
| | | cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传分享内容(返回主键) |
| | | /// </summary> |
| | | /// <param name="i_childAccountId">子账号的主键</param> |
| | | /// <param name="i_fileName">文件名字</param> |
| | | /// <param name="i_content">文件内容</param> |
| | | /// <returns></returns> |
| | | private string DoUploadShardContent(string i_childAccountId, string i_fileName, byte[] i_content) |
| | | { |
| | | var dicQuery = new Dictionary<string, object>(); |
| | | dicQuery["homeId"] = Config.Instance.Home.Id; |
| | | dicQuery["childAccountId"] = i_childAccountId; |
| | | dicQuery["fileName"] = i_fileName; |
| | | |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/share/add", RestSharp.Method.POST, i_content, dicQuery, null, CheckMode.A账号权限, true, 10); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | { |
| | | return null; |
| | | } |
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveShardInfoResult>(result.Data.ToString()); |
| | | return info.Id; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 临时备份房间设备列表_______________ |
| | | |
| | | /// <summary> |
| | | /// 临时备份房间设备列表 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据</param> |
| | | /// <param name="dicBackDevice">空的设备备份列表</param> |
| | | /// <param name="dicBackScene">空的场景备份列表</param> |
| | | private void BackupRoomDevicelistTemporary(MemberShardInfoData memberShardInfo, Dictionary<string, List<string>> dicBackDevice, |
| | | Dictionary<string, List<int>> dicBackScene) |
| | | { |
| | | foreach (var roomKeys in memberShardInfo.dicShardRoom.Keys) |
| | | { |
| | | dicBackDevice[roomKeys] = new List<string>(); |
| | | dicBackScene[roomKeys] = new List<int>(); |
| | | |
| | | dicBackDevice[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].ListDevice); |
| | | dicBackScene[roomKeys].AddRange(memberShardInfo.dicShardRoom[roomKeys].ListSceneId); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 还原临时备份的房间设备列表 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享数据</param> |
| | | /// <param name="dicBackDevice">临时备份的设备备份列表</param> |
| | | /// <param name="dicBackScene">临时备份的场景备份列表</param> |
| | | /// <param name="listFile">上传的文件名</param> |
| | | private void RecoverRoomDevicelistTemporary(MemberShardInfoData memberShardInfo, Dictionary<string, List<string>> dicBackDevice, |
| | | Dictionary<string, List<int>> dicBackScene, List<string> listFile) |
| | | { |
| | | foreach (string fileName in listFile) |
| | | { |
| | | //生成的文件全部删除,房间文件的话,下面会重新生成 |
| | | this.DeleteShardFile(fileName); |
| | | } |
| | | |
| | | foreach (var roomKeys in memberShardInfo.dicShardRoom.Keys) |
| | | { |
| | | if (dicBackDevice.ContainsKey(roomKeys) == false) |
| | | { |
| | | continue; |
| | | } |
| | | memberShardInfo.dicShardRoom[roomKeys].ListDevice.Clear(); |
| | | memberShardInfo.dicShardRoom[roomKeys].ListDevice.AddRange(dicBackDevice[roomKeys]); |
| | | |
| | | memberShardInfo.dicShardRoom[roomKeys].ListSceneId.Clear(); |
| | | memberShardInfo.dicShardRoom[roomKeys].ListSceneId.AddRange(dicBackScene[roomKeys]); |
| | | |
| | | //覆盖房间文件 |
| | | this.AddShardFile(memberShardInfo.dicShardRoom[roomKeys]); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | //----------------------------------分割线(删除指定分享)--------------------------------------------- |
| | | |
| | | #region ■ 移除指定分享内容___________________ |
| | | |
| | | /// <summary> |
| | | /// 移除指定分享内容 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享信息</param> |
| | | /// <param name="nowRoom">当前房间</param> |
| | | /// <param name="listDevice">要取消的设备</param> |
| | | /// <param name="listSceneUI">要取消的场景</param> |
| | | /// <returns></returns> |
| | | public bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom, |
| | | List<CommonDevice> listDevice, List<SceneUI> listSceneUI) |
| | | { |
| | | var roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName]; |
| | | //防止出错,先备份列表 |
| | | var listBackDevice = new List<string>(); |
| | | listBackDevice.AddRange(roomTemp.ListDevice); |
| | | var listBackScene = new List<int>(); |
| | | listBackScene.AddRange(roomTemp.ListSceneId); |
| | | |
| | | var listMark = new List<string>(); |
| | | //要删除的文件名字 |
| | | var listDeleteFile = new List<string>(); |
| | | |
| | | //除了要删除的目标外,还分享的数据 |
| | | var listHadShardKeys = this.GetAllShardedKeysFromDictionary(memberShardInfo, nowRoom, listDevice, listSceneUI); |
| | | |
| | | //先弄设备 |
| | | foreach (var device in listDevice) |
| | | { |
| | | string deviceFileName = device.FilePath; |
| | | string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | //移除路径列表 |
| | | roomTemp.ListDevice.Remove(mainKeys); |
| | | if (listHadShardKeys.Contains(mainKeys) == true) |
| | | { |
| | | //其他场景分享有这个设备,所以不删除这个设备的根源文件,只是把房间的设备列表路径移除 |
| | | continue; |
| | | } |
| | | |
| | | //设备主键 |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(deviceFileName) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[deviceFileName]); |
| | | } |
| | | listDeleteFile.Add(device.FilePath); |
| | | } |
| | | //再弄场景 |
| | | foreach (var sceneUI in listSceneUI) |
| | | { |
| | | //移除缓存 |
| | | roomTemp.ListSceneId.Remove(sceneUI.Id); |
| | | |
| | | //其他场景还嵌套着这个场景,所以不删除这个场景的根源文件,只是把房间的场景列表路径移除 |
| | | //但是它绑定的设备目标要删除 |
| | | if (listHadShardKeys.Contains(sceneUI.Id.ToString()) == true) |
| | | { |
| | | continue; |
| | | } |
| | | //获取要删除的分享主键 |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(sceneUI.FileName) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[sceneUI.FileName]); |
| | | } |
| | | listDeleteFile.Add(sceneUI.FileName); |
| | | |
| | | //删除自定义图片,它存在于本地,但是它是全路径 |
| | | if (sceneUI.IconPathType != 0) |
| | | { |
| | | string[] Arry = sceneUI.IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); |
| | | string sceneFile = Arry[Arry.Length - 1]; |
| | | listDeleteFile.Add(sceneFile); |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(sceneFile) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[sceneFile]); |
| | | } |
| | | } |
| | | |
| | | //执行删除嵌套的设备 |
| | | 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 (listHadShardKeys.Contains(myKeys) == true) |
| | | { |
| | | continue; |
| | | } |
| | | //获取要删除的分享主键 |
| | | string fileName = dicDeviceKeys[myKeys]; |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[fileName]); |
| | | } |
| | | listDeleteFile.Add(fileName); |
| | | } |
| | | //场景的 |
| | | foreach (var seceUi in listBindScene) |
| | | { |
| | | if (seceUi.IconPathType != 0) |
| | | { |
| | | //删除自定义场景图片,它存在于本地,但是它是全路径 |
| | | string[] Arry = seceUi.IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); |
| | | string sceneFile = Arry[Arry.Length - 1]; |
| | | listDeleteFile.Add(sceneFile); |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(sceneFile) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[sceneFile]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //如果这个房间的分享设备和场景全部删除的话,把分享房间文件也一起删除 |
| | | if (roomTemp.ListDevice.Count == 0 && roomTemp.ListSceneId.Count == 0) |
| | | { |
| | | //房间删除 |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(nowRoom.FileName) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[nowRoom.FileName]); |
| | | } |
| | | listDeleteFile.Add(nowRoom.FileName); |
| | | |
| | | if (nowRoom.BackgroundImageType != 0) |
| | | { |
| | | //删除自定义房间图片,它存在于本地,但是它是全路径 |
| | | string[] Arry = nowRoom.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); |
| | | string roomFile = Arry[Arry.Length - 1]; |
| | | listDeleteFile.Add(roomFile); |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(roomFile) == true) |
| | | { |
| | | listMark.Add(memberShardInfo.dicAllShardKeys[roomFile]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //执行移除分享数据 |
| | | var result = this.DoDeleteSharedContent(memberShardInfo, listMark, listDeleteFile); |
| | | //同步房间文件 |
| | | if (result == true && listDeleteFile.Contains(roomTemp.FileName) == false) |
| | | { |
| | | //执行上传房间对象 |
| | | result = this.DoUploadRoomObject(memberShardInfo, roomTemp); |
| | | } |
| | | //同步楼层数据 |
| | | if (result == true && listDeleteFile.Contains(roomTemp.FileName) == true) |
| | | { |
| | | int floorCount = 0; |
| | | foreach (var myRoom in memberShardInfo.dicShardRoom.Values) |
| | | { |
| | | //2020.03.24追加:不能是自身房间 |
| | | if (myRoom.FloorId == roomTemp.FloorId && myRoom.Id != roomTemp.Id) |
| | | { |
| | | floorCount++; |
| | | } |
| | | } |
| | | if (floorCount == 0) |
| | | { |
| | | //如果该楼层已经删完房间了,则更新楼层 |
| | | memberShardInfo.dicShardFloor.Remove(roomTemp.FloorId); |
| | | //执行上传对象 |
| | | result = this.DoUploadFloorObject(memberShardInfo); |
| | | } |
| | | } |
| | | |
| | | if (result == false) |
| | | { |
| | | //恢复 |
| | | roomTemp.ListDevice.Clear(); |
| | | roomTemp.ListDevice.AddRange(listBackDevice); |
| | | |
| | | roomTemp.ListSceneId.Clear(); |
| | | roomTemp.ListSceneId.AddRange(listBackScene); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 执行移除分享数据___________________ |
| | | |
| | | /// <summary> |
| | | /// 执行移除分享数据 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享内容</param> |
| | | /// <param name="listMark">要移除的主键</param> |
| | | /// <param name="listDeleteFile">要删除的文件(房间文件需要删除的话,必须放在最后)</param> |
| | | /// <returns></returns> |
| | | private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listMark, List<string> listDeleteFile) |
| | | { |
| | | if (listMark.Count == 0) |
| | | { |
| | | //有可能只删除一个回路,而这个回路是分配到多个房间的 |
| | | return true; |
| | | } |
| | | |
| | | //开启进度条 |
| | | ProgressBar.Show(); |
| | | //让设备和场景不重复添加的东西 |
| | | var listCheck = new HashSet<string>(); |
| | | foreach (var markKeys in listMark) |
| | | { |
| | | //里面似乎有可能会出现重复 |
| | | if (listCheck.Contains(markKeys) == true) { continue; } |
| | | listCheck.Add(markKeys); |
| | | |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = markKeys }; |
| | | //执行删除 |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/share/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | { |
| | | //关闭进度条 |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | //然后把场景和设备从这个克隆的对象里面移除掉(真实物理设备的房间不用理) |
| | | foreach (var device in i_listDevice) |
| | | { |
| | | string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | cloneRoom.ListDevice.Remove(mainKey); |
| | | |
| | | listCheck.Add(mainKey); |
| | | } |
| | | //关闭进度条 |
| | | foreach (var secne in i_listScene) |
| | | { |
| | | cloneRoom.ListSceneId.Remove(secne.Id); |
| | | |
| | | listCheck.Add(secne.Id.ToString()); |
| | | } |
| | | //如果都移除完的话,则直接走删除分享房间的方法 |
| | | if (cloneRoom.ListDevice.Count == 0 && cloneRoom.ListSceneId.Count == 0) |
| | | { |
| | | //执行整个房间删除的方法 |
| | | return this.DeleteSharedRoom(i_ChildAccountId, new List<Room> { i_nowRoom }); |
| | | } |
| | | //获取场景里面嵌套的子设备和子场景 |
| | | foreach (var sceneTemp in i_listScene) |
| | | { |
| | | //从缓存获取场景的执行目标 |
| | | this.GetSceneAdjustTargetListFromShard(sceneTemp, listCheck, i_listScene, i_listDevice); |
| | | } |
| | | //在删除一个房间中的一些设备的模式下,检测设备和场景是否能够删除(有可能它还在别的房间或者场景当中) |
| | | var listDelDevice = new List<CommonDevice>(); |
| | | var listDelScene = new List<SceneUI>(); |
| | | this.CheckDeviceAndSceneCanDeleteOnDeleteSome(i_listDevice, i_listScene, ref listDelDevice, ref listDelScene, cloneRoom); |
| | | |
| | | //生成分享Bin文件内容(这里不用删除房间) |
| | | var binfFileContent = this.CreatShardBinContentOnDelete(new List<Room>(), listDelDevice, listDelScene); |
| | | |
| | | //上传bin文件 |
| | | var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent)); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | binfFileContent = null; |
| | | |
| | | //如果全部成功了的话,覆盖缓存 |
| | | this.DicDevices.Clear(); |
| | | this.DicScenes.Clear(); |
| | | this.DicRooms.Clear(); |
| | | this.DicFloor.Clear(); |
| | | this.AdjustBinFileContent(binfFileContent); |
| | | |
| | | //删除已经不再分享的图片 |
| | | this.DeleteNotShardPictrue(); |
| | | |
| | | ProgressBar.Close(); |
| | | for (int i = 0; i < listDeleteFile.Count; i++) |
| | | { |
| | | string fileName = listDeleteFile[i]; |
| | | if (i == listDeleteFile.Count - 1 && fileName.StartsWith("Room_") == true) |
| | | { |
| | | //最后一个固定可能是房间文件,直接移除整个对象 |
| | | memberShardInfo.dicShardRoom.Remove(fileName); |
| | | } |
| | | memberShardInfo.dicAllShardKeys.Remove(fileName); |
| | | |
| | | this.DeleteShardFile(fileName); |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除指定分享内容(整个房间删除) |
| | | /// </summary> |
| | | /// <param name="i_ChildAccountId">成员ID</param> |
| | | /// <param name="i_listRoom">需要整个删除的房间</param> |
| | | /// <returns></returns> |
| | | public bool DeleteSharedRoom(string i_ChildAccountId, List<Room> i_listRoom) |
| | | { |
| | | //打开进度条 |
| | | ProgressBar.Show(); |
| | | //设置最大值 |
| | | ProgressBar.SetMaxValue(1); |
| | | |
| | | //获取删除房间的全部全部设备和场景 |
| | | var listDevice = new List<CommonDevice>(); |
| | | var listScene = new List<SceneUI>(); |
| | | this.GetDeleteRoomAllDeviceAndScene(i_listRoom, ref listDevice, ref listScene); |
| | | |
| | | //删除的房间ID |
| | | var listDeleteRoom = new List<string>(); |
| | | foreach (var room in i_listRoom) |
| | | { |
| | | //判断场景和设备是否能删除时使用 |
| | | listDeleteRoom.Add(room.Id); |
| | | } |
| | | //在删除整个房间的模式下,检测设备和场景是否能够删除(有可能它还在别的房间或者场景当中) |
| | | var listDelDevice = new List<CommonDevice>(); |
| | | var listDelScene = new List<SceneUI>(); |
| | | this.CheckDeviceAndSceneCanDeleteOnDeleteRoom(listDevice, listScene, ref listDelDevice, ref listDelScene, listDeleteRoom); |
| | | |
| | | //生成分享Bin文件内容 |
| | | var binfFileContent = this.CreatShardBinContentOnDelete(i_listRoom, listDelDevice, listDelScene); |
| | | |
| | | //上传bin文件 |
| | | var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent)); |
| | | if (fileKey == null) |
| | | { |
| | | ProgressBar.Close(); |
| | | return false; |
| | | } |
| | | ProgressBar.SetValue(1); |
| | | |
| | | //记录主键 |
| | | this.DicShardKeys[SHARED_BIN_FILE] = fileKey; |
| | | binfFileContent = null; |
| | | |
| | | //如果全部成功了的话,覆盖缓存 |
| | | this.DicDevices.Clear(); |
| | | this.DicScenes.Clear(); |
| | | this.DicRooms.Clear(); |
| | | this.DicFloor.Clear(); |
| | | this.AdjustBinFileContent(binfFileContent); |
| | | |
| | | //删除已经不再分享的图片 |
| | | this.DeleteNotShardPictrue(); |
| | | |
| | | ProgressBar.Close(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行移除分享数据 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享内容</param> |
| | | /// <param name="listDelFile">删除的文件</param> |
| | | /// <param name="mode">失败时是否显示tip消息</param> |
| | | /// <returns></returns> |
| | | private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listDelFile) |
| | | private bool DoDeleteSharedContent(List<string> listDelFile, ShowNetCodeMode mode = ShowNetCodeMode.YES) |
| | | { |
| | | if (listDelFile.Count == 0) |
| | | { |
| | |
| | | } |
| | | foreach (var fileName in listDelFile) |
| | | { |
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false) |
| | | if (this.DicShardKeys.ContainsKey(fileName) == false) |
| | | { |
| | | //我也不知道为什么会找不到主键 |
| | | continue; |
| | | } |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = memberShardInfo.dicAllShardKeys[fileName] }; |
| | | var pra = new { homeId = Config.Instance.Home.Id, homeShareId = this.DicShardKeys[fileName] }; |
| | | //执行删除 |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/share/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/share/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | //检测状态码 |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false) |
| | | if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | for (int i = 0; i < listDelFile.Count; i++) |
| | | { |
| | | string fileName = listDelFile[i]; |
| | | memberShardInfo.dicAllShardKeys.Remove(fileName); |
| | | |
| | | this.DeleteShardFile(fileName); |
| | | //移除缓存 |
| | | this.DicShardKeys.Remove(fileName); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 上传房间对象_______________________ |
| | | #region ■ 删除分享内容辅助方法_______________ |
| | | |
| | | /// <summary> |
| | | /// 上传房间对象 |
| | | /// 获取删除房间的全部全部设备和场景 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的共享内容</param> |
| | | /// <param name="upDateRoom">需要上传到云端的房间对象</param> |
| | | /// <returns></returns> |
| | | private bool DoUploadRoomObject(MemberShardInfoData memberShardInfo, Common.Room upDateRoom) |
| | | /// <param name="i_listRoom">删除的房间</param> |
| | | /// <param name="listDevice">全部设备(返回值)</param> |
| | | /// <param name="listScene">全部场景(返回值)</param> |
| | | private void GetDeleteRoomAllDeviceAndScene(List<Room> i_listRoom, ref List<CommonDevice> listDevice, ref List<SceneUI> listScene) |
| | | { |
| | | if (upDateRoom.Id == "Other") |
| | | var listCheck = new HashSet<string>(); |
| | | foreach (var room in i_listRoom) |
| | | { |
| | | return true; |
| | | } |
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(upDateRoom); |
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data); |
| | | //上传内容 |
| | | var shardId = this.DoUploadShardContent(memberShardInfo.ChildAccountId, upDateRoom.FileName, byteData); |
| | | if (shardId == null) |
| | | { |
| | | return false; |
| | | } |
| | | //将房间对象序列化到缓存 |
| | | this.AddShardFile(upDateRoom); |
| | | //获取设备 |
| | | foreach (var mainkey in room.ListDevice) |
| | | { |
| | | if (listCheck.Contains(mainkey) == true) { continue; } |
| | | listCheck.Add(mainkey); |
| | | |
| | | return true; |
| | | //分享数据里面有才添加 |
| | | if (this.DicDevices.ContainsKey(mainkey) == true) |
| | | { |
| | | listDevice.Add(this.DicDevices[mainkey]); |
| | | } |
| | | } |
| | | //然后再获取场景 |
| | | foreach (var sceneId in room.ListSceneId) |
| | | { |
| | | if (listCheck.Contains(sceneId.ToString()) == true) { continue; } |
| | | listCheck.Add(sceneId.ToString()); |
| | | |
| | | //分享数据里面有才添加 |
| | | if (this.DicScenes.ContainsKey(sceneId) == true) |
| | | { |
| | | var sceneTemp = this.DicScenes[sceneId]; |
| | | listScene.Add(sceneTemp); |
| | | |
| | | //获取场景里面嵌套的子设备和子场景 |
| | | this.GetSceneAdjustTargetListFromShard(sceneTemp, listCheck, listScene, listDevice); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 上传楼层对象_______________________ |
| | | |
| | | /// <summary> |
| | | /// 上传楼层对象 |
| | | /// 在删除整个房间的模式下,检测设备和场景是否能够删除(有可能它还在别的房间或者场景当中) |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的共享内容</param> |
| | | /// <returns></returns> |
| | | private bool DoUploadFloorObject(MemberShardInfoData memberShardInfo) |
| | | /// <param name="i_listDevice">理论上要删除的设备</param> |
| | | /// <param name="i_listScene">理论上要删除的场景</param> |
| | | /// <param name="listDeleteDevice">真实能够删除的设备(返回值)</param> |
| | | /// <param name="listDeleteScene">真实能够删除的场景(返回值)</param> |
| | | /// <param name="i_listDelleteRoom">删除的房间</param> |
| | | private void CheckDeviceAndSceneCanDeleteOnDeleteRoom(List<CommonDevice> i_listDevice, List<SceneUI> i_listScene, |
| | | ref List<CommonDevice> listDeleteDevice, ref List<SceneUI> listDeleteScene, List<string> i_listNotCheckRoom) |
| | | { |
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(memberShardInfo.dicShardFloor); |
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data); |
| | | //上传内容 |
| | | var shardId = this.DoUploadShardContent(memberShardInfo.ChildAccountId, HdlFileNameResourse.ShardFloorFile, byteData); |
| | | if (shardId == null) |
| | | //注意:这个函数和下面的CheckDeviceAndSceneCanDeleteOnDeleteSome有本质区别 |
| | | //这个只是完全删除一个房间内的设备或者场景,因此只需要去判断删除以外的就可以了 |
| | | |
| | | //获取理论上需要删除的场景ID |
| | | var listSceneId = new List<int>(); |
| | | foreach (var scene in i_listScene) |
| | | { |
| | | return false; |
| | | listSceneId.Add(scene.Id); |
| | | } |
| | | var listShardDevice = new HashSet<string>(); |
| | | var listShardScene = new HashSet<int>(); |
| | | //获取除了理论上需要删除的场景之外,目前还分享的场景的执行目标里面的设备 |
| | | foreach (var scene in this.DicScenes.Values) |
| | | { |
| | | //这个是要删除的场景 |
| | | if (listSceneId.Contains(scene.Id) == true) { continue; } |
| | | |
| | | foreach (var data in scene.AdjustTargetList) |
| | | { |
| | | //设备 |
| | | if (data.Type == 0) |
| | | { |
| | | var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint); |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | listShardDevice.Add(mainkey); |
| | | } |
| | | } |
| | | //子场景 |
| | | else if (data.Type == 1) |
| | | { |
| | | if (listShardScene.Contains(data.ElseScenesId) == false) |
| | | { |
| | | listShardScene.Add(data.ElseScenesId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //获取除了理论上需要删除的房间之外,目前还分享的设备 |
| | | foreach (var room in this.DicRooms.Values) |
| | | { |
| | | //这个是要删除的房间 |
| | | if (i_listNotCheckRoom.Contains(room.Id) == true) { continue; } |
| | | |
| | | foreach (var mainkey in room.ListDevice) |
| | | { |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | listShardDevice.Add(mainkey); |
| | | } |
| | | } |
| | | foreach (var sceneId in room.ListSceneId) |
| | | { |
| | | if (listShardScene.Contains(sceneId) == false) |
| | | { |
| | | listShardScene.Add(sceneId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //将房间对象序列化到缓存 |
| | | this.AddShardFile(memberShardInfo.dicShardFloor); |
| | | |
| | | return true; |
| | | //判断实际能够删除的设备 |
| | | foreach (var device in i_listDevice) |
| | | { |
| | | var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | //这个设备已经不在分享 |
| | | listDeleteDevice.Add(device); |
| | | } |
| | | } |
| | | //判断实际能够删除的场景 |
| | | foreach (var scene in i_listScene) |
| | | { |
| | | if (listShardScene.Contains(scene.Id) == false) |
| | | { |
| | | //这个场景已经不在分享 |
| | | listDeleteScene.Add(scene); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | /// <summary> |
| | | /// 在删除一个房间中的一些设备的模式下,检测设备和场景是否能够删除(有可能它还在别的房间或者场景当中) |
| | | /// </summary> |
| | | /// <param name="i_listDevice">理论上要删除的设备</param> |
| | | /// <param name="i_listScene">理论上要删除的场景</param> |
| | | /// <param name="listDeleteDevice">真实能够删除的设备(返回值)</param> |
| | | /// <param name="listDeleteScene">真实能够删除的场景(返回值)</param> |
| | | /// <param name="i_nowCloneRoom">当前房间(克隆)</param> |
| | | private void CheckDeviceAndSceneCanDeleteOnDeleteSome(List<CommonDevice> i_listDevice, List<SceneUI> i_listScene, |
| | | ref List<CommonDevice> listDeleteDevice, ref List<SceneUI> listDeleteScene, Room i_nowCloneRoom) |
| | | { |
| | | //注意:这个函数和上面的CheckDeviceAndSceneCanDeleteOnDeleteRoom有本质区别 |
| | | //这个只是删除一个房间内的部分设备或者场景,因此它有可能自身就嵌套着要删除的设备或者场景 |
| | | |
| | | #region ■ 移除共享的一般方法_________________ |
| | | //先获取目前还在分享的设备和场景 |
| | | var listShardDevice = new HashSet<string>(); |
| | | var listShardScene = new HashSet<int>(); |
| | | |
| | | foreach (var roomId in this.DicRooms.Keys) |
| | | { |
| | | //如果是当前克隆的房间,则用克隆的房间来处理,克隆的房间已经把理论上要删除的设备和场景都删除了 |
| | | var room = i_nowCloneRoom.Id != roomId ? this.DicRooms[roomId] : i_nowCloneRoom; |
| | | //还在分享的设备 |
| | | foreach (var mainkey in room.ListDevice) |
| | | { |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | listShardDevice.Add(mainkey); |
| | | } |
| | | } |
| | | //还在分享的场景 |
| | | foreach (var sceneId in room.ListSceneId) |
| | | { |
| | | if (listShardScene.Contains(sceneId) == false) |
| | | { |
| | | listShardScene.Add(sceneId); |
| | | } |
| | | //从场景的执行目标当前获取 |
| | | if (this.DicScenes.ContainsKey(sceneId) == true) |
| | | { |
| | | foreach (var data in this.DicScenes[sceneId].AdjustTargetList) |
| | | { |
| | | //子设备 |
| | | if (data.Type == 0) |
| | | { |
| | | var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint); |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | listShardDevice.Add(mainkey); |
| | | } |
| | | } |
| | | //子场景 |
| | | else if (data.Type == 1) |
| | | { |
| | | if (listShardScene.Contains(data.ElseScenesId) == false) |
| | | { |
| | | listShardScene.Add(data.ElseScenesId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //判断实际能够删除的设备 |
| | | foreach (var device in i_listDevice) |
| | | { |
| | | var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | if (listShardDevice.Contains(mainkey) == false) |
| | | { |
| | | //这个设备已经不在分享 |
| | | listDeleteDevice.Add(device); |
| | | } |
| | | } |
| | | //判断实际能够删除的场景 |
| | | foreach (var scene in i_listScene) |
| | | { |
| | | if (listShardScene.Contains(scene.Id) == false) |
| | | { |
| | | //这个场景已经不在分享 |
| | | listDeleteScene.Add(scene); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从缓存字典中获取已经分享了的全部设备主键和场景的ID |
| | | /// 从分享数据里面获取场景里面的执行目标列表 |
| | | /// </summary> |
| | | /// <param name="memberShardInfo">成员的分享信息</param> |
| | | /// <param name="nowRoom">当前房间</param> |
| | | /// <param name="listDeleteDevice">要删除的设备列表</param> |
| | | /// <param name="listDeleteScene">要删除的场景列表</param> |
| | | /// <param name="scene">场景</param> |
| | | /// <param name="listCheck">重复检测用</param> |
| | | /// <param name="listSceneUI">添加分享的场景列表</param> |
| | | /// <param name="listDevice">添加分享的设备列表</param> |
| | | /// <returns></returns> |
| | | private HashSet<string> GetAllShardedKeysFromDictionary(MemberShardInfoData memberShardInfo, Common.Room nowRoom, |
| | | List<CommonDevice> listDeleteDevice, List<Common.SceneUI> listDeleteScene) |
| | | private void GetSceneAdjustTargetListFromShard(SceneUI scene, HashSet<string> listCheck, List<SceneUI> listSceneUI, List<CommonDevice> listDevice) |
| | | { |
| | | //获取全部要删除的文件名字 |
| | | var dicDeleteDeviceFile = new Dictionary<string, string>(); |
| | | foreach (var device in listDeleteDevice) |
| | | { |
| | | dicDeleteDeviceFile[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device.FilePath; |
| | | } |
| | | var dicDeleteSceneFile = new Dictionary<int, string>(); |
| | | foreach (var scene in listDeleteScene) |
| | | { |
| | | dicDeleteSceneFile[scene.Id] = scene.FileName; |
| | | } |
| | | |
| | | var listShardKeys = new HashSet<string>(); |
| | | //获取还处于分享状态的主键 |
| | | foreach (var roomTemp in memberShardInfo.dicShardRoom.Values) |
| | | foreach (var data in scene.AdjustTargetList) |
| | | { |
| | | //设备 |
| | | foreach (var deviceKeys in roomTemp.ListDevice) |
| | | if (data.Type == 0) |
| | | { |
| | | if (dicDeleteDeviceFile.ContainsKey(deviceKeys) == true) |
| | | string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint); |
| | | if (listCheck.Contains(mainKeys) == true) |
| | | { |
| | | //因为一个回路只能分配一个区域,所以可以直接判断 |
| | | //不重复添加 |
| | | continue; |
| | | } |
| | | if (listShardKeys.Contains(deviceKeys) == false) |
| | | listCheck.Add(mainKeys); |
| | | if (this.DicDevices.ContainsKey(mainKeys) == true) |
| | | { |
| | | //这个文件还分享着 |
| | | listShardKeys.Add(deviceKeys); |
| | | listDevice.Add(this.DicDevices[mainKeys]); |
| | | } |
| | | |
| | | } |
| | | //场景 |
| | | foreach (var sceneId in roomTemp.ListSceneId) |
| | | else if (data.Type == 1) |
| | | { |
| | | if (roomTemp.FileName == nowRoom.FileName) |
| | | string mainKeys = data.ElseScenesId.ToString(); |
| | | if (listCheck.Contains(mainKeys) == true) |
| | | { |
| | | //如果循环到了当前房间 |
| | | if (dicDeleteSceneFile.ContainsKey(sceneId) == true) |
| | | { |
| | | //如果是删除目标,则不添加 |
| | | continue; |
| | | } |
| | | } |
| | | var byteData = this.GetShardFileContent($"Scene_{sceneId}.json"); |
| | | if (byteData == null) |
| | | { |
| | | //不重复添加 |
| | | continue; |
| | | } |
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData); |
| | | var sceneTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData); |
| | | listCheck.Add(mainKeys); |
| | | |
| | | //获取场景里面的全部目标 |
| | | var listTempKeys = new HashSet<string>(); |
| | | //从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取) |
| | | this.GetSceneBindListKeys(sceneTemp, ref listTempKeys); |
| | | //获取场景对象 |
| | | if (this.DicScenes.ContainsKey(data.ElseScenesId) == true) |
| | | { |
| | | var sceneUi = this.DicScenes[data.ElseScenesId]; |
| | | listSceneUI.Add(sceneUi); |
| | | |
| | | if (listShardKeys.Contains(sceneId.ToString()) == false) |
| | | { |
| | | //场景自身 |
| | | listShardKeys.Add(sceneId.ToString()); |
| | | } |
| | | foreach (string myKeys2 in listTempKeys) |
| | | { |
| | | if (listShardKeys.Contains(myKeys2) == false) |
| | | { |
| | | listShardKeys.Add(myKeys2); |
| | | } |
| | | //递归获取执行目标 |
| | | this.GetSceneAdjustTargetListFromShard(sceneUi, listCheck, listSceneUI, listDevice); |
| | | } |
| | | } |
| | | } |
| | | return listShardKeys; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region ■ 生成分享Bin文件内容________________ |
| | | |
| | | /// <summary> |
| | | /// 生成分享Bin文件内容(新增模式) |
| | | /// </summary> |
| | | /// <param name="i_listNewRoom">新的房间对象集合(也就是变更了的房间)</param> |
| | | /// <param name="i_listDevice">这个是需要追加的分享设备</param> |
| | | /// <param name="i_listScene">这个是需要追加的分享场景</param> |
| | | /// <param name="i_listChirdDevice">这个是由场景的执行目标来的</param> |
| | | /// <param name="i_listChirdScene">这个是由场景的执行目标来的</param> |
| | | /// <returns></returns> |
| | | private string CreatShardBinContentOnAdd(List<Room> i_listNewRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene, |
| | | List<CommonDevice> i_listChirdDevice, List<SceneUI> i_listChirdScene) |
| | | { |
| | | string writeText = string.Empty; |
| | | //生成写入文件的【设备对象数据】 |
| | | this.CreatWriteCommonDeviceData(i_listDevice, i_listChirdDevice, false, ref writeText); |
| | | |
| | | //生成写入文件的【场景数据】 |
| | | this.CreatWriteSceneData(i_listScene, i_listChirdScene, false, ref writeText); |
| | | |
| | | //生成写入文件的【场景数据】 |
| | | this.CrearWriteRoomData(i_listNewRoom, false, ref writeText); |
| | | |
| | | return writeText; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取) |
| | | /// 生成分享Bin文件内容(删除模式) |
| | | /// </summary> |
| | | /// <param name="scene">场景</param> |
| | | /// <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) |
| | | /// <param name="i_listDelRoom">要删除的房间</param> |
| | | /// <param name="i_listDevice">这个是需要删除的分享设备</param> |
| | | /// <param name="i_listScene">这个是需要删除的分享场景</param> |
| | | /// <returns></returns> |
| | | private string CreatShardBinContentOnDelete(List<Room> i_listDelRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene) |
| | | { |
| | | foreach (var data in scene.AdjustTargetList) |
| | | string writeText = string.Empty; |
| | | //生成写入文件的【设备对象数据】 |
| | | this.CreatWriteCommonDeviceData(i_listDevice, new List<CommonDevice>(), true, ref writeText); |
| | | |
| | | //生成写入文件的【场景数据】 |
| | | this.CreatWriteSceneData(i_listScene, new List<SceneUI>(), true, ref writeText); |
| | | |
| | | //生成写入文件的【场景数据】 |
| | | this.CrearWriteRoomData(i_listDelRoom, true, ref writeText); |
| | | |
| | | return writeText; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成写入文件的【设备对象数据】 |
| | | /// </summary> |
| | | /// <param name="writeText"></param> |
| | | private void CreatWriteCommonDeviceData(List<CommonDevice> i_listDevice, List<CommonDevice> i_listChirdDevice, bool i_isDel, ref string writeText) |
| | | { |
| | | //合并设备到一个新的对象当中 |
| | | var dicNewDevice = this.MergeNewShardDevices(i_listDevice, i_listChirdDevice, i_isDel); |
| | | var listCheck = new HashSet<string>(); |
| | | foreach (var device in dicNewDevice.Values) |
| | | { |
| | | //设备 |
| | | if (data.Type == 0) |
| | | //设备端点 |
| | | writeText += "#DeviceInfo START#" + (int)device.Type + "\r\n"; |
| | | string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(device); |
| | | writeText += dataInfo + "\r\n"; |
| | | writeText += "#DeviceInfo END#\r\n\r\n"; |
| | | |
| | | //添加Ota设备对象的缓存 |
| | | if (listCheck.Contains(device.DeviceAddr) == false) |
| | | { |
| | | string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint); |
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true && dicDeviceKeys.ContainsKey(mainkey) == false) |
| | | listCheck.Add(device.DeviceAddr); |
| | | var otaDevice = HdlDeviceCommonLogic.Current.GetOTADevice(device.DeviceAddr); |
| | | if (otaDevice != null) |
| | | { |
| | | dicDeviceKeys[mainkey] = dicShardDeviceFile[mainkey]; |
| | | } |
| | | } |
| | | if (data.Type == 1) |
| | | { |
| | | var byteData = this.GetShardFileContent($"Scene_{data.ElseScenesId}.json"); |
| | | if (byteData != null) |
| | | { |
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData); |
| | | var sceneTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData); |
| | | listBindScene.Add(sceneTemp); |
| | | writeText += "#DeviceInfo START#" + (int)otaDevice.Type + "\r\n"; |
| | | string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(otaDevice); |
| | | writeText += dataInfo2 + "\r\n"; |
| | | writeText += "#DeviceInfo END#\r\n\r\n"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从场景对象里面获取全部的绑定目标的主键(这里面的东西必须从分享数据中获取) |
| | | /// 生成写入文件的【场景数据】 |
| | | /// </summary> |
| | | /// <param name="scene">场景</param> |
| | | /// <param name="listKeys">主键列表(设备和场景)</param> |
| | | private void GetSceneBindListKeys(Common.SceneUI scene, ref HashSet<string> listKeys) |
| | | /// <param name="i_listScene">这个是需要追加的分享场景</param> |
| | | /// <param name="i_listChirdScene">这个是由场景的执行目标来的</param> |
| | | /// <param name="writeText"></param> |
| | | private void CreatWriteSceneData(List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene, bool i_isDel, ref string writeText) |
| | | { |
| | | foreach (var data in scene.AdjustTargetList) |
| | | //合并场景到一个新的对象当中 |
| | | var dicNewScene = this.MergeNewShardScenes(i_listScene, i_listChirdScene, i_isDel); |
| | | |
| | | foreach (var scene in dicNewScene.Values) |
| | | { |
| | | //设备 |
| | | if (data.Type == 0) |
| | | writeText += "#START#\r\n"; |
| | | string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(scene); |
| | | writeText += dataInfo + "\r\n"; |
| | | writeText += "#SceneTemplate END#\r\n\r\n"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成写入文件的【房间模板数据】 |
| | | /// </summary> |
| | | /// <param name="i_listNewRoom">新的房间对象集合(也就是变更了的房间)</param> |
| | | /// <param name="writeText"></param> |
| | | private void CrearWriteRoomData(List<Room> i_listNewRoom, bool i_isDel, ref string writeText) |
| | | { |
| | | var dicNewFloor = new Dictionary<string, string>(); |
| | | //合并分享的房间到一个新的对象中 |
| | | var dicNewRoom = this.MergeNewShardRooms(i_listNewRoom, i_isDel); |
| | | foreach (var room in dicNewRoom.Values) |
| | | { |
| | | writeText += "#START#\r\n"; |
| | | string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(room); |
| | | writeText += dataInfo2 + "\r\n"; |
| | | writeText += "#RoomInfo END#\r\n\r\n"; |
| | | |
| | | if (room.FloorId != string.Empty) |
| | | { |
| | | string mainkey = HdlDeviceCommonLogic.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()); |
| | | } |
| | | dicNewFloor[room.FloorId] = HdlResidenceLogic.Current.GetFloorNameById(room.FloorId); |
| | | } |
| | | } |
| | | //楼层数据 |
| | | writeText += "#START#\r\n"; |
| | | string dataInfo1 = Newtonsoft.Json.JsonConvert.SerializeObject(dicNewFloor); |
| | | writeText += dataInfo1 + "\r\n"; |
| | | writeText += "#FloorInfo END#\r\n\r\n"; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 生成分享Bin文件内容辅助方法________ |
| | | |
| | | /// <summary> |
| | | /// 合并分享的设备到一个新的对象中 |
| | | /// </summary> |
| | | /// <param name="i_listDevice">这个是需要追加的分享设备</param> |
| | | /// <param name="i_listChirdDevice">这个是由场景的执行目标来的</param> |
| | | /// <param name="i_isDel">是否是删除分享模式</param> |
| | | /// <returns></returns> |
| | | private Dictionary<string, CommonDevice> MergeNewShardDevices(List<CommonDevice> i_listDevice, List<CommonDevice> i_listChirdDevice, bool i_isDel) |
| | | { |
| | | var dicNewDevice = new Dictionary<string, CommonDevice>(); |
| | | //先合并原来的 |
| | | foreach (var key in this.DicDevices.Keys) |
| | | { |
| | | dicNewDevice[key] = this.DicDevices[key]; |
| | | } |
| | | //再合并新添加的 |
| | | foreach (var device in i_listDevice) |
| | | { |
| | | string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | if (i_isDel == false) |
| | | { |
| | | //直接覆盖,没问题 |
| | | dicNewDevice[mainkey] = device; |
| | | } |
| | | else |
| | | { |
| | | //删除模式 |
| | | dicNewDevice.Remove(mainkey); |
| | | } |
| | | } |
| | | foreach (var device in i_listChirdDevice) |
| | | { |
| | | string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device); |
| | | //直接覆盖,没问题 |
| | | dicNewDevice[mainkey] = device; |
| | | } |
| | | return dicNewDevice; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 合并分享的场景到一个新的对象中 |
| | | /// </summary> |
| | | /// <param name="i_listScene">这个是需要追加的分享场景</param> |
| | | /// <param name="i_listChirdScene">这个是由场景的执行目标来的</param> |
| | | /// <param name="i_isDel">是否是删除分享模式</param> |
| | | /// <returns></returns> |
| | | private Dictionary<int, SceneUI> MergeNewShardScenes(List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene, bool i_isDel) |
| | | { |
| | | var dicNewScene = new Dictionary<int, SceneUI>(); |
| | | //先合并原来的 |
| | | foreach (var key in this.DicScenes.Keys) |
| | | { |
| | | dicNewScene[key] = this.DicScenes[key]; |
| | | } |
| | | //再合并新添加的 |
| | | foreach (var scene in i_listScene) |
| | | { |
| | | if (i_isDel == false) |
| | | { |
| | | //直接覆盖,没问题 |
| | | dicNewScene[scene.Id] = scene; |
| | | } |
| | | else |
| | | { |
| | | //删除模式 |
| | | dicNewScene.Remove(scene.Id); |
| | | } |
| | | } |
| | | foreach (var scene in i_listChirdScene) |
| | | { |
| | | //直接覆盖,没问题 |
| | | dicNewScene[scene.Id] = scene; |
| | | } |
| | | return dicNewScene; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 合并分享的房间到一个新的对象中 |
| | | /// </summary> |
| | | /// <param name="i_listNewRoom">新的房间对象集合(也就是变更了的房间)</param> |
| | | /// <param name="i_isDel">是否是删除分享模式</param> |
| | | /// <returns></returns> |
| | | private Dictionary<string, Room> MergeNewShardRooms(List<Room> i_listNewRoom, bool i_isDel) |
| | | { |
| | | var dicNewRoom = new Dictionary<string, Room>(); |
| | | //先合并原来的 |
| | | foreach (var key in this.DicRooms.Keys) |
| | | { |
| | | dicNewRoom[key] = this.DicRooms[key]; |
| | | } |
| | | //再合并新添加的 |
| | | foreach (var room in i_listNewRoom) |
| | | { |
| | | if (i_isDel == false) |
| | | { |
| | | //直接覆盖,没问题 |
| | | dicNewRoom[room.Id] = room; |
| | | } |
| | | else |
| | | { |
| | | //删除模式 |
| | | dicNewRoom.Remove(room.Id); |
| | | } |
| | | } |
| | | return dicNewRoom; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region ■ 获取分享缓存方法___________________ |
| | | |
| | | /// <summary> |
| | | /// 从缓存当中获取分享的设备 |
| | | /// </summary> |
| | | /// <param name="i_deviceKey">设备的主键</param> |
| | | /// <returns></returns> |
| | | public CommonDevice GetShardDeviceFromMemory(string i_deviceKey) |
| | | { |
| | | if (this.DicDevices.ContainsKey(i_deviceKey) == true) |
| | | { |
| | | return this.DicDevices[i_deviceKey]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从缓存当中获取分享的场景 |
| | | /// </summary> |
| | | /// <param name="i_sceneId">场景ID</param> |
| | | /// <returns></returns> |
| | | public SceneUI GetShardSceneFromMemory(int i_sceneId) |
| | | { |
| | | if (this.DicScenes.ContainsKey(i_sceneId) == true) |
| | | { |
| | | return this.DicScenes[i_sceneId]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从缓存当中获取分享的房间 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<string, Room> GetShardRoomFromMemory() |
| | | { |
| | | return this.DicRooms; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从缓存当中获取分享的房间 |
| | | /// </summary> |
| | | /// <param name="i_roomId">房间ID</param> |
| | | /// <returns></returns> |
| | | public Room GetShardRoomFromMemory(string i_roomId) |
| | | { |
| | | if (this.DicRooms.ContainsKey(i_roomId) == true) |
| | | { |
| | | return this.DicRooms[i_roomId]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从缓存当中获取分享的楼层 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<string, string> GetShardFloorFormMemory() |
| | | { |
| | | return this.DicFloor; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 一般方法___________________________ |
| | | |
| | | /// <summary> |
| | | /// 获取分享文件的内容 |
| | | /// </summary> |
| | | /// <param name="fileName">文件名称(不是全路径)</param> |
| | | /// <returns></returns> |
| | | private byte[] GetShardFileContent(string fileName) |
| | | { |
| | | string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName); |
| | | if (System.IO.File.Exists(fullName) == false) |
| | | { |
| | | return null; |
| | | } |
| | | var varByte = HdlFileLogic.Current.ReadFileByteContent(fullName); |
| | | return varByte; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空共享缓存 |
| | | /// </summary> |
| | | public void Dispone() |
| | | { |
| | | this.DicDevices = null; |
| | | this.DicScenes.Clear(); |
| | | this.DicRooms.Clear(); |
| | | this.DicShardKeys.Clear(); |
| | | this.DicFloor.Clear(); |
| | | |
| | | //清空文件夹 |
| | | string strDir = HdlFileNameResourse.DownLoadShardDirectory; |
| | | HdlFileLogic.Current.CreateDirectory(strDir, true); |
| | | |
| | | m_Current = null; |
| | | } |
| | | |
| | | #endregion |