From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 28 二月 2020 15:25:13 +0800
Subject: [PATCH] 2020.2.28

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs |  433 +++++++++++++++++++++++++++++------------------------
 1 files changed, 236 insertions(+), 197 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs
index 66555a5..8b0d4e2 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs
@@ -39,6 +39,11 @@
                 m_Current = value;
             }
         }
+        /// <summary>
+        /// 鍒嗕韩鐨勮澶囨枃浠�(key:璁惧涓婚敭,value:璁惧鏂囦欢)
+        /// </summary>
+        private Dictionary<string, string> dicShardDeviceFile = new Dictionary<string, string>();
+
         #endregion
 
         #region 鈻� 鑾峰彇鍒嗕韩鏂囦欢_______________________
@@ -48,13 +53,13 @@
         /// </summary>
         /// <param name="listDistributedMark"></param>
         /// <returns></returns>
-        public async Task<List<string>> SetShardFileToLocation(List<string> listDistributedMark)
+        private async Task<List<string>> SetShardFileToLocation(List<string> listDistributedMark)
         {
             if (listDistributedMark.Count == 0)
             {
                 return new List<string>();
             }
-            ProgressBar.SetMaxValue(listDistributedMark.Count);
+            int listMarkCount = listDistributedMark.Count;
 
             List<string> listFile = new List<string>();
             //鏂囦欢澶�
@@ -64,8 +69,9 @@
             Shared.Common.CommonPage.BackKeyCanClick = false;
             UserCenterResourse.Option.AppCanSignout = false;
 
-            foreach (string keys in listDistributedMark)
+            for (int i = 0; i < listDistributedMark.Count; i++)
             {
+                string keys = listDistributedMark[i];
                 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)
@@ -81,7 +87,7 @@
                 //淇濆瓨鍒版寚瀹氭枃浠跺す涓�
                 Global.WriteFileToDirectoryByBytes(strDir, dataResult.ShareName, dataResult.ShareDataBytes);
                 //璁剧疆杩涘害鍊�
-                ProgressBar.SetValue(1);
+                ProgressFormBar.Current.SetValue(i + 1, listMarkCount);
             }
 
             //鍏佽鎸夌郴缁熺殑杩斿洖閿�
@@ -220,125 +226,10 @@
         /// </summary>
         public void ClearShardDirectory()
         {
+            this.dicShardDeviceFile.Clear();
             //鍒涘缓鏂囦欢澶�
             string strDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
             Global.CreateEmptyDirectory(strDir, true);
-        }
-
-        #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);
-                }
-            }
-
-            //璁剧疆鎴块棿閲岄潰璁惧鐨刄I瀵硅薄(鍥犱负杩欎釜涓滆タ鏄弽搴忓垪鍖栧嚭鏉ョ殑,璁惧UI瀵硅薄鏄笉搴忓垪鍖栧璞�)
-            foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
-            {
-                //杩樺師璁惧瀵硅薄
-                tempRoom.DeviceUIList.Clear();
-                for (int i = 0; i < tempRoom.DeviceUIFilePathList.Count; i++)
-                {
-                    string deviceFile = tempRoom.DeviceUIFilePathList[i];
-                    //杩欎釜璁惧鏂囦欢鍖归厤寰楀埌鎴块棿
-                    listDeviceFile.Remove(deviceFile);
-                    if (this.IsFileExists(deviceFile) == false)
-                    {
-                        //绉婚櫎鎺夎繖涓笉瀵瑰姴鐨勮矾寰�
-                        tempRoom.DeviceUIFilePathList.RemoveAt(i);
-                        i--;
-                        continue;
-                    }
-                    tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
-                }
-                //杩樺師鍦烘櫙瀵硅薄
-                tempRoom.SceneUIList.Clear();
-                for (int i = 0; i < tempRoom.SceneUIFilePathList.Count; i++)
-                {
-                    string uiPath = tempRoom.SceneUIFilePathList[i];
-                    //杩欎釜鍦烘櫙鏂囦欢鍖归厤寰楀埌鎴块棿
-                    listSceneFile.Remove(uiPath);
-                    var byteData = this.GetShardFileContent(uiPath);
-                    if (byteData == null)
-                    {
-                        //绉婚櫎鎺夎繖涓笉瀵瑰姴鐨勮矾寰�
-                        tempRoom.SceneUIFilePathList.RemoveAt(i);
-                        i--;
-                        continue;
-                    }
-                    string valueData = System.Text.Encoding.UTF8.GetString(byteData);
-                    var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
-                    tempRoom.SceneUIList.Add(tempUi);
-                }
-            }
-            //濡傛灉瀛樺湪鍖归厤涓嶄笂鐨勬枃浠�
-            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
@@ -394,11 +285,9 @@
             //浠庝簯绔幏鍙栦笅鏉ユ枃浠�
             if (listAddMark.Count > 0)
             {
-                //寮哄埗鎸囧畾鏂囨湰闄勫姞淇℃伅锛氬叡浜暟鎹悓姝ヤ腑
-                string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing);
-                //寮�鍚繘搴︽潯
-                ProgressBar.Show(msg);
-                ProgressBar.SetAppendText(msg);
+                //寮�鍚繘搴︽潯 鍏变韩鏁版嵁鍚屾涓�
+                ProgressFormBar.Current.Start();
+                ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
 
                 //灏嗗垎浜殑鏁版嵁瀛樺叆鏈湴(鑾峰彇鐨勬槸鏈湴娌℃湁鐨�)
                 this.ClearShardDirectory();
