xm
2020-07-14 d87400af518ebc9274f4447f06476959c3aa5102
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs
@@ -5,7 +5,6 @@
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
@@ -53,7 +52,7 @@
        /// </summary>
        /// <param name="listDistributedMark"></param>
        /// <returns></returns>
        private async Task<List<string>> SetShardFileToLocation(List<string> listDistributedMark)
        private List<string> SetShardFileToLocation(List<string> listDistributedMark)
        {
            if (listDistributedMark.Count == 0)
            {
@@ -63,7 +62,7 @@
            List<string> listFile = new List<string>();
            //文件夹
            string strDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
            string strDir = DirNameResourse.DownLoadShardDirectory;
            //不允许按系统的返回键
            Shared.Common.CommonPage.BackKeyCanClick = false;
@@ -73,8 +72,8 @@
            {
                string keys = listDistributedMark[i];
                var dataPra = new { DistributedMark = keys, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
                var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetOneShareData", false, dataPra);
                if (result == null)
                var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetOneShareData", false, dataPra, null, true);
                if (string.IsNullOrEmpty(result) == true)
                {
                    //允许按系统的返回键
                    Shared.Common.CommonPage.BackKeyCanClick = true;
@@ -85,7 +84,7 @@
                //文件名字
                listFile.Add(dataResult.ShareName);
                //保存到指定文件夹下
                Global.WriteFileToDirectoryByBytes(strDir, dataResult.ShareName, dataResult.ShareDataBytes);
                HdlFileLogic.Current.SaveTextToFile(System.IO.Path.Combine(strDir, dataResult.ShareName), System.Text.Encoding.UTF8.GetString(dataResult.ShareDataBytes));
                //设置进度值
                ProgressFormBar.Current.SetValue(i + 1, listMarkCount);
            }
@@ -104,13 +103,13 @@
        /// <returns></returns>
        public byte[] GetShardFileContent(string fileName)
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
            }
            string path = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
            var varByte = Global.ReadFileByDirectory(path, fileName);
            string path = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            var varByte = HdlFileLogic.Current.ReadFileByteContent(path);
            return varByte;
        }
@@ -120,10 +119,7 @@
        /// <returns></returns>
        public List<string> GetLocalAllShardFile()
        {
            string path = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
            var listFile = HdlAutoBackupLogic.GetFileFromDirectory(path);
            return listFile;
            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.DownLoadShardDirectory);
        }
        /// <summary>
@@ -133,7 +129,7 @@
        /// <returns></returns>
        public bool IsFileExists(string fileName)
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fullName) == false)
            {
                return false;
@@ -155,9 +151,9 @@
            {
                return;
            }
            string oldName = UserCenterLogic.CombinePath(fileName);
            string newName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
            System.IO.File.Copy(oldName, newName, true);
            string oldName = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
            string newName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            HdlFileLogic.Current.CopyFile(oldName, newName);
        }
        /// <summary>
@@ -167,12 +163,9 @@
        public void AddShardFile(Common.Room room)
        {
            room.IsSharedRoom = true;
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(room);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, room.FileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, room.FileName);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
            HdlFileLogic.Current.SaveFileContent(fullName, room);
        }
        /// <summary>
@@ -182,12 +175,9 @@
        public void AddShardFile(Common.SceneUI scene)
        {
            scene.IsSharedScene = true;
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(scene);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, scene.FileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, scene.FileName);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
            HdlFileLogic.Current.SaveFileContent(fullName, scene);
        }
        /// <summary>
@@ -196,12 +186,9 @@
        /// <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);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, DirNameResourse.ShardFloorFile);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
            HdlFileLogic.Current.SaveFileContent(fullName, dic);
        }
        #endregion
@@ -214,11 +201,8 @@
        /// <param name="fileName">指定文件名字</param>
        public void DeleteShardFile(string fileName)
        {
            fileName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fileName) == true)
            {
                System.IO.File.Delete(fileName);
            }
            fileName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            HdlFileLogic.Current.DeleteFile(fileName);
        }
        /// <summary>
