HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-14 e90209beae6a4e822cecb18e6889f8bda23f630e
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs
File was renamed from ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs
@@ -7,7 +7,7 @@
using System.Text;
using ZigBee.Device;
namespace Shared.Phone
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 分享的逻辑
@@ -50,60 +50,57 @@
        /// <summary>
        /// 将分享的数据存入本地,返回的是文件名字(异常时返回null),调用 GetShardFileContent 可以获取文件内的内容
        /// </summary>
        /// <param name="dicFileKeys">key:文件的主键 value:文件名称</param>
        /// <param name="listDistributedMark"></param>
        /// <returns></returns>
        private List<string> SetShardFileToLocation(Dictionary<string, string> dicFileKeys)
        private List<string> SetShardFileToLocation(List<string> listDistributedMark)
        {
            if (dicFileKeys.Count == 0)
            if (listDistributedMark.Count == 0)
            {
                return new List<string>();
            }
            int listMarkCount = dicFileKeys.Count;
            int listMarkCount = listDistributedMark.Count;
            List<string> listFile = new List<string>();
            //文件夹
            string strDir = HdlFileNameResourse.DownLoadShardDirectory;
            string strDir = DirNameResourse.DownLoadShardDirectory;
            //不允许按系统的返回键
            Config.Instance.BackKeyCanClick = false;
            HdlUserCenterResourse.AccountOption.AppCanSignout = false;
            Shared.Common.CommonPage.BackKeyCanClick = false;
            UserCenterResourse.AccountOption.AppCanSignout = false;
            //计数
            int nowCount = 0;
            foreach (var fileKey in dicFileKeys.Keys)
            for (int i = 0; i < listDistributedMark.Count; i++)
            {
                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)
                string keys = listDistributedMark[i];
                var dataPra = new { DistributedMark = keys, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
                var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetOneShareData", false, dataPra, null, true);
                if (string.IsNullOrEmpty(result) == true)
                {
                    //允许按系统的返回键
                    Config.Instance.BackKeyCanClick = true;
                    HdlUserCenterResourse.AccountOption.AppCanSignout = true;
                    Shared.Common.CommonPage.BackKeyCanClick = true;
                    UserCenterResourse.AccountOption.AppCanSignout = true;
                    return null;
                }
                var dataResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetShardInfoResult>(result);
                //对应旧版本的设备文件 Device_OnoffOutput_abcdfrtgg_01
                string shareName = dicFileKeys[fileKey];
                if (shareName.StartsWith("Device_") == true)
                if (dataResult.ShareName.StartsWith("Device_") == true)
                {
                    var strArry = shareName.Split(new string[] { "_" }, StringSplitOptions.None);
                    var strArry = dataResult.ShareName.Split(new string[] { "_" }, StringSplitOptions.None);
                    if (strArry.Length == 4)
                    {
                        shareName = strArry[0] + "_" + strArry[2] + "_" + strArry[3];
                        dataResult.ShareName = strArry[0] + "_" + strArry[2] + "_" + strArry[3];
                    }
                }
                //文件名字
                listFile.Add(shareName);
                listFile.Add(dataResult.ShareName);
                //保存到指定文件夹下
                HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(strDir, shareName), result);
                HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(strDir, dataResult.ShareName), dataResult.ShareDataBytes);
                //设置进度值
                ProgressFormBar.Current.SetValue(nowCount, listMarkCount);
                ProgressFormBar.Current.SetValue(i + 1, listMarkCount);
            }
            //允许按系统的返回键
            Config.Instance.BackKeyCanClick = true;
            HdlUserCenterResourse.AccountOption.AppCanSignout = true;
            Shared.Common.CommonPage.BackKeyCanClick = true;
            UserCenterResourse.AccountOption.AppCanSignout = true;
            return listFile;
        }
@@ -115,12 +112,12 @@
        /// <returns></returns>
        public byte[] GetShardFileContent(string fileName)
        {
            string fullName = System.IO.Path.Combine(HdlFileNameResourse.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(HdlFileNameResourse.DownLoadShardDirectory, fileName);
            string path = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            var varByte = HdlFileLogic.Current.ReadFileByteContent(path);
            return varByte;
        }
@@ -131,7 +128,7 @@
        /// <returns></returns>
        public List<string> GetLocalAllShardFile()
        {
            return HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.DownLoadShardDirectory);
            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.DownLoadShardDirectory);
        }
        /// <summary>