@@ -406,15 +295,17 @@
                 if (listDbFile == null)
                 {
                     //鍏抽棴
-                    ProgressBar.Close();
+                    ProgressFormBar.Current.Close();
                     return false;
                 }
 
                 //鐢熸垚鏂囦欢
                 foreach (string fileName in listDbFile)
                 {
-                    var data = this.GetShardFileContent(fileName);
-                    Global.WriteFileByBytesByHomeId(fileName, data);
+                    var oldPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, 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)
                     {
                         //鎴块棿鏂囦欢鐗规畩澶勭悊
@@ -442,11 +333,9 @@
                 //鍙湁鎴愬憳鎵嶆湁杩欎釜姒傚康
                 return true;
             }
-            //寮哄埗鎸囧畾鏂囨湰闄勫姞淇℃伅锛氬叡浜暟鎹悓姝ヤ腑
-            string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing);
-            //寮�鍚繘搴︽潯
-            ProgressBar.Show(msg);
-            ProgressBar.SetAppendText(msg);
+            //寮�鍚繘搴︽潯  鍏变韩鏁版嵁鍚屾涓�
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
 
             if (dicUpdateTime == null)
             {
@@ -465,7 +354,7 @@
                 if (string.IsNullOrEmpty(result) == true)
                 {
                     //鍏抽棴
-                    ProgressBar.Close();
+                    ProgressFormBar.Current.Close();
                     return false;
                 }
                 var listShardData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GetShardInfoResult>>(result);
@@ -480,13 +369,25 @@
             var listLocalFile = Global.FileListByHomeId();
             foreach (string fileName in listLocalFile)
             {
+                if (fileName == DirNameResourse.ShardFloorFile)
+                {
+                    //妤煎眰鏂囦欢
+                    var varData = Global.ReadFileByHomeId(fileName);
+                    var dicFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(Encoding.UTF8.GetString(varData));
+                    Common.Config.Instance.Home.FloorDics = dicFloor;
+                    Common.Config.Instance.Home.Save(false);
+
+                    Global.DeleteFilebyHomeId(fileName);
+                }
+
                 if (listShardFile.Contains(fileName) == true)
                 {
                     //鏈湴鐨勮繖涓枃浠惰繕鍒嗕韩鐫�,娌℃湁闂
                     continue;
                 }
+
                 //妫�娴嬫湰鍦拌澶囨枃浠�,鏄惁瀛樺湪宸茬粡鍙栨秷浜嗗叡浜簡鐨�
-                if (fileName.StartsWith(Common.LocalDevice.deviceFirstName) == true)
+                if (fileName.StartsWith("Device_") == true)
                 {
                     //鍒犻櫎鎺夎繖涓澶囨枃浠�
                     Global.DeleteFilebyHomeId(fileName);
@@ -531,7 +432,7 @@
             //淇濆瓨鍏ㄩ儴鍒嗕韩鏂囦欢鐨勬洿鏂版棩鏈�
             this.SaveAllShardFileAgoUpdateTime(dicUpdateTime);
             //鍏抽棴
-            ProgressBar.Close();
+            ProgressFormBar.Current.Close();
 
             return true;
         }
@@ -577,7 +478,6 @@
         /// <summary>
         /// 鑾峰彇鎴愬憳鍏变韩鍒楄〃鐒跺悗淇濆瓨鍒版湰鍦�(鐢ㄥ畬涔嬪悗鏈�濂借皟鐢ㄦ竻绌� ClearShardDirectory鍑芥暟娓呯┖)
         /// </summary>
-        /// <param name="SubAccountDistributedMark">鎴愬憳鍒楄〃鎺ュ彛杩斿洖鐨凷ubAccountDistributedMark</param>
         /// <param name="memberShardInfo">
         /// <para>鎴愬憳鐨勫垎浜暟鎹�</para>
         /// <para>濡傛灉涓嶇煡閬撹繖鏄粈涔堜笢瑗�,灏盢ew涓�涓�,鐒跺悗缂撳瓨璧锋潵,璋冪敤鍏朵粬鍑芥暟閮介渶瑕佽繖涓笢瑗�</para>
@@ -588,12 +488,15 @@
         {
             if (memberShardInfo.Refresh == false)
             {
+                //浠庢湰鍦拌幏鍙栨垚鍛樼殑鍒嗕韩鍒楄〃
+                this.GetMemberShardContentListFromLocal(memberShardInfo);
                 return true;
             }
             memberShardInfo.Refresh = false;
 
-            //鎵撳紑杩涘害鏉�
-            ProgressBar.Show();
+            //姝e湪鑾峰彇鍒嗕韩鏁版嵁
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting));
 
             var infoPra = new
             {
@@ -605,7 +508,7 @@
             if (result == null)
             {
                 //鍏抽棴杩涘害鏉�
-                ProgressBar.Close();
+                ProgressFormBar.Current.Close();
                 return false;
             }
             var listData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result);
@@ -640,14 +543,163 @@
             if (listFile == null)
             {
                 //鍏抽棴杩涘害鏉�
-                ProgressBar.Close();
+                ProgressFormBar.Current.Close();
                 return false;
             }
+
+            //浠庢湰鍦拌幏鍙栨垚鍛樼殑鍒嗕韩鍒楄〃
+            this.GetMemberShardContentListFromLocal(memberShardInfo);
+
             //鍏抽棴杩涘害鏉�
-            ProgressBar.Close();
+            ProgressFormBar.Current.Close();
 
             return true;
         }