@@ -228,8 +212,7 @@
        {
            this.dicShardDeviceFile.Clear();
            //创建文件夹
            string strDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
            Global.CreateEmptyDirectory(strDir, true);
            HdlFileLogic.Current.CreateDirectory(DirNameResourse.DownLoadShardDirectory, true);
        }
        #endregion
@@ -239,7 +222,7 @@
        /// <summary>
        /// 同步服务器的分享内容(里面只负责把东西存入本地)
        /// </summary>
        public async Task<bool> SynchronizeDbSharedContent()
        public bool SynchronizeDbSharedContent()
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
@@ -249,8 +232,7 @@
            //获取主人分享给成员的文件列表
            var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
            var listNotShow = new List<string>() { "NotSetAgain" };
            var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra, listNotShow);
            var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (string.IsNullOrEmpty(result) == true)
            {
                return false;
@@ -291,7 +273,7 @@
                //将分享的数据存入本地(获取的是本地没有的)
                this.ClearShardDirectory();
                var listDbFile = await this.SetShardFileToLocation(listAddMark);
                var listDbFile = this.SetShardFileToLocation(listAddMark);
                if (listDbFile == null)
                {
                    //关闭
@@ -302,22 +284,16 @@
                //生成文件
                foreach (string fileName in listDbFile)
                {
                    var oldPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
                    var oldPath = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
                    var newPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
                    System.IO.File.Copy(oldPath, newPath, true);
                    if (fileName.StartsWith("Room_") == true)
                    {
                        //房间文件特殊处理
                        Config.Instance.Home.AddRoomId(fileName.Replace("Room_", string.Empty).Replace(".json", string.Empty));
                    }
                    HdlFileLogic.Current.CopyFile(oldPath, newPath);
                }
                //清空共享文件夹
                this.ClearShardDirectory();
            }
            //同步服务器的取消了的分享内容
            return await this.SynchronizeDeleteSharedContent(listShardFile, dicUpdateTime);
            return this.SynchronizeDeleteSharedContent(listShardFile, dicUpdateTime);
        }
        /// <summary>
@@ -326,7 +302,7 @@
        /// <param name="listShardFile">云端上面分享的文件,为Null时从新获取</param>
        /// <param name="dicUpdateTime">分享文件的更新时间,为Null时从新获取</param>
        /// <returns></returns>
        public async Task<bool> SynchronizeDeleteSharedContent(HashSet<string> listShardFile = null, Dictionary<string, string> dicUpdateTime = null)
        public bool SynchronizeDeleteSharedContent(HashSet<string> listShardFile = null, Dictionary<string, string> dicUpdateTime = null)
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
@@ -349,8 +325,7 @@
                listShardFile = new HashSet<string>();
                //获取主人分享给成员的文件列表
                var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
                var listNotShow = new List<string>() { "NotSetAgain" };
                var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra, listNotShow);
                var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
                if (string.IsNullOrEmpty(result) == true)
                {
                    //关闭
@@ -368,7 +343,7 @@
            //清空楼层数据
            Common.Config.Instance.Home.FloorDics.Clear();
            //然后检测本地的文件
            var listLocalFile = Global.FileListByHomeId();
            var listLocalFile = HdlFileLogic.Current.GetRootPathListFile();
            foreach (string fileName in listLocalFile)
            {
                if (fileName == DirNameResourse.ShardFloorFile)
@@ -408,8 +383,6 @@
                    //删除掉这个房间文件
                    Global.DeleteFilebyHomeId(fileName);
                    dicUpdateTime.Remove(fileName);
                    Config.Instance.Home.RemoveRoomId(nowRoom.Id);
                }
                //检测本地场景文件,是否存在已经取消了共享了的
                else if (fileName.StartsWith("Scene_") == true)
@@ -451,7 +424,7 @@
        private Dictionary<string, string> GetAllShardFileAgoUpdateTime()
        {
            var dicTime = new Dictionary<string, string>();
            var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ShardFileUpdateTimeFile);
            var data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.ShardFileUpdateTimeFile);
            if (data == null)
            {
                //目标文件不存在
@@ -467,9 +440,7 @@
        /// <param name="dicTime"></param>
        private void SaveAllShardFileAgoUpdateTime(Dictionary<string, string> dicTime)
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(dicTime);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.ShardFileUpdateTimeFile, byteData);
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.ShardFileUpdateTimeFile, dicTime);
        }
        #endregion