@@ -141,7 +138,7 @@
        /// <returns></returns>
        public bool IsFileExists(string fileName)
        {
            string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fullName) == false)
            {
                return false;
@@ -164,7 +161,7 @@
                return;
            }
            string oldName = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
            string newName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
            string newName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            HdlFileLogic.Current.CopyFile(oldName, newName);
        }
@@ -175,7 +172,7 @@
        public void AddShardFile(Common.Room room)
        {
            room.IsSharedRoom = true;
            string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, room.FileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, room.FileName);
            //写入内容
            HdlFileLogic.Current.SaveFileContent(fullName, room);
        }
@@ -187,7 +184,7 @@
        public void AddShardFile(Common.SceneUI scene)
        {
            scene.IsSharedScene = true;
            string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, scene.FileName);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, scene.FileName);
            //写入内容
            HdlFileLogic.Current.SaveFileContent(fullName, scene);
        }
@@ -198,7 +195,7 @@
        /// <param name="dic">楼层</param>
        public void AddShardFile(Dictionary<string, string> dic)
        {
            string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, HdlFileNameResourse.ShardFloorFile);
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, DirNameResourse.ShardFloorFile);
            //写入内容
            HdlFileLogic.Current.SaveFileContent(fullName, dic);
        }
@@ -213,7 +210,7 @@
        /// <param name="fileName">指定文件名字</param>
        public void DeleteShardFile(string fileName)
        {
            fileName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
            fileName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            HdlFileLogic.Current.DeleteFile(fileName);
        }
@@ -224,7 +221,7 @@
        {
            this.dicShardDeviceFile.Clear();
            //创建文件夹
            HdlFileLogic.Current.CreateDirectory(HdlFileNameResourse.DownLoadShardDirectory, true);
            HdlFileLogic.Current.CreateDirectory(DirNameResourse.DownLoadShardDirectory, true);
        }
        #endregion
@@ -236,44 +233,48 @@
        /// </summary>
        public bool SynchronizeDbSharedContent()
        {
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3)
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //只有成员才有这个概念
                return true;
            }
            //获取主人分享给成员的文件列表
            var listShardInfo = this.GetShardFileListFromDb(Config.Instance.Guid);
            if (listShardInfo == null)
            var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
            var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (string.IsNullOrEmpty(result) == true)
            {
                return false;
            }
            var listShardInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GetShardInfoResult>>(result);
            //主键
            var dicAddMark = new Dictionary<string, string>();
            var listAddMark = new List<string>();
            //检测取消了共享的操作使用
            var dicShardFile = new Dictionary<string, string>();
            var listShardFile = new HashSet<string>();
            //获取前回共享文件的更新日期(keys:文件名字,value:更新日期)
            var dicUpdateTime = this.GetAllShardFileAgoUpdateTime();
            //先看看这分享数据里面有什么鬼
            foreach (var info in listShardInfo)
            {
                dicShardFile[info.FileName] = info.Id;
                string updateTime = info.TimeSpan;
                string fileName = info.ShareName;
                listShardFile.Add(fileName);
                //如果本地没有,或者更新日期大于前回更新日期的时候
                if (Global.IsExistsByHomeId(info.FileName) == false
                    || dicUpdateTime.ContainsKey(info.FileName) == false
                    || info.CreateTime.CompareTo(dicUpdateTime[info.FileName]) > 0)
                if (Global.IsExistsByHomeId(fileName) == false
                    || dicUpdateTime.ContainsKey(fileName) == false
                    || updateTime.CompareTo(dicUpdateTime[fileName]) > 0)
                {
                    dicAddMark[info.Id] = info.FileName;
                    listAddMark.Add(info.DistributedMark);
                    //更新日更新
                    dicUpdateTime[info.FileName] = info.CreateTime;
                    dicUpdateTime[fileName] = updateTime;
                }
            }
            //从云端获取下来文件
            if (dicAddMark.Count > 0)
            if (listAddMark.Count > 0)
            {
                //开启进度条 共享数据同步中
                ProgressFormBar.Current.Start();
@@ -281,7 +282,7 @@
                //将分享的数据存入本地(获取的是本地没有的)
                this.ClearShardDirectory();
                var listDbFile = this.SetShardFileToLocation(dicAddMark);
                var listDbFile = this.SetShardFileToLocation(listAddMark);
                if (listDbFile == null)
                {
                    //关闭
@@ -292,7 +293,7 @@
                //生成文件
                foreach (string fileName in listDbFile)
                {
                    var oldPath = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
                    var oldPath = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
                    var newPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
                    HdlFileLogic.Current.CopyFile(oldPath, newPath);
                }
@@ -301,18 +302,18 @@
            }
            //同步服务器的取消了的分享内容
            return this.SynchronizeDeleteSharedContent(dicShardFile, dicUpdateTime);
            return this.SynchronizeDeleteSharedContent(listShardFile, dicUpdateTime);
        }
        /// <summary>
        /// 同步服务器的取消了的分享内容
        /// </summary>
        /// <param name="dicShardFile">云端上面分享的文件,为Null时从新获取 key:文件名 value:主键</param>
        /// <param name="listShardFile">云端上面分享的文件,为Null时从新获取</param>
        /// <param name="dicUpdateTime">分享文件的更新时间,为Null时从新获取</param>
        /// <returns></returns>
        public bool SynchronizeDeleteSharedContent(Dictionary<string, string> dicShardFile = null, Dictionary<string, string> dicUpdateTime = null)
        public bool SynchronizeDeleteSharedContent(HashSet<string> listShardFile = null, Dictionary<string, string> dicUpdateTime = null)
        {
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3)
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //只有成员才有这个概念
                return true;