+
+        /// <summary>
+        /// 浠庢湰鍦拌幏鍙栨垚鍛樼殑鍒嗕韩鍒楄〃
+        /// </summary>
+        /// <param name="memberShardInfo">鎴愬憳鐨勫垎浜暟鎹殑缂撳瓨(璋冪敤杩欎釜鍑芥暟浼氬埛鏂拌繖涓彉閲忕殑淇℃伅)</param>
+        private void GetMemberShardContentListFromLocal(MemberShardInfoData memberShardInfo)
+        {
+            memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
+            this.dicShardDeviceFile.Clear();
+
+            var listDeviceFile = new HashSet<string>();
+            var listSceneFile = new HashSet<string>();
+
+            var listFile = this.GetLocalAllShardFile();
+            //鍏堝垵濮嬪寲鎴块棿
+            foreach (string fileName in listFile)
+            {
+                try
+                {
+                    if (fileName.StartsWith("Room_") == true)
+                    {
+                        //鎴块棿鏂囦欢
+                        var byteData = this.GetShardFileContent(fileName);
+                        if (byteData != null)
+                        {
+                            string valueData = System.Text.Encoding.UTF8.GetString(byteData);
+                            var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData);
+                            memberShardInfo.dicShardRoom[fileName] = roomTemp;
+                        }
+                    }
+                    else if (fileName == 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)
+                    {
+                        string[] Arry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
+                        string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(Arry[2], Convert.ToInt32(Arry[3]));
+                        this.dicShardDeviceFile[mainKeys] = fileName;
+
+                        //璁惧鏂囦欢
+                        listDeviceFile.Add(fileName);
+                    }
+                    else if (fileName.StartsWith("Scene_") == true)
+                    {
+                        //鍦烘櫙鏂囦欢
+                        listSceneFile.Add(fileName);
+                    }
+                }
+                catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
+            }
+
+            //璁剧疆鎴块棿閲岄潰璁惧鐨刄I瀵硅薄(鍥犱负杩欎釜涓滆タ鏄弽搴忓垪鍖栧嚭鏉ョ殑,璁惧UI瀵硅薄鏄笉搴忓垪鍖栧璞�)
+            foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
+            {
+                //杩樺師璁惧瀵硅薄
+                tempRoom.DeviceUIList.Clear();
+                for (int i = 0; i < tempRoom.DeviceUIFilePathList.Count; i++)
+                {
+                    string deviceFile = tempRoom.DeviceUIFilePathList[i];
+                    //杩欎釜璁惧鏂囦欢鍖归厤寰楀埌鎴块棿
+                    listDeviceFile.Remove(deviceFile);
+                    if (this.IsFileExists(deviceFile) == false)
+                    {
+                        //绉婚櫎鎺夎繖涓笉瀵瑰姴鐨勮矾寰�
+                        tempRoom.DeviceUIFilePathList.RemoveAt(i);
+                        i--;
+                        continue;
+                    }
+                    tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
+                }
+                //杩樺師鍦烘櫙瀵硅薄
+                tempRoom.SceneUIList.Clear();
+                for (int i = 0; i < tempRoom.SceneUIFilePathList.Count; i++)
+                {
+                    string uiPath = tempRoom.SceneUIFilePathList[i];
+                    //杩欎釜鍦烘櫙鏂囦欢鍖归厤寰楀埌鎴块棿
+                    listSceneFile.Remove(uiPath);
+                    var byteData = this.GetShardFileContent(uiPath);
+                    if (byteData == null)
+                    {
+                        //绉婚櫎鎺夎繖涓笉瀵瑰姴鐨勮矾寰�
+                        tempRoom.SceneUIFilePathList.RemoveAt(i);
+                        i--;
+                        continue;
+                    }
+                    string valueData = System.Text.Encoding.UTF8.GetString(byteData);
+                    var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
+                    tempRoom.SceneUIList.Add(tempUi);
+
+                    //鑾峰彇鍦烘櫙閲岄潰鐨勫叏閮ㄧ洰鏍�(2019.11.05杩藉姞鎿嶄綔,鏈夊彲鑳介偅涓澶囨槸鐢卞満鏅祵濂楁潵鐨�,鎵�浠ュ畠鏈夊彲鑳戒笉灞炰簬浠讳綍鎴块棿)
+                    foreach (var data in tempUi.AddSceneMemberDataList)
+                    {
+                        //璁惧
+                        if (data.Type == 0)
+                        {
+                            string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+                            if (dicShardDeviceFile.ContainsKey(mainkey) == true )
+                            {
+                                //杩欎釜璁惧鏂囦欢鍖归厤寰楀埌
+                                listDeviceFile.Remove(dicShardDeviceFile[mainkey]);
+                            }
+                        }
+                        if (data.Type == 1)
+                        {
+                            var temp = new SceneUI();
+                            temp.Id = data.ElseScenesId;
+                            //杩欎釜鍦烘櫙鏂囦欢鍖归厤寰楀埌
+                            listSceneFile.Remove(temp.FileName);
+                        }
+                    }
+                }
+            }
+            //濡傛灉瀛樺湪鍖归厤涓嶄笂鐨勬枃浠�
+            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.uUnallocated);
+                //杩樺師璁惧瀵硅薄
+                foreach (string deviceFile in listDeviceFile)
+                {
+                    roomTemp.DeviceUIFilePathList.Add(deviceFile);
+                    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
 
@@ -779,13 +831,12 @@
                 //鍏嬮殕涓�涓璞�
                 roomTemp = nowRoom.CloneRoomClass();
                 memberShardInfo.TempRoom = roomTemp;
-                //鏂板垎浜殑鎴块棿,濡傛灉鍥剧墖鏄嚜瀹氫箟鐨�,鍒欎笂浼犲浘鐗�
-                if (roomTemp.BackgroundImageType != 0)
+                //鏂板垎浜殑鎴块棿,濡傛灉鍥剧墖鏄嚜瀹氫箟鐨�,骞朵笖杩欎釜鍥剧墖鏄瓨鍦ㄧ殑,鍒欎笂浼犲浘鐗�
+                if (roomTemp.BackgroundImageType != 0 && Common.Global.IsExistsByHomeId(roomTemp.BackgroundImage) == true)
                 {
                     //鑷畾涔夌殑鍥剧墖,瀹冨瓨鍦ㄤ簬鏈湴,浣嗘槸瀹冩槸鍏ㄨ矾寰�
-                    string[] Arry = roomTemp.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
-                    listFile.Add(Arry[Arry.Length - 1]);
-                    this.AddShardFile(Arry[Arry.Length - 1]);
+                    listFile.Add(roomTemp.BackgroundImage);
+                    this.AddShardFile(roomTemp.BackgroundImage);
                 }
             }
             else