@@ -487,7 +458,7 @@
        /// <para>New的时候记得对SubAccountDistributedMark赋值,它是成员列表接口返回的SubAccountDistributedMark</para>
        /// </param>
        /// <returns></returns>
        public async Task<bool> GetMemberShardContentListAndSetToLocation(MemberShardInfoData memberShardInfo)
        public bool GetMemberShardContentListAndSetToLocation(MemberShardInfoData memberShardInfo)
        {
            if (memberShardInfo.Refresh == false)
            {
@@ -507,8 +478,8 @@
                HouseDistributedMark = Shared.Common.Config.Instance.HomeId,
                IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare
            };
            var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (result == null)
            var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (string.IsNullOrEmpty(result) == true)
            {
                //关闭进度条
                ProgressFormBar.Current.Close();
@@ -542,7 +513,7 @@
            }
            //将分享的数据存入本地,返回的是文件名字(异常时返回null)
            var listFile = await this.SetShardFileToLocation(listMark);
            var listFile = this.SetShardFileToLocation(listMark);
            if (listFile == null)
            {
                //关闭进度条
@@ -736,7 +707,7 @@
        /// <param name="listScene">选择上传的场景(不要获取它里面的绑定列表)</param>
        /// <param name="BarMaxValue">进度条的最大值,如果不为-1,则内部不会自动弹出进度条</param>
        /// <param name="listCheckFile">文件重复上传检测</param>
        public async Task<bool> DoUploadSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
        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)
@@ -790,11 +761,11 @@
            }
            //上传分享
            var result = await this.DoUploadShardContent(memberShardInfo, listFile, listCheckFile);
            var result = this.DoUploadShardContent(memberShardInfo, listFile, listCheckFile);
            if (result == true)
            {
                //删除指定自定义图片
                result = await this.DoDeleteSharedContent(memberShardInfo, listDelPic);
                result = this.DoDeleteSharedContent(memberShardInfo, listDelPic);
            }
            if (BarMaxValue == -1)
            {
@@ -1008,7 +979,7 @@
        /// <param name="listFile">上传的文件名</param>
        /// <param name="listCheckFile">重复文件上传检测</param>
        /// <returns></returns>
        private async Task<bool> DoUploadShardContent(MemberShardInfoData memberShardInfo, List<string> listFile, HashSet<string> listCheckFile)
        private bool DoUploadShardContent(MemberShardInfoData memberShardInfo, List<string> listFile, HashSet<string> listCheckFile)
        {
            var dicKeys = new Dictionary<string, string>();
            for (int i = 0; i < listFile.Count; i++)
@@ -1043,8 +1014,8 @@
                    //追加共享
                    if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
                    {
                        var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info);
                        if (result == null)
                        var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info, null, true);
                        if (string.IsNullOrEmpty(result) == true)
                        {
                            return false;
                        }
@@ -1054,7 +1025,7 @@
                    else
                    {
                        info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
                        var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info);
                        var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
                        if (result == false)
                        {
                            return false;
@@ -1082,7 +1053,7 @@
        /// <returns></returns>
        private string UpLoadBigBackupFileToDB(MemberShardInfoData memberShardInfo, string fileName)
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory, fileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
@@ -1275,7 +1246,7 @@
        /// <param name="listDevice">要取消的设备</param>
        /// <param name="listSceneUI">要取消的场景</param>
        /// <returns></returns>
        public async Task<bool> DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
        public bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
            List<CommonDevice> listDevice, List<SceneUI> listSceneUI)
        {
            var roomTemp = memberShardInfo.dicShardRoom[nowRoom.FileName];
@@ -1312,7 +1283,6 @@
                }
                listDeleteFile.Add(device.FilePath);
            }
            //再弄场景
            foreach (var sceneUI in listSceneUI)
            {
@@ -1404,12 +1374,12 @@
            }
            //执行移除分享数据
            var result = await this.DoDeleteSharedContent(memberShardInfo, nowRoom, listMark, listDeleteFile);
            var result = this.DoDeleteSharedContent(memberShardInfo, nowRoom, listMark, listDeleteFile);
            //同步房间文件
            if (result == true && listDeleteFile.Contains(roomTemp.FileName) == false)
            {
                //执行上传房间对象
                result = await this.DoUploadRoomObject(memberShardInfo, roomTemp);
                result = this.DoUploadRoomObject(memberShardInfo, roomTemp);
            }
            //同步楼层数据
            if (result == true && listDeleteFile.Contains(roomTemp.FileName) == true)