@@ -328,21 +329,23 @@
            }
            //重新获取
            if (dicShardFile == null)
            if (listShardFile == null)
            {
                dicShardFile = new Dictionary<string, string>();
                listShardFile = new HashSet<string>();
                //获取主人分享给成员的文件列表
                var listShardData = this.GetShardFileListFromDb(Config.Instance.Guid);
                if (listShardData == null)
                var infoPra = new { DistributedMark = Config.Instance.Guid, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare };
                var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
                if (string.IsNullOrEmpty(result) == true)
                {
                    //关闭
                    ProgressFormBar.Current.Close();
                    return false;
                }
                var listShardData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GetShardInfoResult>>(result);
                //先看看这分享数据里面有什么鬼
                foreach (var info in listShardData)
                {
                    dicShardFile[info.FileName] = info.Id;
                    listShardFile.Add(info.ShareName);
                }
            }
@@ -352,7 +355,7 @@
            var listLocalFile = HdlFileLogic.Current.GetRootPathListFile();
            foreach (string fileName in listLocalFile)
            {
                if (fileName == HdlFileNameResourse.ShardFloorFile)
                if (fileName == DirNameResourse.ShardFloorFile)
                {
                    //楼层文件
                    var varData = Global.ReadFileByHomeId(fileName);
@@ -362,7 +365,7 @@
                    Global.DeleteFilebyHomeId(fileName);
                }
                if (dicShardFile.ContainsKey(fileName) == true)
                if (listShardFile.Contains(fileName) == true)
                {
                    //本地的这个文件还分享着,没有问题
                    continue;
@@ -419,26 +422,6 @@
            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
        #region ■ 同步内容更新时间___________________
@@ -450,7 +433,7 @@
        private Dictionary<string, string> GetAllShardFileAgoUpdateTime()
        {
            var dicTime = new Dictionary<string, string>();
            var data = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.ShardFileUpdateTimeFile);
            var data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.ShardFileUpdateTimeFile);
            if (data == null)
            {
                //目标文件不存在
@@ -466,7 +449,7 @@
        /// <param name="dicTime"></param>
        private void SaveAllShardFileAgoUpdateTime(Dictionary<string, string> dicTime)
        {
            HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.ShardFileUpdateTimeFile, dicTime);
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.ShardFileUpdateTimeFile, dicTime);
        }
        #endregion