@@ -797,15 +848,13 @@
                     if (roomTemp.BackgroundImageType != 0)
                     {
                         //鍒犻櫎鑷畾涔夊浘鐗�
-                        string[] Arry = roomTemp.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
-                        listDelPic.Add(Arry[Arry.Length - 1]);
+                        listDelPic.Add(roomTemp.BackgroundImage);
                     }
-                    if (nowRoom.BackgroundImageType != 0)
+                    if (nowRoom.BackgroundImageType != 0 && Common.Global.IsExistsByHomeId(nowRoom.BackgroundImage) == true)
                     {
                         //鑷畾涔夌殑鍥剧墖,瀹冨瓨鍦ㄤ簬鏈湴,浣嗘槸瀹冩槸鍏ㄨ矾寰�
-                        string[] Arry = nowRoom.BackgroundImage.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
-                        listFile.Add(Arry[Arry.Length - 1]);
-                        this.AddShardFile(Arry[Arry.Length - 1]);
+                        listFile.Add(nowRoom.BackgroundImage);
+                        this.AddShardFile(nowRoom.BackgroundImage);
                     }
                     //鍙樻洿鍥剧墖璁剧疆
                     roomTemp.BackgroundImageType = nowRoom.BackgroundImageType;
@@ -818,6 +867,9 @@
                 //璁惧
                 listFile.Add(device.FilePath);
                 this.AddShardFile(device.FilePath);