@@ -1428,7 +1398,7 @@
                    //如果该楼层已经删完房间了,则更新楼层
                    memberShardInfo.dicShardFloor.Remove(roomTemp.FloorId);
                    //执行上传对象
                    result = await this.DoUploadFloorObject(memberShardInfo);
                    result = this.DoUploadFloorObject(memberShardInfo);
                }
            }
@@ -1456,7 +1426,7 @@
        /// <param name="listMark">要移除的主键</param>
        /// <param name="listDeleteFile">要删除的文件(房间文件需要删除的话,必须放在最后)</param>
        /// <returns></returns>
        private async Task<bool> DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
        private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
            List<string> listMark, List<string> listDeleteFile)
        {
            if (listMark.Count == 0)
@@ -1477,7 +1447,7 @@
                info.DistributedMark = markKeys;
                //执行删除
                var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info);
                var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info, null, true);
                if (result == false)
                {
                    //关闭进度条
@@ -1508,7 +1478,7 @@
        /// <param name="memberShardInfo">成员的分享内容</param>
        /// <param name="listDelFile">删除的文件</param>
        /// <returns></returns>
        private async Task<bool> DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listDelFile)
        private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listDelFile)
        {
            if (listDelFile.Count == 0)
            {
@@ -1526,7 +1496,7 @@
                info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
                //执行删除
                var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info);
                var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info, null, true);
                if (result == false)
                {
                    return false;
@@ -1552,7 +1522,7 @@
        /// <param name="memberShardInfo">成员的共享内容</param>
        /// <param name="upDateRoom">需要上传到云端的房间对象</param>
        /// <returns></returns>
        private async Task<bool> DoUploadRoomObject(MemberShardInfoData memberShardInfo, Common.Room upDateRoom)
        private bool DoUploadRoomObject(MemberShardInfoData memberShardInfo, Common.Room upDateRoom)
        {
            if (upDateRoom.Id == "Other")
            {
@@ -1566,7 +1536,7 @@
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(upDateRoom);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            info.ShareDataBytes = byteData;
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info);
            var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
            if (result == false)
            {
                return false;
@@ -1586,7 +1556,7 @@
        /// </summary>
        /// <param name="memberShardInfo">成员的共享内容</param>
        /// <returns></returns>
        private async Task<bool> DoUploadFloorObject(MemberShardInfoData memberShardInfo)
        private bool DoUploadFloorObject(MemberShardInfoData memberShardInfo)
        {
            var info = new EditorShardContent();
            info.DistributedMark = memberShardInfo.dicAllShardKeys[DirNameResourse.ShardFloorFile];
@@ -1596,7 +1566,7 @@
            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);
            var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
            if (result == false)
            {
                return false;