@@ -498,22 +481,28 @@
            ProgressFormBar.Current.Start();
            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting));
            //从云端获取分享的文件列表
            var listData = this.GetShardFileListFromDb(memberShardInfo.ChildAccountId);
            if (listData == null)
            var infoPra = new
            {
                DistributedMark = memberShardInfo.SubAccountDistributedMark,
                HouseDistributedMark = Shared.Common.Config.Instance.HomeId,
                IsOtherAccountControl = Common.Config.Instance.Home.IsOthreShare
            };
            var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (string.IsNullOrEmpty(result) == true)
            {
                //关闭进度条
                ProgressFormBar.Current.Close();
                return false;
            }
            var listData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result);
            //先清空共享文件夹
            this.ClearShardDirectory();
            var dicFileKey = new Dictionary<string, string>();
            var listMark = new List<string>();
            foreach (var data in listData)
            {
                //性能优化:如果本地拥有这个文件的话,直接使用那个文件
                string fileName = data.FileName;
                string fileName = data.ShareName;
                if (fileName.StartsWith("Device_") == true)
                {
                    string[] Arry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
@@ -524,12 +513,12 @@
                    }
                }
                //记录起它的主键
                memberShardInfo.dicAllShardKeys[fileName] = data.Id;
                memberShardInfo.dicAllShardKeys[fileName] = data.DistributedMark;
                if (fileName.StartsWith("Room_") == true || fileName.StartsWith("Scene_") == true)
                {
                    //房间文件和场景文件需要重新反序列化
                    dicFileKey[data.Id] = data.FileName;
                    listMark.Add(data.DistributedMark);
                    continue;
                }
                if (Shared.Common.Global.IsExistsByHomeId(fileName) == true)
@@ -538,11 +527,11 @@
                    this.AddShardFile(fileName);
                    continue;
                }
                dicFileKey[data.Id] = data.FileName;
                listMark.Add(data.DistributedMark);
            }
            //将分享的数据存入本地,返回的是文件名字(异常时返回null)
            var listFile = this.SetShardFileToLocation(dicFileKey);
            var listFile = this.SetShardFileToLocation(listMark);
            if (listFile == null)
            {
                //关闭进度条
@@ -590,7 +579,7 @@
                            memberShardInfo.dicShardRoom[fileName] = roomTemp;
                        }
                    }
                    else if (fileName == HdlFileNameResourse.ShardFloorFile)
                    else if (fileName == DirNameResourse.ShardFloorFile)
                    {
                        //楼层文件
                        var byteData = this.GetShardFileContent(fileName);
@@ -606,14 +595,14 @@
                        if (Arry.Length == 4)
                        {
                            //对应旧数据:Device_OnOffOutput_abcjdffdfj_01
                            string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(Arry[2], Convert.ToInt32(Arry[3]));
                            string mainKeys = Common.LocalDevice.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]));
                            string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(Arry[1], Convert.ToInt32(Arry[2]));
                            this.dicShardDeviceFile[mainKeys] = fileName;
                            //设备文件
                            dicDeviceFile[mainKeys] = fileName;
