| | |
| | | using Shared.Common;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Collections.Specialized;
|
| | | using System.IO;
|
| | | using System.Net;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
| | | //文件夹
|
| | | string strDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
|
| | |
|
| | | //不允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | |
|
| | | foreach (string keys in listDistributedMark)
|
| | | {
|
| | | var dataPra = new { DistributedMark = keys, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.isAdministrator };
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetOneShareData", false, dataPra);
|
| | | if (result == null)
|
| | | {
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | | return null;
|
| | | }
|
| | | var dataResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetShardInfoResult>(result);
|
| | |
| | | //设置进度值
|
| | | ProgressBar.SetValue(1);
|
| | | }
|
| | |
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | |
|
| | | return listFile;
|
| | | }
|
| | |
| | | /// <summary>
|
| | | /// 获取本地全部的共享文件
|
| | | /// </summary>
|
| | | /// <param name="room">指定只获取指定房间的</param>
|
| | | /// <returns></returns>
|
| | | public List<string> GetLocalAllShardFile(Common.Room room = null)
|
| | | public List<string> GetLocalAllShardFile()
|
| | | {
|
| | | string path = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
|
| | | var listFile = HdlAutoBackupLogic.GetFileFromDirectory(path);
|
| | | if (room == null)
|
| | |
|
| | | return listFile;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 文件是否存在
|
| | | /// </summary>
|
| | | /// <param name="fileName"></param>
|
| | | /// <returns></returns>
|
| | | public bool IsFileExists(string fileName)
|
| | | {
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | return listFile;
|
| | | return false;
|
| | | }
|
| | | //房间
|
| | | var listRoomFile = new List<string>() { room.FileName };
|
| | | //场景文件
|
| | | listRoomFile.AddRange(room.SceneUIFilePathList);
|
| | | //设备文件
|
| | | foreach (var uiName in room.DeviceUIFilePathList)
|
| | | {
|
| | | string deviceName = uiName.Replace("DeviceUI_", string.Empty);
|
| | | listRoomFile.Add(deviceName);
|
| | | }
|
| | | return null;
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加楼层对象到缓存
|
| | | /// </summary>
|
| | | /// <param name="dic">楼层</param>
|
| | | public void AddShardFile(Dictionary<string, string> dic)
|
| | | {
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | |
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, DirNameResourse.ShardFloorFile);
|
| | | //写入内容
|
| | | Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 删除分享文件_______________________
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取成员共享列表___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 从本地获取成员的分享列表
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享数据的缓存(调用这个函数会刷新这个变量的信息)</param>
|
| | | public void GetMemberShardContentListFromLocal(MemberShardInfoData memberShardInfo)
|
| | | {
|
| | | memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
|
| | |
|
| | | var listDeviceFile = new HashSet<string>();
|
| | | var listSceneFile = new HashSet<string>();
|
| | |
|
| | | var listFile = this.GetLocalAllShardFile();
|
| | | //先初始化房间
|
| | | foreach (string fileName in listFile)
|
| | | {
|
| | | 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 == DirNameResourse.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)
|
| | | {
|
| | | //设备文件
|
| | | listDeviceFile.Add(fileName);
|
| | | }
|
| | | else if (fileName.StartsWith("Scene_") == true)
|
| | | {
|
| | | //场景文件
|
| | | listSceneFile.Add(fileName);
|
| | | }
|
| | | }
|
| | |
|
| | | //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
|
| | | foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //还原设备对象
|
| | | tempRoom.DeviceUIList.Clear();
|
| | | foreach (string uiPath in tempRoom.DeviceUIFilePathList)
|
| | | {
|
| | | string deviceFile = uiPath.Replace("DeviceUI_", string.Empty);
|
| | | //这个设备文件匹配得到房间
|
| | | listDeviceFile.Remove(deviceFile);
|
| | | if (this.IsFileExists(deviceFile) == false)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(uiPath));
|
| | | }
|
| | | //还原场景对象
|
| | | tempRoom.SceneUIList.Clear();
|
| | | foreach (string uiPath in tempRoom.SceneUIFilePathList)
|
| | | {
|
| | | //这个场景文件匹配得到房间
|
| | | listSceneFile.Remove(uiPath);
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | if (byteData == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | tempRoom.SceneUIList.Add(tempUi);
|
| | | }
|
| | | }
|
| | | //如果存在匹配不上的文件
|
| | | if (listDeviceFile.Count != 0 || listSceneFile.Count != 0)
|
| | | {
|
| | | //创建一个临时房间来存储
|
| | | var roomTemp = new Room();
|
| | | roomTemp.Id = "Other";
|
| | | roomTemp.FloorId = "Other";
|
| | | memberShardInfo.dicShardRoom[roomTemp.FileName] = roomTemp;
|
| | | roomTemp.Name = Language.StringByID(R.MyInternationalizationString.uSharedRoom);
|
| | | //还原设备对象
|
| | | foreach (string deviceFile in listDeviceFile)
|
| | | {
|
| | | roomTemp.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | }
|
| | | //还原场景对象
|
| | | foreach (string uiPath in listSceneFile)
|
| | | {
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | roomTemp.SceneUIList.Add(tempUi);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 同步服务器的分享内容_______________
|
| | |
|
| | | /// <summary>
|
| | |
| | | }
|
| | |
|
| | | //获取主人分享给成员的文件列表
|
| | | var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id , IsOtherAccountControl = Common.Config.Instance.isAdministrator };
|
| | | var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.isAdministrator };
|
| | | var listNotShow = new List<string>() { "NotSetAgain" };
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra, listNotShow);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | //----------------------------------分割线(数据预备)-------------------------------------------------
|
| | |
|
| | | #region ■ 数据预备___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取成员共享列表然后保存到本地(用完之后最好调用清空 ClearShardDirectory函数清空)
|
| | | /// </summary>
|
| | | /// <param name="SubAccountDistributedMark">成员列表接口返回的SubAccountDistributedMark</param>
|
| | | /// <param name="memberShardInfo">
|
| | | /// <para>成员的分享数据</para>
|
| | | /// <para>如果不知道这是什么东西,就New一个,然后缓存起来,调用其他函数都需要这个东西</para>
|
| | | /// <para>New的时候记得对SubAccountDistributedMark赋值,它是成员列表接口返回的SubAccountDistributedMark</para>
|
| | | /// </param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> GetMemberShardContentListAndSetToLocation(MemberShardInfoData memberShardInfo)
|
| | | {
|
| | | if (memberShardInfo.Refresh == false)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | memberShardInfo.Refresh = false;
|
| | |
|
| | | //打开进度条
|
| | | ProgressBar.Show();
|
| | |
|
| | | var infoPra = new
|
| | | {
|
| | | DistributedMark = memberShardInfo.SubAccountDistributedMark,
|
| | | HouseDistributedMark = Shared.Common.Config.Instance.HomeId,
|
| | | IsOtherAccountControl = Common.Config.Instance.isAdministrator
|
| | | };
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
|
| | | if (result == null)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | return false;
|
| | | }
|
| | | var listData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result);
|
| | | //先清空共享文件夹
|
| | | this.ClearShardDirectory();
|
| | |
|
| | | var listMark = new List<string>();
|
| | | foreach (var data in listData)
|
| | | {
|
| | | //性能优化:如果本地拥有这个文件的话,直接使用那个文件
|
| | | string fileName = data.ShareName;
|
| | | //记录起它的主键
|
| | | memberShardInfo.dicAllShardKeys[fileName] = data.DistributedMark;
|
| | |
|
| | | if (fileName.StartsWith("Room_") == true || fileName.StartsWith("Scene_") == true)
|
| | | {
|
| | | //房间文件和场景文件需要重新反序列化
|
| | | listMark.Add(data.DistributedMark);
|
| | | continue;
|
| | | }
|
| | | if (Shared.Common.Global.IsExistsByHomeId(fileName) == true)
|
| | | {
|
| | | //其他文件的话,如果本地存在,则以本地文件为准
|
| | | this.AddShardFile(fileName);
|
| | | continue;
|
| | | }
|
| | | listMark.Add(data.DistributedMark);
|
| | | }
|
| | |
|
| | | //将分享的数据存入本地,返回的是文件名字(异常时返回null)
|
| | | var listFile = await this.SetShardFileToLocation(listMark);
|
| | | if (listFile == null)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | return false;
|
| | | }
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | //----------------------------------分割线(上传新的分享)---------------------------------------------
|
| | |
|
| | | #region ■ 执行上传新的分享___________________
|
| | |
| | | /// <param name="memberShardInfo">成员的分享数据</param>
|
| | | /// <param name="nowRoom">当前的房间对象</param>
|
| | | /// <param name="listDevice">选择上传的设备</param>
|
| | | /// <param name="listScene">选择上传的场景</param>
|
| | | /// <param name="listScene">选择上传的场景(不要获取它里面的绑定列表)</param>
|
| | | /// <param name="BarMaxValue">进度条的最大值,如果不为-1,则内部不会自动弹出进度条</param>
|
| | | /// <param name="listCheckFile">文件重复上传检测</param>
|
| | | public async Task<bool> DoUploadSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
|
| | | List<CommonDevice> listDevice, List<Common.SceneUI> listScene)
|
| | | 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>();
|
| | |
|
| | | //获取场景里面嵌套的子设备和子场景
|
| | |
| | | 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<string>>();
|
| | | //临时备份房间设备列表
|
| | | this.BackupRoomDevicelistTemporary(memberShardInfo, dicBackDevice, dicBackScene);
|
| | |
|
| | | Common.Room roomTemp = null;
|
| | | if (memberShardInfo.dicShardRoom.ContainsKey(nowRoom.FileName) == false)
|
| | | {
|
| | | //克隆一个对象
|
| | | roomTemp = nowRoom.CloneRoomClass();
|
| | | memberShardInfo.dicShardRoom[nowRoom.FileName] = roomTemp;
|
| | | }
|
| | | roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName];
|
| | |
|
| | | //获取上传的文件,然后将文件复制到指定文件夹
|
| | | var listFile = this.GetUploadListFile(ref roomTemp, listDevice, listScene, listChirdDevice, listChirdScene);
|
| | | var listDelPic = new List<string>();
|
| | | var listFile = this.GetUploadListFile(memberShardInfo, nowRoom, listDevice, listScene, listChirdDevice, listChirdScene, listDelPic);
|
| | |
|
| | | //打开进度条
|
| | | ProgressBar.Show();
|
| | | //设置最大值
|
| | | ProgressBar.SetMaxValue(listFile.Count);
|
| | | //不允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | |
|
| | | if (BarMaxValue == -1)
|
| | | {
|
| | | //打开进度条
|
| | | ProgressBar.Show();
|
| | | //设置最大值
|
| | | ProgressBar.SetMaxValue(listFile.Count);
|
| | | }
|
| | | else
|
| | | {
|
| | | //设置最大值
|
| | | ProgressBar.SetMaxValue(BarMaxValue);
|
| | | }
|
| | |
|
| | | //上传分享
|
| | | var result = await this.DoUploadShardContent(memberShardInfo, nowRoom, listFile);
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | var result = await this.DoUploadShardContent(memberShardInfo, listFile, listCheckFile);
|
| | | if (result == true)
|
| | | {
|
| | | //删除指定自定义图片
|
| | | result = await this.DoDeleteSharedContent(memberShardInfo, listDelPic);
|
| | | }
|
| | | if (BarMaxValue == -1)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | }
|
| | |
|
| | | //允许按系统的返回键
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | |
|
| | | if (result == false)
|
| | | {
|
| | | //恢复原数据
|
| | | if (memberShardInfo.TempRoom == null)
|
| | | {
|
| | | memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImageType = BackgroundImageType;
|
| | | memberShardInfo.dicShardRoom[nowRoom.FileName].BackgroundImage = BackgroundImage;
|
| | | }
|
| | | this.RecoverRoomDevicelistTemporary(memberShardInfo, dicBackDevice, dicBackScene, listFile);
|
| | | return false;
|
| | | }
|
| | | else
|
| | | {
|
| | | //覆盖数据
|
| | | if (memberShardInfo.TempRoom != null)
|
| | | {
|
| | | memberShardInfo.dicShardRoom[nowRoom.FileName] = memberShardInfo.TempRoom;
|
| | | }
|
| | | }
|
| | | memberShardInfo.TempRoom = null;
|
| | |
|
| | | return true;
|
| | | return result;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取上传的文件名
|
| | | /// </summary>
|
| | | /// <param name="roomTemp">需要上传到云端的房间对象</param>
|
| | | /// <param name="listDevice">分享的设备列表</param>
|
| | | /// <param name="listScene">分享的场景列表</param>
|
| | | /// <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>
|
| | | /// <returns></returns>
|
| | | private List<string> GetUploadListFile(ref Common.Room roomTemp, List<CommonDevice> listDevice, List<Common.SceneUI> listScene,
|
| | | List<CommonDevice> listChirdDevice, List<Common.SceneUI> listChirdScene)
|
| | | 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)
|
| | | {
|
| | | var listFile = new List<string>();
|
| | | var listOtaCheck = new List<string>();
|
| | |
|
| | | Common.Room roomTemp = null;
|
| | | if (memberShardInfo.dicShardRoom.ContainsKey(nowRoom.FileName) == false)
|
| | | {
|
| | | //克隆一个对象
|
| | | roomTemp = nowRoom.CloneRoomClass();
|
| | | memberShardInfo.TempRoom = roomTemp;
|
| | | //新分享的房间,如果图片是自定义的,则上传图片
|
| | | if (roomTemp.BackgroundImageType != 0)
|
| | | {
|
| | | //自定义的图片,它存在于本地,但是它是全路径
|
| | | string[] Arry = roomTemp.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | listFile.Add(Arry[Arry.Length - 1]);
|
| | | this.AddShardFile(Arry[Arry.Length - 1]);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName];
|
| | | //如果云端分享的房间的图片和主人的不一样的时候
|
| | | if (roomTemp.BackgroundImage != nowRoom.BackgroundImage)
|
| | | {
|
| | | if (roomTemp.BackgroundImageType != 0)
|
| | | {
|
| | | //删除自定义图片
|
| | | string[] Arry = roomTemp.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | listDelPic.Add(Arry[Arry.Length - 1]);
|
| | | }
|
| | | if (nowRoom.BackgroundImageType != 0)
|
| | | {
|
| | | //自定义的图片,它存在于本地,但是它是全路径
|
| | | string[] Arry = nowRoom.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | listFile.Add(Arry[Arry.Length - 1]);
|
| | | this.AddShardFile(Arry[Arry.Length - 1]);
|
| | | }
|
| | | //变更图片设置
|
| | | roomTemp.BackgroundImageType = nowRoom.BackgroundImageType;
|
| | | roomTemp.BackgroundImage = nowRoom.BackgroundImage;
|
| | | }
|
| | | }
|
| | |
|
| | | foreach (var device in listDevice)
|
| | | {
|
| | | //设备
|
| | | listFile.Add(device.FilePath);
|
| | | HdlShardLogic.Current.AddShardFile(device.FilePath);
|
| | | this.AddShardFile(device.FilePath);
|
| | |
|
| | | //设备的UI
|
| | | var deviceUi = $"DeviceUI_{device.FilePath}";
|
| | |
| | | {
|
| | | //设备
|
| | | listFile.Add(device.FilePath);
|
| | | HdlShardLogic.Current.AddShardFile(device.FilePath);
|
| | | this.AddShardFile(device.FilePath);
|
| | | }
|
| | |
|
| | | //场景
|
| | | foreach (var secene in listScene)
|
| | | {
|
| | | if (secene.IconPathType != 0)
|
| | | {
|
| | | //自定义的图片,它存在于本地,但是它是全路径
|
| | | string[] Arry = secene.IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | listFile.Add(Arry[Arry.Length - 1]);
|
| | | this.AddShardFile(Arry[Arry.Length - 1]);
|
| | | }
|
| | |
|
| | | listFile.Add(secene.FileName);
|
| | | HdlShardLogic.Current.AddShardFile(secene);
|
| | | this.AddShardFile(secene);
|
| | |
|
| | | if (roomTemp.SceneUIFilePathList.Contains(secene.FileName) == false)
|
| | | {
|
| | |
| | | foreach (var secene in listChirdScene)
|
| | | {
|
| | | listFile.Add(secene.FileName);
|
| | | HdlShardLogic.Current.AddShardFile(secene);
|
| | | this.AddShardFile(secene);
|
| | | }
|
| | | //房间文件也给过去
|
| | | listFile.Add(roomTemp.FileName);
|
| | | HdlShardLogic.Current.AddShardFile(roomTemp);
|
| | | this.AddShardFile(roomTemp);
|
| | |
|
| | | //反正楼层文件很小,一起给过去吧
|
| | | if (roomTemp.FloorId != string.Empty)
|
| | | {
|
| | | memberShardInfo.dicShardFloor[roomTemp.FloorId] = roomTemp.FloorName; ;
|
| | | }
|
| | | this.AddShardFile(memberShardInfo.dicShardFloor);
|
| | | listFile.Add(DirNameResourse.ShardFloorFile);
|
| | |
|
| | | return listFile;
|
| | | }
|
| | |
| | | /// <param name="listSceneUI">添加分享的场景列表</param>
|
| | | /// <param name="listDevice">添加分享的设备列表</param>
|
| | | /// <returns></returns>
|
| | | private void GetSceneDeviceList(Common.SceneUI scene, HashSet<string> listCheck, List<Common.SceneUI> listSceneUI, List<CommonDevice> listDevice)
|
| | | public void GetSceneDeviceList(Common.SceneUI scene, HashSet<string> listCheck, List<Common.SceneUI> listSceneUI, List<CommonDevice> listDevice)
|
| | | {
|
| | | foreach (var data in scene.AddSceneMemberDataList)
|
| | | {
|
| | |
| | | /// 上传分享(返回云端分享文件的主键:DistributedMark)
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享数据</param>
|
| | | /// <param name="nowRoom">当前的房间对象</param>
|
| | | /// <param name="listFile">上传的文件名</param>
|
| | | /// <param name="listCheckFile">重复文件上传检测</param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> DoUploadShardContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom, List<string> listFile)
|
| | | private async Task<bool> DoUploadShardContent(MemberShardInfoData memberShardInfo, List<string> listFile, HashSet<string> listCheckFile)
|
| | | {
|
| | | var dicKeys = new Dictionary<string, string>();
|
| | | for (int i = 0; i < listFile.Count; i++)
|
| | | {
|
| | | string fileName = listFile[i];
|
| | | var info = new UploadShardContent();
|
| | | info.SubAccountDistributedMark = memberShardInfo.SubAccountDistributedMark;
|
| | | info.ShareName = fileName;
|
| | | info.ShareDataBytes = HdlShardLogic.Current.GetShardFileContent(fileName);
|
| | |
|
| | | //追加共享
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
|
| | | if (listCheckFile != null)
|
| | | {
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | if (listCheckFile.Contains(fileName) == true)
|
| | | {
|
| | | //重复文件不再上传
|
| | | continue;
|
| | | }
|
| | | listCheckFile.Add(fileName);
|
| | | }
|
| | | if (fileName.EndsWith(".png") == true)
|
| | | {
|
| | | //上传图片
|
| | | var result = this.UpLoadBigBackupFileToDB(memberShardInfo, fileName);
|
| | | if (result == null)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //这里有点特殊,接口是直接返回主键回来的,而不是Jsoin
|
| | | dicKeys[fileName] = result;
|
| | | }
|
| | | else
|
| | | {
|
| | | info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
|
| | | var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info);
|
| | | if (result == false)
|
| | | var info = new UploadShardContent();
|
| | | info.SubAccountDistributedMark = memberShardInfo.SubAccountDistributedMark;
|
| | | info.ShareName = fileName;
|
| | | info.ShareDataBytes = HdlShardLogic.Current.GetShardFileContent(fileName);
|
| | |
|
| | | //追加共享
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
|
| | | {
|
| | | return false;
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //这里有点特殊,接口是直接返回主键回来的,而不是Jsoin
|
| | | dicKeys[fileName] = result;
|
| | | }
|
| | | dicKeys[fileName] = info.DistributedMark;
|
| | | else
|
| | | {
|
| | | info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
|
| | | var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | dicKeys[fileName] = info.DistributedMark;
|
| | | }
|
| | | }
|
| | | //设置进度值
|
| | | ProgressBar.SetValue(1);
|
| | | }
|
| | | //如果没有错误,则添加临时缓存
|
| | | var listShard = memberShardInfo.dicAllMemberShard[nowRoom.FileName];
|
| | | foreach (var keys in dicKeys.Keys)
|
| | | {
|
| | | if (listShard.Contains(keys) == false)
|
| | | {
|
| | | listShard.Add(keys);
|
| | | }
|
| | | memberShardInfo.dicAllShardKeys[keys] = dicKeys[keys];
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 上传图片文件到云端
|
| | | /// </summary>
|
| | | /// <param name="fullDir">文件夹的全路径</param>
|
| | | /// <param name="listPicFile">图片文件列表</param>
|
| | | /// <returns></returns>
|
| | | private string UpLoadBigBackupFileToDB(MemberShardInfoData memberShardInfo, string fileName)
|
| | | {
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var nvc = new NameValueCollection();
|
| | | nvc.Add("ShareName", fileName);
|
| | | nvc.Add("HouseDistributedMark", Common.Config.Instance.Home.Id);
|
| | | nvc.Add("SubAccountDistributedMark", memberShardInfo.SubAccountDistributedMark);
|
| | | nvc.Add("ShareDataBytes", Convert.ToBase64String(this.GetShardFileContent(fileName)));
|
| | | nvc.Add("IsOtherAccountCtrl", Common.Config.Instance.isAdministrator.ToString());
|
| | |
|
| | | //追加共享
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
|
| | | {
|
| | | var result = this.UpLoadBigBackupFileToDB("ZigbeeDataShare/AddShareData", fullName, nvc);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | //这里有点特殊,接口是直接返回主键回来的,而不是Jsoin
|
| | | return result;
|
| | | }
|
| | | else
|
| | | {
|
| | | nvc.Add("DistributedMark", memberShardInfo.dicAllShardKeys[fileName]);
|
| | | var result = this.UpLoadBigBackupFileToDB("ZigbeeDataShare/EditShareData", fullName, nvc);
|
| | | if (result != "1")
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return memberShardInfo.dicAllShardKeys[fileName];
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 上传大文件
|
| | | /// </summary>
|
| | | /// <param name="RequestName">请求接口</param>
|
| | | /// <param name="fullFileName">文件名字(含路径)</param>
|
| | | /// <param name="nvc"></param>
|
| | | /// <returns></returns>
|
| | | private string UpLoadBigBackupFileToDB(string RequestName, string fullFileName, NameValueCollection nvc)
|
| | | {
|
| | | string paramName = "file";
|
| | | string contentType = "application/octet-stream";
|
| | | string requestUrl = $"{CommonPage.RequestHttpsHost}/{RequestName}";
|
| | | //启用管理员权限
|
| | | //if (Config.Instance.isAdministrator == true)
|
| | | //{
|
| | | // requestUrl = $"{Config.Instance.AdminRequestBaseUrl}/{RequestName}";
|
| | | //}
|
| | | //else
|
| | | //{
|
| | | // requestUrl = $"{CommonPage.RequestHttpsHost}/{RequestName}";
|
| | | //}
|
| | |
|
| | | string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
|
| | | byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
|
| | |
|
| | | var wr = (HttpWebRequest)WebRequest.Create(requestUrl);
|
| | | wr.ContentType = "multipart/form-data; boundary=" + boundary;
|
| | | wr.Method = "POST";
|
| | | wr.KeepAlive = true;
|
| | | wr.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
| | |
|
| | | var rs = wr.GetRequestStream();
|
| | |
|
| | | string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
|
| | | foreach (string key in nvc.Keys)
|
| | | {
|
| | | rs.Write(boundarybytes, 0, boundarybytes.Length);
|
| | | string formitem = string.Format(formdataTemplate, key, nvc[key]);
|
| | | byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
|
| | | rs.Write(formitembytes, 0, formitembytes.Length);
|
| | | }
|
| | | rs.Write(boundarybytes, 0, boundarybytes.Length);
|
| | |
|
| | | string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
|
| | | string header = string.Format(headerTemplate, paramName, fullFileName, contentType);
|
| | | byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
|
| | | rs.Write(headerbytes, 0, headerbytes.Length);
|
| | |
|
| | | var fileStream = new FileStream(fullFileName, FileMode.Open, FileAccess.Read);
|
| | | byte[] buffer = new byte[4096];
|
| | | int bytesRead = 0;
|
| | | while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
|
| | | {
|
| | | rs.Write(buffer, 0, bytesRead);
|
| | | }
|
| | | fileStream.Close();
|
| | |
|
| | | byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
|
| | | rs.Write(trailer, 0, trailer.Length);
|
| | | rs.Close();
|
| | |
|
| | | WebResponse wresp = null;
|
| | | try
|
| | | {
|
| | | wresp = wr.GetResponse();
|
| | | Stream stream2 = wresp.GetResponseStream();
|
| | | StreamReader reader2 = new StreamReader(stream2);
|
| | |
|
| | | string result = reader2.ReadToEnd();
|
| | | if (RequestName == "ZigbeeDataShare/AddShareData")
|
| | | {
|
| | | return result;
|
| | | }
|
| | |
|
| | | var data = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(result);
|
| | |
|
| | | bool flage = UserCenterLogic.CheckNotEorrorMsg(data, requestUrl);
|
| | | if (flage == true)
|
| | | {
|
| | | return "1";
|
| | | }
|
| | | return "0";
|
| | | }
|
| | | catch
|
| | | {
|
| | | return "-1";
|
| | | }
|
| | | finally
|
| | | {
|
| | | if (wresp != null)
|
| | | {
|
| | | wresp.Close();
|
| | | wresp = null;
|
| | | }
|
| | | wr = null;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | foreach (string fileName in listFile)
|
| | | {
|
| | | //生成的文件全部删除,房间文件的话,下面会重新生成
|
| | | HdlShardLogic.Current.DeleteShardFile(fileName);
|
| | | this.DeleteShardFile(fileName);
|
| | | }
|
| | |
|
| | | foreach (var roomKeys in memberShardInfo.dicShardRoom.Keys)
|
| | |
| | | memberShardInfo.dicShardRoom[roomKeys].SceneUIFilePathList.AddRange(dicBackScene[roomKeys]);
|
| | |
|
| | | //覆盖房间文件
|
| | | HdlShardLogic.Current.AddShardFile(memberShardInfo.dicShardRoom[roomKeys]);
|
| | | this.AddShardFile(memberShardInfo.dicShardRoom[roomKeys]);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | var listMark = new List<string>();
|
| | | //要删除的文件名字
|
| | | var listDeleteFile = new List<string>();
|
| | | //这个是只移除缓存的文件名字
|
| | | var listDeleteFileEx = new List<string>();
|
| | | //云端的指定房间的共享文件列表
|
| | | var dicShardFile = memberShardInfo.dicAllMemberShard[nowRoom.FileName];
|
| | |
|
| | | //除了要删除的目标外,还分享的数据
|
| | | var listHadShard = this.GetAllShardedFileNameFromDictionary(memberShardInfo, nowRoom, listDevice, listSceneUI);
|
| | |
|
| | |
| | | roomTemp.DeviceUIFilePathList.Remove($"DeviceUI_{device.FilePath}");
|
| | | if (listHadShard.Contains(deviceFileName) == true)
|
| | | {
|
| | | //其他房间分享有这个设备,所以不删除这个设备的根源文件,只是把房间的设备列表路径移除
|
| | | listDeleteFileEx.Add(deviceFileName);
|
| | | //其他场景分享有这个设备,所以不删除这个设备的根源文件,只是把房间的设备列表路径移除
|
| | | continue;
|
| | | }
|
| | |
|
| | | //设备主键
|
| | | if (dicShardFile.Contains(deviceFileName) == true)
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(deviceFileName) == true)
|
| | | {
|
| | | listMark.Add(memberShardInfo.dicAllShardKeys[deviceFileName]);
|
| | | }
|
| | |
| | | //但是它绑定的设备目标要删除
|
| | | if (listHadShard.Contains(sceneUI.FileName) == true)
|
| | | {
|
| | | listDeleteFileEx.Add(sceneUI.FileName);
|
| | | continue;
|
| | | }
|
| | | else
|
| | | //获取要删除的分享主键
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(sceneUI.FileName) == true)
|
| | | {
|
| | | //获取要删除的分享主键
|
| | | if (dicShardFile.Contains(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[sceneUI.FileName]);
|
| | | listMark.Add(memberShardInfo.dicAllShardKeys[sceneFile]);
|
| | | }
|
| | | listDeleteFile.Add(sceneUI.FileName);
|
| | | }
|
| | |
|
| | | //执行删除嵌套的设备
|
| | | var listTemp = new HashSet<string>();
|
| | | this.GetSceneBindFileName(sceneUI, ref listTemp);
|
| | | var dicBindScene = new Dictionary<string, SceneUI>();
|
| | | this.GetSceneBindFileName(sceneUI, ref listTemp, ref dicBindScene);
|
| | | foreach (var fileName in listTemp)
|
| | | {
|
| | | if (listHadShard.Contains(fileName) == true)
|
| | |
| | | continue;
|
| | | }
|
| | | //获取要删除的分享主键
|
| | | if (dicShardFile.Contains(fileName) == true)
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == true)
|
| | | {
|
| | | listMark.Add(memberShardInfo.dicAllShardKeys[fileName]);
|
| | | }
|
| | | listDeleteFile.Add(fileName);
|
| | |
|
| | | if (dicBindScene.ContainsKey(fileName) == true && dicBindScene[fileName].IconPathType != 0)
|
| | | {
|
| | | //删除自定义场景图片,它存在于本地,但是它是全路径
|
| | | string[] Arry = dicBindScene[fileName].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.DeviceUIFilePathList.Count == 0 && roomTemp.SceneUIFilePathList.Count == 0)
|
| | | {
|
| | | listMark.Add(memberShardInfo.dicAllShardKeys[nowRoom.FileName]);
|
| | | //房间删除
|
| | | 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]);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //执行移除分享数据
|
| | |
| | | //同步房间文件
|
| | | if (result == true && listDeleteFile.Contains(roomTemp.FileName) == false)
|
| | | {
|
| | | //执行上传对象
|
| | | //执行上传房间对象
|
| | | result = await this.DoUploadRoomObject(memberShardInfo, roomTemp);
|
| | | }
|
| | | if (result == true)
|
| | | //同步楼层数据
|
| | | if (result == true && listDeleteFile.Contains(roomTemp.FileName) == true)
|
| | | {
|
| | | foreach (var exFile in listDeleteFileEx)
|
| | | int floorCount = 0;
|
| | | foreach (var myRoom in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //只移除缓存,不删除云端
|
| | | if (dicShardFile.Contains(exFile) == true)
|
| | | {
|
| | | dicShardFile.Remove(exFile);
|
| | | }
|
| | | if (myRoom.FloorId == roomTemp.FloorId) { floorCount++; }
|
| | | }
|
| | | if (floorCount == 0)
|
| | | {
|
| | | //如果该楼层已经删完房间了,则更新楼层
|
| | | memberShardInfo.dicShardFloor.Remove(roomTemp.FloorId);
|
| | | //执行上传对象
|
| | | result = await this.DoUploadFloorObject(memberShardInfo);
|
| | | }
|
| | |
|
| | | }
|
| | | else
|
| | |
|
| | | if (result == false)
|
| | | {
|
| | | //恢复
|
| | | roomTemp.DeviceUIFilePathList.Clear();
|
| | |
| | | }
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | |
|
| | | var dicShard = memberShardInfo.dicAllMemberShard[nowRoom.FileName];
|
| | | ;
|
| | | for (int i = 0; i < listDeleteFile.Count; i++)
|
| | | {
|
| | | string fileName = listDeleteFile[i];
|
| | |
| | | {
|
| | | //最后一个固定可能是房间文件,直接移除整个对象
|
| | | memberShardInfo.dicShardRoom.Remove(fileName);
|
| | | memberShardInfo.dicAllMemberShard.Remove(fileName);
|
| | | }
|
| | | else
|
| | | {
|
| | | //移除指定文件
|
| | | dicShard.Remove(fileName);
|
| | | }
|
| | | memberShardInfo.dicAllShardKeys.Remove(fileName);
|
| | |
|
| | | HdlShardLogic.Current.DeleteShardFile(fileName);
|
| | | this.DeleteShardFile(fileName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 执行移除分享数据
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享内容</param>
|
| | | /// <param name="listDelFile">删除的文件</param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listDelFile)
|
| | | {
|
| | | if (listDelFile.Count == 0)
|
| | | {
|
| | | return true;
|
| | | }
|
| | |
|
| | | var info = new DeleteShardInfo();
|
| | | foreach (var fileName in listDelFile)
|
| | | {
|
| | | if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
|
| | | {
|
| | | //我也不知道为什么会找不到主键
|
| | | continue;
|
| | | }
|
| | |
|
| | | info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
|
| | | //执行删除
|
| | | var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | }
|
| | | for (int i = 0; i < listDelFile.Count; i++)
|
| | | {
|
| | | string fileName = listDelFile[i];
|
| | | memberShardInfo.dicAllShardKeys.Remove(fileName);
|
| | |
|
| | | this.DeleteShardFile(fileName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
| | | /// <returns></returns>
|
| | | private async Task<bool> DoUploadRoomObject(MemberShardInfoData memberShardInfo, Common.Room upDateRoom)
|
| | | {
|
| | | if (upDateRoom.Id == "Other")
|
| | | {
|
| | | return true;
|
| | | }
|
| | | var info = new EditorShardContent();
|
| | | info.DistributedMark = memberShardInfo.dicAllShardKeys[upDateRoom.FileName];
|
| | | info.ShareName = upDateRoom.FileName;
|
| | |
| | | return false;
|
| | | }
|
| | | //将房间对象序列化到缓存
|
| | | HdlShardLogic.Current.AddShardFile(upDateRoom);
|
| | | this.AddShardFile(upDateRoom);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 上传楼层对象_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 上传楼层对象
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的共享内容</param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> DoUploadFloorObject(MemberShardInfoData memberShardInfo)
|
| | | {
|
| | | var info = new EditorShardContent();
|
| | | info.DistributedMark = memberShardInfo.dicAllShardKeys[DirNameResourse.ShardFloorFile];
|
| | | info.ShareName = DirNameResourse.ShardFloorFile;
|
| | | info.SubAccountDistributedMark = memberShardInfo.SubAccountDistributedMark;
|
| | |
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(memberShardInfo.dicShardFloor);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | info.ShareDataBytes = byteData;
|
| | | var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //将房间对象序列化到缓存
|
| | | this.AddShardFile(memberShardInfo.dicShardFloor);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | //获取还处于分享状态的文件
|
| | | foreach (var roomTemp in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | bool flage = roomTemp.FileName == nowRoom.FileName;
|
| | | //设备
|
| | | foreach (var deviceUi in roomTemp.DeviceUIFilePathList)
|
| | | {
|
| | | string deviceFile = deviceUi.Replace("DeviceUI_", string.Empty);
|
| | | if (flage == true && listDeleteFile.Contains(deviceFile) == true)
|
| | | if (listDeleteFile.Contains(deviceFile) == true)
|
| | | {
|
| | | //当前房间的要特殊处理,如果是删除目标,则不添加
|
| | | //因为一个回路只能分配一个区域,所以可以直接判断
|
| | | continue;
|
| | | }
|
| | | if (listShardFile.Contains(deviceFile) == false)
|
| | | {
|
| | | //这个文件还分享着
|
| | | listShardFile.Add(deviceFile);
|
| | | }
|
| | |
|
| | | }
|
| | | //场景
|
| | | foreach (var scene in roomTemp.SceneUIList)
|
| | |
| | | //这个场景已经被删除
|
| | | continue;
|
| | | }
|
| | | if (flage == true && listDeleteFile.Contains(scene.FileName) == true)
|
| | | if (roomTemp.FileName == nowRoom.FileName)
|
| | | {
|
| | | //当前房间的要特殊处理,如果是删除目标,则不添加
|
| | | continue;
|
| | | //如果循环到了当前房间
|
| | | if (listDeleteFile.Contains(scene.FileName) == true)
|
| | | {
|
| | | //如果是删除目标,则不添加
|
| | | continue;
|
| | | }
|
| | | }
|
| | | //获取场景里面的全部目标
|
| | | var listTemp = new HashSet<string>();
|
| | | this.GetSceneBindFileName(scene, ref listTemp);
|
| | | var dicTemp = new Dictionary<string, SceneUI>();
|
| | | this.GetSceneBindFileName(scene, ref listTemp, ref dicTemp);
|
| | |
|
| | | if (listShardFile.Contains(scene.FileName) == false)
|
| | | {
|
| | |
| | | /// </summary>
|
| | | /// <param name="scene">场景</param>
|
| | | /// <param name="listFile">文件列表(里面存的是设备UI文件和设备文件和场景文件)</param>
|
| | | private void GetSceneBindFileName(Common.SceneUI scene, ref HashSet<string> listFile)
|
| | | /// <param name="dicBindScene">绑定的场景对象</param>
|
| | | private void GetSceneBindFileName(Common.SceneUI scene, ref HashSet<string> listFile,ref Dictionary<string, SceneUI> dicBindScene)
|
| | | {
|
| | | foreach (var data in scene.AddSceneMemberDataList)
|
| | | {
|
| | |
| | | if (data.Type == 0)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
|
| | | if (device != null&& listFile.Contains(device.FilePath) == false)
|
| | | if (device != null && listFile.Contains(device.FilePath) == false)
|
| | | {
|
| | | listFile.Add(device.FilePath);
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | | {
|
| | | var sceneTemp = Room.CurrentRoom.GetSceneUIBySceneId(data.ElseScenesId);
|
| | | if (sceneTemp != null && listFile.Contains(sceneTemp.FileName))
|
| | | var temp = new SceneUI();
|
| | | temp.Id = data.ElseScenesId;
|
| | | var byteData = this.GetShardFileContent(temp.FileName);
|
| | | if (byteData != null)
|
| | | {
|
| | | listFile.Add(sceneTemp.FileName);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | if (roomTemp != null)
|
| | | {
|
| | | dicBindScene[roomTemp.FileName] = roomTemp;
|
| | | if (listFile.Contains(roomTemp.FileName) == false)
|
| | | {
|
| | | listFile.Add(roomTemp.FileName);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | public string SubAccountDistributedMark = string.Empty;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 接收分享数据
|
| | | /// </summary>
|
| | | private class ReceiveShardInfoResult
|
| | | {
|
| | | /// <summary>
|
| | | /// 文件名字
|
| | | /// </summary>
|
| | | public string ShareName = string.Empty;
|
| | | /// <summary>
|
| | | /// 主键
|
| | | /// </summary>
|
| | | public string DistributedMark = string.Empty;
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|