+
+                //鍔犵偣缂撳瓨
+                this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
 
                 //璁惧鐨刄I
                 var deviceUi = device.FilePath;
@@ -832,17 +884,19 @@
                 //璁惧
                 listFile.Add(device.FilePath);
                 this.AddShardFile(device.FilePath);
+
+                //鍔犵偣缂撳瓨
+                this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
             }
 
             //鍦烘櫙
             foreach (var secene in listScene)
             {
-                if (secene.IconPathType != 0)
+                if (secene.IconPathType != 0 && Common.Global.IsExistsByHomeId(secene.IconPath) == true)
                 {
-                    //鑷畾涔夌殑鍥剧墖,瀹冨瓨鍦ㄤ簬鏈湴,浣嗘槸瀹冩槸鍏ㄨ矾寰�
-                    string[] Arry = secene.IconPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
-                    listFile.Add(Arry[Arry.Length - 1]);
-                    this.AddShardFile(Arry[Arry.Length - 1]);
+                    //鑷畾涔夌殑鍥剧墖,瀹冨瓨鍦ㄤ簬鏈湴
+                    listFile.Add(secene.IconPath);
+                    this.AddShardFile(secene.IconPath);
                 }
 
                 listFile.Add(secene.FileName);
@@ -875,7 +929,7 @@
         }
 
         /// <summary>
-        /// 浠庣綉鍏宠幏鍙栧満鏅殑鐩爣璁惧鍒楄〃
+        /// 鑾峰彇鍦烘櫙鐨勭洰鏍囪澶囧垪琛�(杩欎釜涓嶈兘浠庡垎浜暟鎹腑鑾峰彇)
         /// </summary>
         /// <param name="scene">鍦烘櫙</param>
         /// <param name="listCheck">閲嶅妫�娴嬬敤</param>