@@ -675,7 +664,7 @@
                        //设备
                        if (data.Type == 0)
                        {
                            string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                            string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                            if (dicShardDeviceFile.ContainsKey(mainkey) == true )
                            {
                                //这个设备文件匹配得到
@@ -783,8 +772,8 @@
            var listFile = this.GetUploadListFile(memberShardInfo, nowRoom, listDevice, listScene, listChirdDevice, listChirdScene, listDelPic);
            //不允许按系统的返回键
            Config.Instance.BackKeyCanClick = false;
            HdlUserCenterResourse.AccountOption.AppCanSignout = false;
            Shared.Common.CommonPage.BackKeyCanClick = false;
            UserCenterResourse.AccountOption.AppCanSignout = false;
            if (BarMaxValue == -1)
            {
@@ -813,8 +802,8 @@
            }
            //允许按系统的返回键
            Config.Instance.BackKeyCanClick = true;
            HdlUserCenterResourse.AccountOption.AppCanSignout = true;
            Shared.Common.CommonPage.BackKeyCanClick = true;
            UserCenterResourse.AccountOption.AppCanSignout = true;
            if (result == false)
            {
@@ -899,7 +888,7 @@
                this.AddShardFile(device.FilePath);
                //加点缓存
                string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                string mainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
                this.dicShardDeviceFile[mainKeys] = device.FilePath;
                if (roomTemp.ListDevice.Contains(mainKeys) == false)
@@ -915,7 +904,7 @@
                this.AddShardFile(device.FilePath);
                //加点缓存
                this.dicShardDeviceFile[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device.FilePath;
                this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
            }
            //场景
@@ -952,7 +941,7 @@
                memberShardInfo.dicShardFloor[roomTemp.FloorId] = HdlResidenceLogic.Current.GetFloorNameById(roomTemp.FloorId);
            }
            this.AddShardFile(memberShardInfo.dicShardFloor);
            listFile.Add(HdlFileNameResourse.ShardFloorFile);
            listFile.Add(DirNameResourse.ShardFloorFile);
            return listFile;
        }
@@ -972,7 +961,7 @@
                //设备
                if (data.Type == 0)
                {
                    string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    if (listCheck.Contains(mainKeys) == true)
                    {
                        //不重复添加
@@ -980,7 +969,7 @@
                    }
                    listCheck.Add(mainKeys);
                    var device = HdlDeviceCommonLogic.Current.GetDevice(data.DeviceAddr, data.Epoint);
                    var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
                    if (device != null)
                    {
                        listDevice.Add(device);
@@ -1033,15 +1022,45 @@
                    }
                    listCheckFile.Add(fileName);
                }
                var shareByte = this.GetShardFileContent(fileName);
                //上传文件
                var shardId = this.DoUploadShardContent(memberShardInfo.ChildAccountId, fileName, shareByte);
                if (shardId == null)
                if (fileName.EndsWith(".png") == true)
                {
                    return false;
                    //上传图片
                    var result = this.UpLoadBigBackupFileToDB(memberShardInfo, fileName);
                    if (result == null)
                    {
                        return false;
                    }
                    dicKeys[fileName] = result;
                }
                //收集主键
                dicKeys[fileName] = shardId;
                else
                {
                    var info = new UploadShardContent();
                    info.SubAccountDistributedMark = memberShardInfo.SubAccountDistributedMark;
                    info.ShareName = fileName;
                    info.ShareDataBytes = HdlShardLogic.Current.GetShardFileContent(fileName);
                    //追加共享
                    if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
                    {
                        var result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info, null, true);
                        if (string.IsNullOrEmpty(result) == true)
                        {
                            return false;
                        }
                        //这里有点特殊,接口是直接返回主键回来的,而不是Jsoin
                        dicKeys[fileName] = result;
                    }
                    else
                    {
                        info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
                        var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
                        if (result == false)
                        {
                            return false;
                        }
                        dicKeys[fileName] = info.DistributedMark;
                    }
                }
                //设置进度值
                ProgressBar.SetValue(1);
            }