@@ -971,7 +1025,7 @@
                     if (memberShardInfo.dicAllShardKeys.ContainsKey(fileName) == false)
                     {
                         var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/AddShareData", false, info);
-                        if (string.IsNullOrEmpty(result) == true)
+                        if (result == null)
                         {
                             return false;
                         }
@@ -1019,24 +1073,19 @@
             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;
-                }
                 //杩欓噷鏈夌偣鐗规畩锛屾帴鍙f槸鐩存帴杩斿洖涓婚敭鍥炴潵鐨勶紝鑰屼笉鏄疛soin
+                var result = this.DoUpLoadBigBackupFileToDB("ZigbeeDataShare/AddShareData", fullName, nvc);
                 return result;
             }
             else
             {
                 nvc.Add("DistributedMark", memberShardInfo.dicAllShardKeys[fileName]);
-                var result = this.UpLoadBigBackupFileToDB("ZigbeeDataShare/EditShareData", fullName, nvc);
-                if (result != "1")
+                var result = this.DoUpLoadBigBackupFileToDB("ZigbeeDataShare/EditShareData", fullName, nvc);
+                if (result == null)
                 {
                     return null;
                 }
@@ -1045,26 +1094,17 @@
         }
 
         /// <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)
+        private string DoUpLoadBigBackupFileToDB(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");
@@ -1074,6 +1114,8 @@
             wr.Method = "POST";
             wr.KeepAlive = true;
             wr.Credentials = System.Net.CredentialCache.DefaultCredentials;
+
+            wr.Headers.Add(HttpRequestHeader.Authorization, Config.Instance.Token);
 
             var rs = wr.GetRequestStream();
 
@@ -1113,23 +1155,24 @@
                 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";
+                    //缂栬緫鐨勬椂鍊欙紝杩欎釜涓滆タ浼氭槸null
+                    return data.ResponseData == null ? "1" : data.ResponseData.ToString();
                 }
-                return "0";
+
+                //Log鍑哄姏
+                IMessageCommon.Current.GetMsgByRequestName(RequestName, data, nvc);
+
+                return null;
             }
             catch
             {
-                return "-1";
+                return null;
             }
             finally
             {
@@ -1417,7 +1460,6 @@
             }
             //鍏抽棴杩涘害鏉�
             ProgressBar.Close();
-            ;
             for (int i = 0; i < listDeleteFile.Count; i++)
             {
                 string fileName = listDeleteFile[i];
@@ -1624,7 +1666,7 @@
         }
 
         /// <summary>
-        /// 浠庡満鏅璞¢噷闈㈣幏鍙栧叏閮ㄧ殑缁戝畾鐩爣鐨勬枃浠跺悕瀛�
+        /// 浠庡満鏅璞¢噷闈㈣幏鍙栧叏閮ㄧ殑缁戝畾鐩爣鐨勬枃浠跺悕瀛�(杩欓噷闈㈢殑涓滆タ蹇呴』浠庡垎浜暟鎹腑鑾峰彇)
         /// </summary>
         /// <param name="scene">鍦烘櫙</param>
         /// <param name="listFile">鏂囦欢鍒楄〃(閲岄潰瀛樼殑鏄澶嘦I鏂囦欢鍜岃澶囨枃浠跺拰鍦烘櫙鏂囦欢)</param>
@@ -1636,10 +1678,10 @@
                 //璁惧
                 if (data.Type == 0)
                 {
-                    var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
-                    if (device != null && listFile.Contains(device.FilePath) == false)
+                    string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+                    if (dicShardDeviceFile.ContainsKey(mainkey) == true && listFile.Contains(dicShardDeviceFile[mainkey]) == false)
                     {
-                        listFile.Add(device.FilePath);
+                        listFile.Add(dicShardDeviceFile[mainkey]);
                     }
                 }
                 if (data.Type == 1)
@@ -1651,13 +1693,10 @@
                     {
                         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)
                         {
-                            dicBindScene[roomTemp.FileName] = roomTemp;
-                            if (listFile.Contains(roomTemp.FileName) == false)
-                            {
-                                listFile.Add(roomTemp.FileName);
-                            }
+                            listFile.Add(roomTemp.FileName);
                         }
                     }
                 }

--
Gitblit v1.8.0