@@ -1055,28 +1074,135 @@
        }
        /// <summary>
        /// 上传分享内容(返回主键)
        /// 上传图片文件到云端
        /// </summary>
        /// <param name="i_childAccountId">子账号的主键</param>
        /// <param name="i_fileName">文件名字</param>
        /// <param name="i_content">文件内容</param>
        /// <param name="fullDir">文件夹的全路径</param>
        /// <param name="listPicFile">图片文件列表</param>
        /// <returns></returns>
        private string DoUploadShardContent(string i_childAccountId, string i_fileName, byte[] i_content)
        private string UpLoadBigBackupFileToDB(MemberShardInfoData memberShardInfo, string fileName)
        {
            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)
            string fullName = System.IO.Path.Combine(DirNameResourse.DownLoadShardDirectory, fileName);
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
            }
            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveShardInfoResult>(result.Data.ToString());
            return info.Id;
            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)));
            //追加共享
            if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
            {
                //这里有点特殊,接口是直接返回主键回来的,而不是Jsoin
                var result = this.DoUpLoadBigBackupFileToDB("ZigbeeDataShare/AddShareData", fullName, nvc);
                return result;
            }
            else
            {
                nvc.Add("DistributedMark", memberShardInfo.dicAllShardKeys[fileName]);
                var result = this.DoUpLoadBigBackupFileToDB("ZigbeeDataShare/EditShareData", fullName, nvc);
                if (result == null)
                {
                    return null;
                }
                return memberShardInfo.dicAllShardKeys[fileName];
            }
        }
        /// <summary>
        /// 执行上传大文件
        /// </summary>
        /// <param name="RequestName">请求接口</param>
        /// <param name="fullFileName">文件名字(含路径)</param>
        /// <param name="nvc"></param>
        /// <returns></returns>
        private string DoUpLoadBigBackupFileToDB(string RequestName, string fullFileName, NameValueCollection nvc)
        {
            string paramName = "file";
            string contentType = "application/octet-stream";
            string 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;
            wr.Headers.Add(HttpRequestHeader.Authorization, Config.Instance.Token);
            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();
                var data = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(result);
                bool flage = UserCenterLogic.CheckNotEorrorMsg(data, requestUrl);
                if (flage == true)
                {
                    //编辑的时候,这个东西会是null
                    return data.ResponseData == null ? "1" : data.ResponseData.ToString();
                }
                //Log出力
                IMessageCommon.Current.GetMsgByRequestName(RequestName, data, nvc);
                return null;
            }
            catch
            {
                return null;
            }
            finally
            {
                if (wresp != null)
                {
                    wresp.Close();
                    wresp = null;
                }
                wr = null;
            }
        }
        #endregion
@@ -1169,7 +1295,7 @@
            foreach (var device in listDevice)
            {
                string deviceFileName = device.FilePath;
                string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
                string mainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
                //移除路径列表
                roomTemp.ListDevice.Remove(mainKeys);
                if (listHadShardKeys.Contains(mainKeys) == true)
@@ -1276,7 +1402,7 @@
            }
            //执行移除分享数据
            var result = this.DoDeleteSharedContent(memberShardInfo, listMark, listDeleteFile);
            var result = this.DoDeleteSharedContent(memberShardInfo, nowRoom, listMark, listDeleteFile);
            //同步房间文件
            if (result == true && listDeleteFile.Contains(roomTemp.FileName) == false)
            {
@@ -1324,10 +1450,12 @@
        /// 执行移除分享数据
        /// </summary>
        /// <param name="memberShardInfo">成员的分享内容</param>
        /// <param name="nowRoom">当前房间</param>
        /// <param name="listMark">要移除的主键</param>
        /// <param name="listDeleteFile">要删除的文件(房间文件需要删除的话,必须放在最后)</param>
        /// <returns></returns>
        private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, List<string> listMark, List<string> listDeleteFile)
        private bool DoDeleteSharedContent(MemberShardInfoData memberShardInfo, Common.Room nowRoom,
            List<string> listMark, List<string> listDeleteFile)
        {
            if (listMark.Count == 0)
            {
@@ -1335,6 +1463,7 @@
                return true;
            }
            var info = new DeleteShardInfo();
            //开启进度条
            ProgressBar.Show();
            var listCheck = new HashSet<string>();
@@ -1344,11 +1473,10 @@
                if (listCheck.Contains(markKeys) == true) { continue; }
                listCheck.Add(markKeys);
                var pra = new { homeId = Config.Instance.Home.Id, homeShareId = markKeys };
                info.DistributedMark = 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)
                var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info, null, true);
                if (result == false)
                {
                    //关闭进度条
                    ProgressBar.Close();
@@ -1384,6 +1512,8 @@
            {
                return true;
            }
            var info = new DeleteShardInfo();
            foreach (var fileName in listDelFile)
            {
                if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
@@ -1391,11 +1521,11 @@
                    //我也不知道为什么会找不到主键
                    continue;
                }
                var pra = new { homeId = Config.Instance.Home.Id, homeShareId = memberShardInfo.dicAllShardKeys[fileName] };
                info.DistributedMark = memberShardInfo.dicAllShardKeys[fileName];
                //执行删除
                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)
                var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/DeleteShareData", false, info, null, true);
                if (result == false)
                {
                    return false;
                }
@@ -1426,11 +1556,16 @@
            {
                return true;
            }
            var info = new EditorShardContent();
            info.DistributedMark = memberShardInfo.dicAllShardKeys[upDateRoom.FileName];
            info.ShareName = upDateRoom.FileName;
            info.SubAccountDistributedMark = memberShardInfo.SubAccountDistributedMark;
            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)
            info.ShareDataBytes = byteData;
            var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
            if (result == false)
            {
                return false;
            }
@@ -1451,15 +1586,19 @@
        /// <returns></returns>
        private 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);
            //上传内容
            var shardId = this.DoUploadShardContent(memberShardInfo.ChildAccountId, HdlFileNameResourse.ShardFloorFile, byteData);
            if (shardId == null)
            info.ShareDataBytes = byteData;
            var result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeDataShare/EditShareData", false, info, null, true);
            if (result == false)
            {
                return false;
            }
            //将房间对象序列化到缓存
            this.AddShardFile(memberShardInfo.dicShardFloor);
@@ -1485,7 +1624,7 @@
            var dicDeleteDeviceFile = new Dictionary<string, string>();
            foreach (var device in listDeleteDevice)
            {
                dicDeleteDeviceFile[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device.FilePath;
                dicDeleteDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
            }
            var dicDeleteSceneFile = new Dictionary<int, string>();
            foreach (var scene in listDeleteScene)
@@ -1567,7 +1706,7 @@
                //设备
                if (data.Type == 0)
                {
                    string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    if (dicShardDeviceFile.ContainsKey(mainkey) == true && dicDeviceKeys.ContainsKey(mainkey) == false)
                    {
                        dicDeviceKeys[mainkey] = dicShardDeviceFile[mainkey];
@@ -1598,7 +1737,7 @@
                //设备
                if (data.Type == 0)
                {
                    string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    if (listKeys.Contains(mainkey) == false)
                    {
                        listKeys.Add(mainkey);
@@ -1619,6 +1758,75 @@
        #region ■ 结构体类___________________________
        /// <summary>
        /// 上传分享的内容
        /// </summary>
        private class UploadShardContent : IfacePraCommon
        {
            /// <summary>
            /// 分享数据的主键
            /// </summary>
            public string DistributedMark = string.Empty;
            /// <summary>
            /// 分享名字
            /// </summary>
            public string ShareName = string.Empty;
            /// <summary>
            /// 住宅ID
            /// </summary>
            public string HouseDistributedMark = Common.Config.Instance.Home.Id;
            /// <summary>
            /// 子账号的guid
            /// </summary>
            public string SubAccountDistributedMark = string.Empty;
            /// <summary>
            /// 分享内容
            /// </summary>
            public byte[] ShareDataBytes = null;
        }
        /// <summary>
        /// 删除共享的内容
        /// </summary>
        private class DeleteShardInfo : IfacePraCommon
        {
            /// <summary>
            /// 共享数据的唯一标识
            /// </summary>
            public string DistributedMark = null;
            /// <summary>
            /// 住宅ID
            /// </summary>
            public string HouseDistributedMark = Common.Config.Instance.Home.Id;
        }
        /// <summary>
        /// 编辑共享内容
        /// </summary>
        private class EditorShardContent : IfacePraCommon
        {
            /// <summary>
            /// 主键
            /// </summary>
            public string DistributedMark = string.Empty;
            /// <summary>
            /// 分享名字
            /// </summary>
            public string ShareName = string.Empty;
            /// <summary>
            /// 住宅ID
            /// </summary>
            public string HouseDistributedMark = Common.Config.Instance.Home.Id;
            /// <summary>
            /// 分享内容
            /// </summary>
            public byte[] ShareDataBytes = null;
            /// <summary>
            /// 子账号的Guid
            /// </summary>
            public string SubAccountDistributedMark = string.Empty;
        }
        /// <summary>
        /// 接收分享数据
        /// </summary>
        private class ReceiveShardInfoResult
@@ -1626,15 +1834,11 @@
            /// <summary>
            /// 文件名字
            /// </summary>
            public string FileName = string.Empty;
            /// <summary>
            /// 更新时间
            /// </summary>
            public string CreateTime = string.Empty;
            public string ShareName = string.Empty;
            /// <summary>
            /// 主键
            /// </summary>
            public string Id = string.Empty;
            public string DistributedMark = string.Empty;
        }
        #endregion