From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3
---
ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs | 1775 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 1,775 insertions(+), 0 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs
new file mode 100644
index 0000000..0689ba2
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs
@@ -0,0 +1,1775 @@
+锘縰sing Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.IO;
+using System.Net;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone
+{
+ /// <summary>
+ /// 鍒嗕韩鐨勯�昏緫
+ /// </summary>
+ public class HdlShardLogic
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// 鍒嗕韩鐨勯�昏緫
+ /// </summary>
+ private static HdlShardLogic m_Current = null;
+ /// <summary>
+ /// 鍒嗕韩鐨勯�昏緫
+ /// </summary>
+ public static HdlShardLogic Current
+ {
+ get
+ {
+ if (m_Current == null)
+ {
+ m_Current = new HdlShardLogic();
+ }
+ return m_Current;
+ }
+ set
+ {
+ m_Current = value;
+ }
+ }
+ /// <summary>
+ /// 鍒嗕韩鍘嬬缉鏂囦欢鐨勫悕瀛�
+ /// </summary>
+ private const string SHARED_BIN_FILE = "SharedData.bin";
+ /// <summary>
+ /// 鍒嗕韩鐨勮澶囧璞�
+ /// </summary>
+ private Dictionary<string, CommonDevice> DicDevices = null;
+ /// <summary>
+ /// 鍒嗕韩鐨勫満鏅璞�
+ /// </summary>
+ private Dictionary<int, SceneUI> DicScenes = new Dictionary<int, SceneUI>();
+ /// <summary>
+ /// 鍒嗕韩鐨勬埧闂翠俊鎭�
+ /// </summary>
+ private Dictionary<string, Room> DicRooms = new Dictionary<string, Room>();
+ /// <summary>
+ /// 鍒嗕韩鐨勬ゼ灞備俊鎭�
+ /// </summary>
+ private Dictionary<string, string> DicFloor = new Dictionary<string, string>();
+ /// <summary>
+ /// 鍒嗕韩鐨勬枃浠剁殑涓婚敭(key:鏂囦欢鍚�,value:涓婚敭)
+ /// </summary>
+ private Dictionary<string, string> DicShardKeys = new Dictionary<string, string>();
+
+ #endregion
+
+ #region 鈻� 鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭_______________
+
+ /// <summary>
+ /// 鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭(閲岄潰鍙礋璐f妸涓滆タ瀛樺叆鏈湴)
+ /// </summary>
+ public bool SynchronizeDbSharedContent()
+ {
+ if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 3)
+ {
+ //鍙湁鎴愬憳鎵嶆湁杩欎釜姒傚康
+ return true;
+ }
+
+ //鑾峰彇涓讳汉鍒嗕韩缁欐垚鍛樼殑鏂囦欢鍒楄〃
+ var listShardInfo = this.GetShardFileListFromDb(Config.Instance.Guid);
+ if (listShardInfo == null)
+ {
+ return false;
+ }
+
+ //涓婚敭
+ var dicAddMark = new Dictionary<string, string>();
+ //妫�娴嬪彇娑堜簡鍏变韩鐨勬搷浣滀娇鐢�
+ var dicShardFile = new Dictionary<string, string>();
+ //鑾峰彇鍓嶅洖鍏变韩鏂囦欢鐨勬洿鏂版棩鏈�(keys:鏂囦欢鍚嶅瓧,value:鏇存柊鏃ユ湡)
+ var dicUpdateTime = this.GetAllShardFileAgoUpdateTime();
+
+ //鍏堢湅鐪嬭繖鍒嗕韩鏁版嵁閲岄潰鏈変粈涔堥
+ foreach (var info in listShardInfo)
+ {
+ //濡傛灉鏄帇缂╂枃浠�,闇�瑕佺壒娈婂鐞�
+ if (info.FileName == SHARED_BIN_FILE)
+ {
+ //鍒ゆ柇Bin鏂囦欢鐨勬洿鏂版棩鏈�
+ if (dicUpdateTime.ContainsKey(info.FileName) == false
+ || info.CreateTime.CompareTo(dicUpdateTime[info.FileName]) > 0)
+ {
+ dicAddMark[info.Id] = info.FileName;
+ //鏇存柊鏃ユ洿鏂�
+ dicUpdateTime[info.FileName] = info.CreateTime;
+ }
+ continue;
+ }
+ dicShardFile[info.FileName] = info.Id;
+
+ //濡傛灉鏈湴娌℃湁,鎴栬�呮洿鏂版棩鏈熷ぇ浜庡墠鍥炴洿鏂版棩鏈熺殑鏃跺��
+ if (Global.IsExistsByHomeId(info.FileName) == false
+ || dicUpdateTime.ContainsKey(info.FileName) == false
+ || info.CreateTime.CompareTo(dicUpdateTime[info.FileName]) > 0)
+ {
+ dicAddMark[info.Id] = info.FileName;
+ //鏇存柊鏃ユ洿鏂�
+ dicUpdateTime[info.FileName] = info.CreateTime;
+ }
+ }
+
+ //涓嶈蹇樿鍒濆鍖栬繖涓笢瑗�
+ this.DicDevices = new Dictionary<string, CommonDevice>();
+ //浠庝簯绔幏鍙栦笅鏉ユ枃浠�
+ if (dicAddMark.Count > 0)
+ {
+ //寮�鍚繘搴︽潯 鍏变韩鏁版嵁鍚屾涓�
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
+
+ //灏嗗垎浜殑鏁版嵁瀛樺叆鏈湴(鑾峰彇鐨勬槸鏈湴娌℃湁鐨�)
+ var listDbFile = this.SetShardFileToLocation(dicAddMark);
+ if (listDbFile == null)
+ {
+ //鍏抽棴
+ ProgressFormBar.Current.Close();
+ return false;
+ }
+
+ //杞Щ鏂囦欢
+ foreach (string fileName in listDbFile)
+ {
+ //涓嶆槸bin鏂囦欢,鍒欑Щ鍔ㄦ枃浠跺埌鏈湴
+ if (fileName != SHARED_BIN_FILE)
+ {
+ var oldPath = Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
+ var newPath = Path.Combine(Config.Instance.FullPath, fileName);
+ HdlFileLogic.Current.CopyFile(oldPath, newPath);
+ }
+ else
+ {
+ //璇诲彇bin鏂囦欢鐨勫唴瀹�
+ var dataContent = this.GetShardFileContent(fileName);
+ if (dataContent != null)
+ {
+ //瑙f瀽bin鏂囦欢
+ this.AdjustBinFileContent(Encoding.UTF8.GetString(dataContent));
+ }
+ }
+ }
+ }
+
+ //鍚屾鏈嶅姟鍣ㄧ殑鍙栨秷浜嗙殑鍒嗕韩鍐呭
+ return this.SynchronizeSharedCancelContent(dicShardFile, dicUpdateTime);
+ }
+
+ /// <summary>
+ /// 鍚屾鏈嶅姟鍣ㄧ殑鍙栨秷浜嗙殑鍒嗕韩鍐呭
+ /// </summary>
+ /// <param name="dicShardFile">浜戠涓婇潰鍒嗕韩鐨勬枃浠�,key:鏂囦欢鍚� value:涓婚敭</param>
+ /// <param name="dicUpdateTime">鍒嗕韩鏂囦欢鐨勬洿鏂版椂闂�,key:鏂囦欢鍚� value:鏃堕棿</param>
+ /// <returns></returns>
+ private bool SynchronizeSharedCancelContent(Dictionary<string, string> dicShardFile, Dictionary<string, string> dicUpdateTime)
+ {
+ //寮�鍚繘搴︽潯 鍏变韩鏁版嵁鍚屾涓�
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
+
+ //閲嶆柊璁剧疆妤煎眰
+ Config.Instance.Home.FloorDics.Clear();
+ foreach (var key in this.DicFloor.Keys)
+ {
+ Config.Instance.Home.FloorDics[key] = this.DicFloor[key];
+ }
+ //鑾峰彇鍒嗕韩鐨勮澶囩殑鏂囦欢鍚�
+ var listShardDeviceFile = new HashSet<string>();
+ foreach (var device in this.DicDevices.Values)
+ {
+ listShardDeviceFile.Add(device.FilePath);
+ }
+ //浣忓畢鐨勬牴鐩綍
+ var localPath = Config.Instance.FullPath;
+
+ //鐒跺悗妫�娴嬫湰鍦扮殑鏂囦欢
+ var listLocalFile = HdlFileLogic.Current.GetRootPathListFile();
+ foreach (string fileName in listLocalFile)
+ {
+ try
+ {
+ if (dicShardFile.ContainsKey(fileName) == true)
+ {
+ //鏈湴鐨勮繖涓枃浠惰繕鍒嗕韩鐫�,娌℃湁闂,鎴栬搴旇鍙湁鍒嗕韩鍥剧墖
+ continue;
+ }
+
+ //妫�娴嬫湰鍦拌澶囨枃浠�,鏄惁瀛樺湪宸茬粡鍙栨秷浜嗗叡浜簡鐨�
+ if (fileName.StartsWith("Device_") == true)
+ {
+ //鍒ゆ柇鏄惁杩樺湪鍒嗕韩鐨刡in鏂囦欢閲岄潰
+ if (listShardDeviceFile.Contains(fileName) == false)
+ {
+ //鍒犻櫎鎺夎繖涓澶囨枃浠�
+ HdlFileLogic.Current.DeleteFile(Path.Combine(localPath, fileName));
+ dicUpdateTime.Remove(fileName);
+ }
+ }
+ //妫�娴嬫湰鍦版埧闂存枃浠�,鏄惁瀛樺湪宸茬粡鍙栨秷浜嗗叡浜簡鐨�
+ else if (fileName.StartsWith("Room_") == true)
+ {
+ var fullFile = Path.Combine(localPath, fileName);
+ var roomData = HdlFileLogic.Current.ReadFileTextContent(fullFile);
+ if (roomData != null)
+ {
+ var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(roomData);
+ if (nowRoom.IsSharedRoom == false || this.DicRooms.ContainsKey(nowRoom.Id) == true)
+ {
+ //杩欎釜鎴块棿鏄粬鑷繁鍒涘缓鐨�,鎴栬�呰繕鍦ㄥ垎浜潃
+ continue;
+ }
+ //鍒犻櫎鎺夎繖涓埧闂存枃浠�
+ HdlFileLogic.Current.DeleteFile(fullFile);
+ dicUpdateTime.Remove(fileName);
+ }
+ }
+ //妫�娴嬫湰鍦板満鏅枃浠�,鏄惁瀛樺湪宸茬粡鍙栨秷浜嗗叡浜簡鐨�
+ else if (fileName.StartsWith("Scene_") == true)
+ {
+ var fullFile = Path.Combine(localPath, fileName);
+ var sceneData = HdlFileLogic.Current.ReadFileTextContent(fullFile);
+ var nowScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(sceneData);
+ if (nowScene != null)
+ {
+ if (nowScene.IsSharedScene == false || this.DicScenes.ContainsKey(nowScene.Id) == true)
+ {
+ //杩欎釜鍦烘櫙鏄粬鑷繁鍒涘缓鐨�,鎴栬�呰繕鍦ㄥ垎浜潃
+ continue;
+ }
+ //鍒犻櫎鎺夎繖涓満鏅枃浠�
+ HdlFileLogic.Current.DeleteFile(fullFile);
+ dicUpdateTime.Remove(fileName);
+ }
+ }
+ }
+ catch { }
+ }
+
+ //淇濆瓨妤煎眰鏁版嵁
+ Config.Instance.Home.Save(false);
+
+ //缃戝叧鏂囦欢闈炲悎娉曟�ф槸鍒锋柊璁惧鍒楄〃鐨勫嚱鏁伴噷闈㈠疄鐜�
+
+ //淇濆瓨鍏ㄩ儴鍒嗕韩鏂囦欢鐨勬洿鏂版棩鏈�
+ this.SaveAllShardFileAgoUpdateTime(dicUpdateTime);
+ //鍏抽棴
+ ProgressFormBar.Current.Close();
+
+ //閲婃斁缂撳瓨
+ this.Dispone();
+
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鍚屾鍐呭鏇存柊鏃堕棿___________________
+
+ /// <summary>
+ /// 鑾峰彇鍏ㄩ儴鍒嗕韩鏂囦欢鐨勫墠鍥炴洿鏂版棩鏈�
+ /// </summary>
+ /// <returns></returns>
+ private Dictionary<string, string> GetAllShardFileAgoUpdateTime()
+ {
+ var dicTime = new Dictionary<string, string>();
+ var data = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.ShardFileUpdateTimeFile);
+ if (data == null)
+ {
+ //鐩爣鏂囦欢涓嶅瓨鍦�
+ return dicTime;
+ }
+ dicTime = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(System.Text.Encoding.UTF8.GetString(data));
+ return dicTime;
+ }
+
+ /// <summary>
+ /// 淇濆瓨鍏ㄩ儴鍒嗕韩鏂囦欢鐨勬洿鏂版棩鏈�
+ /// </summary>
+ /// <param name="dicTime"></param>
+ private void SaveAllShardFileAgoUpdateTime(Dictionary<string, string> dicTime)
+ {
+ HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.ShardFileUpdateTimeFile, dicTime);
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鍒嗕韩鏁版嵁鍒楄〃___________________
+
+ /// <summary>
+ /// 浠庝簯绔幏鍙栧垎浜殑鏂囦欢鍒楄〃
+ /// </summary>
+ /// <param name="i_childAccountId">璐﹀彿鐨刬d,鎴愬憳鐧婚檰鐨勮瘽,鐩存帴浼犺处鍙峰瘑鐮佺櫥闄嗕箣鍚�,浜戠杩斿洖鐨勯偅涓猧d</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/app/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;
+ }
+
+ /// <summary>
+ /// 灏嗗垎浜殑鏁版嵁瀛樺叆鏈湴,杩斿洖鐨勬槸鏂囦欢鍚嶅瓧(寮傚父鏃惰繑鍥瀗ull)
+ /// </summary>
+ /// <param name="dicFileKeys">key:鏂囦欢鐨勪富閿� value:鏂囦欢鍚嶇О</param>
+ /// <returns></returns>
+ private List<string> SetShardFileToLocation(Dictionary<string, string> dicFileKeys)
+ {
+ if (dicFileKeys.Count == 0)
+ {
+ return new List<string>();
+ }
+ //鍒涘缓鏂囦欢澶�
+ string strDir = HdlFileNameResourse.DownLoadShardDirectory;
+ HdlFileLogic.Current.CreateDirectory(strDir, true);
+
+ int listMarkCount = dicFileKeys.Count;
+
+ List<string> listFile = new List<string>();
+
+ //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭
+ Config.Instance.BackKeyCanClick = false;
+ HdlUserCenterResourse.AccountOption.AppCanSignout = false;
+
+ //璁℃暟
+ int nowCount = 0;
+ foreach (var fileKey in dicFileKeys.Keys)
+ {
+ nowCount++;
+ var pra = new { homeId = Config.Instance.Home.Id, homeShareId = fileKey };
+ var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/app/home/share/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺, true, 10);
+ //妫�娴嬬姸鎬佺爜
+ if (result == null)
+ {
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Config.Instance.BackKeyCanClick = true;
+ HdlUserCenterResourse.AccountOption.AppCanSignout = true;
+ return null;
+ }
+ string shareName = dicFileKeys[fileKey];
+ //鏂囦欢鍚嶅瓧
+ listFile.Add(shareName);
+ //淇濆瓨鍒版寚瀹氭枃浠跺す涓�
+ HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(strDir, shareName), result);
+ //璁剧疆杩涘害鍊�
+ ProgressFormBar.Current.SetValue(nowCount, listMarkCount);
+ }
+
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Config.Instance.BackKeyCanClick = true;
+ HdlUserCenterResourse.AccountOption.AppCanSignout = true;
+
+ return listFile;
+ }
+
+ #endregion
+
+
+ #region 鈻� 鍒濆鍖栨垚鍛樺垎浜暟鎹甠________________
+
+ /// <summary>
+ /// 鍒濆鍖栨垚鍛樺叡浜垪琛ㄧ劧鍚庝繚瀛樺埌鏈湴
+ /// </summary>
+ /// <param name="i_ChildAccountId">鎴愬憳ID</param>
+ /// <returns></returns>
+ public bool InitMemberShardContentListAndSetToLocation(string i_ChildAccountId)
+ {
+ if (DicDevices != null)
+ {
+ //宸茬粡鑾峰彇浜�,鍒欎笉鍐嶈幏鍙�
+ return true;
+ }
+
+ //姝e湪鑾峰彇鍒嗕韩鏁版嵁
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting));
+
+ //浠庝簯绔幏鍙栧垎浜殑鏂囦欢鍒楄〃
+ var listData = this.GetShardFileListFromDb(i_ChildAccountId);
+ if (listData == null)
+ {
+ //鍏抽棴杩涘害鏉�
+ ProgressFormBar.Current.Close();
+ return false;
+ }
+
+ //鍒嗕韩鐨勫帇缂╂枃浠剁殑涓婚敭
+ string shardBinKey = string.Empty;
+ foreach (var data in listData)
+ {
+ //濡傛灉鏄繖涓帇缂╂枃浠�
+ if (data.FileName == SHARED_BIN_FILE)
+ {
+ shardBinKey = data.Id;
+ }
+ //璁板綍璧峰畠浠殑涓婚敭
+ this.DicShardKeys[data.FileName] = data.Id;
+ }
+
+ //涓嬭浇鍘嬬缉鐨刡in鏂囦欢,鐒跺悗杩涜瑙f瀽,鍏朵粬鏂囦欢涓嶇敤鐞嗕細
+ bool result = this.DownloadBinFileAndAdjust(shardBinKey);
+ //鍏抽棴杩涘害鏉�
+ ProgressFormBar.Current.Close();
+
+ return result;
+ }
+
+ /// <summary>
+ /// 涓嬭浇鍘嬬缉鐨刡in鏂囦欢,鐒跺悗杩涜瑙f瀽
+ /// </summary>
+ /// <param name="i_binFileId">鍘嬬缉鏂囦欢鐨勪富閿�</param>
+ /// <returns></returns>
+ private bool DownloadBinFileAndAdjust(string i_binFileId)
+ {
+ if (i_binFileId == string.Empty)
+ {
+ //涓嶈蹇樿瑕佸垵濮嬪寲杩欎釜涓滆タ
+ this.DicDevices = new Dictionary<string, CommonDevice>();
+ return true;
+ }
+ var pra = new { homeId = Config.Instance.Home.Id, homeShareId = i_binFileId };
+ var result = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("home-wisdom/app/home/share/downOne", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺, true, 10);
+ //妫�娴嬬姸鎬佺爜
+ if (result == null)
+ {
+ return false;
+ }
+ //涓嶈蹇樿瑕佸垵濮嬪寲杩欎釜涓滆タ
+ this.DicDevices = new Dictionary<string, CommonDevice>();
+
+ //鐩存帴椋欏埌100%
+ ProgressFormBar.Current.SetValue(1);
+
+ var fileContent = Encoding.UTF8.GetString(result);
+ //瑙f瀽鍘嬬缉鐨刡in鏂囦欢
+ this.AdjustBinFileContent(fileContent);
+
+ return true;
+ }
+
+ /// <summary>
+ /// 瑙f瀽鍘嬬缉鐨刡in鏂囦欢
+ /// </summary>
+ /// <param name="i_content"></param>
+ private void AdjustBinFileContent(string i_content)
+ {
+ var deviceType = string.Empty;
+
+ //鏍规嵁鎹㈣绗﹀垏鍒嗘暟鎹枃鏈�
+ string[] arryData = i_content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
+ string strContentData = string.Empty;
+ foreach (string strData in arryData)
+ {
+ if (strData == "#START#")
+ {
+ //鏃犻檮鍔犳暟鎹殑銆愭暟鎹爣棰樸��
+ continue;
+ }
+ if (strData.StartsWith("#DeviceInfo START#") == true)
+ {
+ //闄勫姞鏁版嵁:璁惧瀵硅薄绫诲瀷
+ deviceType = strData.Substring(18);
+ continue;
+ }
+ //鎵ц鏁版嵁澶勭悊
+ try
+ {
+ //鍦烘櫙瀵硅薄
+ if (strData == "#Scene END#")
+ {
+ var scene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(strContentData);
+ this.DicScenes[scene.Id] = scene;
+
+ strContentData = string.Empty;
+ continue;
+ }
+ //妤煎眰瀵硅薄
+ else if (strData == "#FloorInfo END#")
+ {
+ this.DicFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strContentData);
+
+ strContentData = string.Empty;
+ continue;
+ }
+ //鎴块棿瀵硅薄
+ else if (strData == "#RoomInfo END#")
+ {
+ var room = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(strContentData);
+ this.DicRooms[room.Id] = room;
+
+ strContentData = string.Empty;
+ continue;
+ }
+ //璁惧瀵硅薄
+ else if (strData == "#DeviceInfo END#")
+ {
+ //鍙嶅簭鍒楀寲璁惧
+ CommonDevice device = null;
+ if (HdlCheckLogic.Current.CheckIsNumber(deviceType) == true)
+ {
+ //鏁板�煎瀷涓烘柊鏁版嵁,鐩存帴杞崲
+ device = CommonDevice.CommonDeviceByByteString(Convert.ToInt32(deviceType), strContentData);
+ }
+ else
+ {
+ //瀛楃涓插瀷涓烘棫鏁版嵁,闇�瑕佺壒娈婂鐞�
+ var myType = (DeviceType)Enum.Parse(typeof(DeviceType), deviceType);
+ device = CommonDevice.CommonDeviceByByteString((int)myType, strContentData);
+ }
+ if (device != null)
+ {
+ this.DicDevices[HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device)] = device;
+ }
+ strContentData = string.Empty;
+ continue;
+ }
+ else
+ {
+ strContentData += strData;
+ }
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex, "鍒嗕韩bin鏂囦欢鍑洪棶棰榎r\n" + strContentData);
+ strContentData = string.Empty;
+ }
+ }
+ }
+
+ #endregion
+
+
+ #region 鈻� 涓婁紶鍒嗕韩鍐呭_______________________
+
+ /// <summary>
+ /// 鎵ц涓婁紶鏂扮殑鍒嗕韩(璁惧鍜屽満鏅粎闄愬悓涓�涓埧闂�)
+ /// </summary>
+ /// <param name="i_ChildAccountId">鎴愬憳鐨処D</param>
+ /// <param name="i_nowRoom">鎸囧畾鐨勬埧闂�</param>
+ /// <param name="i_listDevice">閫夋嫨涓婁紶鐨勮澶�(浠呴檺涓�涓埧闂�)</param>
+ /// <param name="i_listScene">閫夋嫨涓婁紶鐨勫満鏅�(浠呴檺涓�涓埧闂�,涓嶈鑾峰彇瀹冮噷闈㈢殑缁戝畾鍒楄〃)</param>
+ public bool UploadSharedContent(string i_ChildAccountId, Room i_nowRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene)
+ {
+ if (i_listDevice.Count == 0 && i_listScene.Count == 0)
+ {
+ return true;
+ }
+ //鎵撳紑杩涘害鏉�
+ ProgressBar.Show();
+
+ var listCheck = new HashSet<string>();
+
+ //鑾峰彇鍦烘櫙閲岄潰宓屽鐨勫瓙璁惧鍜屽瓙鍦烘櫙(杩欏嚑涓笢瑗夸笉鍔犲埌鎴块棿)
+ var listChirdDevice = new List<CommonDevice>();
+ var listChirdScene = new List<SceneUI>();
+ foreach (var SceneTemp in i_listScene)
+ {
+ //浠庣紦瀛樿幏鍙栧満鏅殑鎵ц鐩爣
+ this.GetSceneAdjustTargetListFromLocal(SceneTemp, listCheck, listChirdScene, listChirdDevice);
+ }
+ //鍏嬮殕涓�涓埧闂村嚭鏉�
+ var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(i_nowRoom);
+ if (this.DicRooms.ContainsKey(cloneRoom.Id) == true)
+ {
+ //鎶婂師鏉ョ殑鐨勪笢瑗夸篃澶嶅埗杩囨潵
+ cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice);
+ cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac);
+ cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId);
+ }
+ else
+ {
+ //杩欓噷鏈夌偣鐗规畩,濡傛灉涓嶅瓨鍦ㄧ殑璇�,鎶婄湡瀹炶澶囩殑鍖哄煙涓㈣繃鍘�,鍥犱负鍙槸涓婚敭鑰屽凡
+ cloneRoom.ListDeviceMac.AddRange(i_nowRoom.ListDeviceMac);
+ }
+ //鐒跺悗鎶婂満鏅拰璁惧涓㈠埌杩欎釜鍏嬮殕鐨勫璞¢噷闈㈠幓
+ foreach (var device in i_listDevice)
+ {
+ string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ if (cloneRoom.ListDevice.Contains(mainKey) == false)
+ {
+ //涓㈣澶囪繃鍘�
+ cloneRoom.ListDevice.Add(mainKey);
+ }
+ }
+ foreach (var secne in i_listScene)
+ {
+ if (cloneRoom.ListSceneId.Contains(secne.Id) == false)
+ {
+ //涓㈠満鏅繃鍘�
+ cloneRoom.ListSceneId.Add(secne.Id);
+ }
+ }
+ //鑾峰彇闇�瑕佷笂浼犵殑鍥剧墖
+ var listUploadPic = this.GetUploadPictrueFile(new List<Room> { cloneRoom }, i_listScene, listChirdScene);
+ //鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭
+ var binfFileContent = this.CreatShardBinContentOnAdd(new List<Room> { cloneRoom }, i_listDevice, i_listScene, listChirdDevice, listChirdScene);
+
+ //璁剧疆鏈�澶у��
+ ProgressBar.SetMaxValue(listUploadPic.Count + 1);
+
+ //涓婁紶bin鏂囦欢
+ var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent));
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ ProgressBar.SetValue(1);
+
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ binfFileContent = null;
+
+ //涓婁紶鍥剧墖
+ foreach (var fileName in listUploadPic)
+ {
+ var byteData = HdlFileLogic.Current.ReadFileByteContent(Path.Combine(Config.Instance.FullPath, fileName));
+ if (byteData != null)
+ {
+ fileKey = this.DoUploadShardContent(i_ChildAccountId, fileName, byteData);
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ }
+ ProgressBar.SetValue(1);
+ }
+ //濡傛灉鍏ㄩ儴鎴愬姛浜嗙殑璇�,瑕嗙洊缂撳瓨
+ this.DicDevices.Clear();
+ this.DicScenes.Clear();
+ this.DicRooms.Clear();
+ this.DicFloor.Clear();
+ this.AdjustBinFileContent(binfFileContent);
+
+ //鍒犻櫎宸茬粡涓嶅啀鍒嗕韩鐨勫浘鐗�
+ this.DeleteNotShardPictrue();
+
+ ProgressBar.Close();
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鎵ц涓婁紶鏂扮殑鍒嗕韩鎴块棿(鏁翠釜鎴块棿鍒嗕韩)
+ /// </summary>
+ /// <param name="i_ChildAccountId">鎴愬憳鐨処D</param>
+ /// <param name="i_listRoom">闇�瑕佸垎浜殑鎴块棿</param>
+ public bool UploadSharedRoom(string i_ChildAccountId, List<Room> i_listRoom)
+ {
+ //鎵撳紑杩涘害鏉�
+ ProgressBar.Show();
+
+ //璁╄澶囧拰鍦烘櫙涓嶉噸澶嶇殑涓滆タ
+ var listCheck = new HashSet<string>();
+ //鍏嬮殕鎴块棿
+ var listCloneRoom = new List<Room>();
+ //娣诲姞鐨勮澶�
+ var listDevice = new List<CommonDevice>();
+ //娣诲姞鐨勫満鏅�
+ var listScene = new List<SceneUI>();
+
+ foreach (var room in i_listRoom)
+ {
+ //鍏嬮殕涓�涓埧闂村嚭鏉�
+ var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(room);
+ if (this.DicRooms.ContainsKey(cloneRoom.Id) == true)
+ {
+ //鎶婂師鏉ョ殑鐨勪笢瑗夸篃澶嶅埗杩囨潵
+ cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice);
+ cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac);
+ cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId);
+ }
+ else
+ {
+ //杩欓噷鏈夌偣鐗规畩,濡傛灉涓嶅瓨鍦ㄧ殑璇�,鎶婄湡瀹炶澶囩殑鍖哄煙涓㈣繃鍘�,鍥犱负鍙槸涓婚敭鑰屽凡
+ cloneRoom.ListDeviceMac.AddRange(room.ListDeviceMac);
+ }
+ listCloneRoom.Add(cloneRoom);
+
+ //鑾峰彇璁惧瀵硅薄
+ foreach (var mainkey in cloneRoom.ListDevice)
+ {
+ var device = HdlDeviceCommonLogic.Current.GetDevice(mainkey);
+ if (device != null)
+ {
+ listDevice.Add(device);
+ }
+ listCheck.Add(mainkey);
+ }
+ //鑾峰彇鍦烘櫙瀵硅薄
+ foreach (var sceneId in cloneRoom.ListSceneId)
+ {
+ var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
+ if (scene != null)
+ {
+ listScene.Add(scene);
+ }
+ listCheck.Add(sceneId.ToString());
+ //浠庣紦瀛樿幏鍙栧満鏅殑鎵ц鐩爣
+ this.GetSceneAdjustTargetListFromLocal(scene, listCheck, listScene, listDevice);
+ }
+ }
+
+ //鑾峰彇闇�瑕佷笂浼犵殑鍥剧墖
+ var listUploadPic = this.GetUploadPictrueFile(listCloneRoom, listScene, new List<SceneUI>());
+ //鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭
+ var binfFileContent = this.CreatShardBinContentOnAdd(listCloneRoom, listDevice, listScene, new List<CommonDevice>(), new List<SceneUI>());
+
+ //璁剧疆鏈�澶у��
+ ProgressBar.SetMaxValue(listUploadPic.Count + 1);
+
+ //涓婁紶bin鏂囦欢
+ var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent));
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ ProgressBar.SetValue(1);
+
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ binfFileContent = null;
+
+ //涓婁紶鍥剧墖
+ foreach (var fileName in listUploadPic)
+ {
+ var byteData = HdlFileLogic.Current.ReadFileByteContent(Path.Combine(Config.Instance.FullPath, fileName));
+ if (byteData != null)
+ {
+ fileKey = this.DoUploadShardContent(i_ChildAccountId, fileName, byteData);
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ }
+ ProgressBar.SetValue(1);
+ }
+ //濡傛灉鍏ㄩ儴鎴愬姛浜嗙殑璇�,瑕嗙洊缂撳瓨
+ this.DicDevices.Clear();
+ this.DicScenes.Clear();
+ this.DicRooms.Clear();
+ this.DicFloor.Clear();
+ this.AdjustBinFileContent(binfFileContent);
+
+ //鍒犻櫎宸茬粡涓嶅啀鍒嗕韩鐨勫浘鐗�
+ this.DeleteNotShardPictrue();
+
+ ProgressBar.Close();
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鍒犻櫎宸茬粡涓嶅啀鍒嗕韩鐨勫浘鐗�(涓嶇敤绠¤繑鍥炲��,鍗充娇澶辫触涔熸病浜�)
+ /// </summary>
+ private void DeleteNotShardPictrue()
+ {
+ var listPictrue = new List<string>();
+ foreach (var room in this.DicRooms.Values)
+ {
+ if (room.BackgroundImageType != 0)
+ {
+ //鎴块棿鍥剧墖
+ listPictrue.Add(room.BackgroundImage);
+ }
+ }
+ foreach (var scene in this.DicScenes.Values)
+ {
+ if (scene.IconPathType != 0)
+ {
+ //鍦烘櫙鍥剧墖
+ listPictrue.Add(scene.IconPath);
+ }
+ }
+ var listDeleteFile = new List<string>();
+ foreach (var fileName in this.DicShardKeys.Keys)
+ {
+ //濡傛灉鏄埧闂存垨鑰呭満鏅殑鍥剧墖
+ if (fileName.StartsWith("RoomIcon_") == true || fileName.StartsWith("SceneIcon_") == true)
+ {
+ if (listPictrue.Contains(fileName) == false)
+ {
+ //杩欎釜鍥剧墖鍙樻洿浜�,闇�瑕佸垹闄ゆ帀
+ listDeleteFile.Add(fileName);
+ }
+ }
+ }
+ //鍒犻櫎鍥剧墖
+ this.DoDeleteSharedContent(listDeleteFile, ShowNetCodeMode.No);
+ }
+
+ /// <summary>
+ /// 涓婁紶鍒嗕韩鍐呭(杩斿洖涓婚敭)
+ /// </summary>
+ /// <param name="i_childAccountId">瀛愯处鍙风殑涓婚敭</param>
+ /// <param name="i_fileName">鏂囦欢鍚嶅瓧</param>
+ /// <param name="i_content">鏂囦欢鍐呭</param>
+ /// <returns></returns>
+ private string DoUploadShardContent(string i_childAccountId, string i_fileName, byte[] i_content)
+ {
+ var dicQuery = new Dictionary<string, object>();
+ dicQuery["homeId"] = Config.Instance.Home.Id;
+ dicQuery["childAccountId"] = i_childAccountId;
+ dicQuery["fileName"] = i_fileName;
+
+ var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/share/add", RestSharp.Method.POST, i_content, dicQuery, null, CheckMode.A璐﹀彿鏉冮檺, true, 10);
+ //妫�娴嬬姸鎬佺爜
+ if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
+ {
+ return null;
+ }
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveShardInfoResult>(result.Data.ToString());
+ return info.Id;
+ }
+
+ #endregion
+
+ #region 鈻� 涓婁紶鍒嗕韩鍐呭杈呭姪鏂规硶_______________
+
+ /// <summary>
+ /// 浠庢湰鍦拌幏鍙栧満鏅噷闈㈢殑鎵ц鐩爣鍒楄〃
+ /// </summary>
+ /// <param name="scene">鍦烘櫙</param>
+ /// <param name="listCheck">閲嶅妫�娴嬬敤</param>
+ /// <param name="listSceneUI">娣诲姞鍒嗕韩鐨勫満鏅垪琛�</param>
+ /// <param name="listDevice">娣诲姞鍒嗕韩鐨勮澶囧垪琛�</param>
+ /// <returns></returns>
+ private void GetSceneAdjustTargetListFromLocal(SceneUI scene, HashSet<string> listCheck, List<SceneUI> listSceneUI, List<CommonDevice> listDevice)
+ {
+ foreach (var data in scene.AdjustTargetList)
+ {
+ //璁惧
+ if (data.Type == 0)
+ {
+ string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+ if (listCheck.Contains(mainKeys) == true)
+ {
+ //涓嶉噸澶嶆坊鍔�
+ continue;
+ }
+ listCheck.Add(mainKeys);
+
+ var device = HdlDeviceCommonLogic.Current.GetDevice(data.DeviceAddr, data.Epoint);
+ if (device != null)
+ {
+ listDevice.Add(device);
+ }
+ }
+ //鍦烘櫙
+ else if (data.Type == 1)
+ {
+ string mainKeys = data.ElseScenesId.ToString();
+ if (listCheck.Contains(mainKeys) == true)
+ {
+ //涓嶉噸澶嶆坊鍔�
+ continue;
+ }
+ listCheck.Add(mainKeys);
+
+ //鑾峰彇鍦烘櫙瀵硅薄
+ var sceneUi = HdlSceneLogic.Current.GetSceneUIBySceneId(data.ElseScenesId);
+ if (sceneUi != null)
+ {
+ listSceneUI.Add(sceneUi);
+ //閫掑綊鑾峰彇鎵ц鐩爣
+ this.GetSceneAdjustTargetListFromLocal(sceneUi, listCheck, listSceneUI, listDevice);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇闇�瑕佷笂浼犵殑鍥剧墖鍚嶅瓧
+ /// </summary>
+ /// <param name="i_listRoom">鎴块棿瀵硅薄</param>
+ /// <param name="i_listScene">鍦烘櫙瀵硅薄</param>
+ /// <param name="i_listChirdScene">鍦烘櫙瀵硅薄</param>
+ /// <returns></returns>
+ private List<string> GetUploadPictrueFile(List<Room> i_listRoom, List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene)
+ {
+ var listPic = new List<string>();
+ foreach (var room in i_listRoom)
+ {
+ if (room.BackgroundImageType != 0 && this.DicShardKeys.ContainsKey(room.BackgroundImage) == false)
+ {
+ //鑷畾涔夊浘鐗�
+ listPic.Add(room.BackgroundImage);
+ }
+ }
+ foreach (var scene in i_listScene)
+ {
+ if (scene.IconPathType != 0 && this.DicShardKeys.ContainsKey(scene.IconPath) == false)
+ {
+ //鑷畾涔夊浘鐗�
+ listPic.Add(scene.IconPath);
+ }
+ }
+ foreach (var scene in i_listChirdScene)
+ {
+ if (scene.IconPathType != 0 && this.DicShardKeys.ContainsKey(scene.IconPath) == false)
+ {
+ //鑷畾涔夊浘鐗�
+ listPic.Add(scene.IconPath);
+ }
+ }
+ return listPic;
+ }
+
+ #endregion
+
+
+ #region 鈻� 鍒犻櫎鍒嗕韩鍐呭_______________________
+
+ /// <summary>
+ /// 绉婚櫎鎸囧畾鍒嗕韩鍐呭(璁惧鍜屽満鏅粎闄愬悓涓�涓埧闂�)
+ /// </summary>
+ /// <param name="i_ChildAccountId">鎴愬憳ID</param>
+ /// <param name="i_nowRoom">鎸囧畾鐨勬埧闂�</param>
+ /// <param name="i_listDevice">閫夋嫨涓婁紶鐨勮澶�(浠呴檺涓�涓埧闂�)</param>
+ /// <param name="i_listScene">閫夋嫨涓婁紶鐨勫満鏅�(浠呴檺涓�涓埧闂�,涓嶈鑾峰彇瀹冮噷闈㈢殑缁戝畾鍒楄〃)</param>
+ /// <returns></returns>
+ public bool DeleteSharedContent(string i_ChildAccountId, Room i_nowRoom,
+ List<CommonDevice> i_listDevice, List<SceneUI> i_listScene)
+ {
+ //鍏嬮殕涓�涓埧闂村嚭鏉�
+ var cloneRoom = HdlRoomLogic.Current.CloneRoomClass(i_nowRoom);
+ if (this.DicRooms.ContainsKey(cloneRoom.Id) == true)
+ {
+ //鎶婂師鏉ョ殑鐨勪笢瑗夸篃澶嶅埗杩囨潵
+ cloneRoom.ListDevice.AddRange(this.DicRooms[cloneRoom.Id].ListDevice);
+ cloneRoom.ListDeviceMac.AddRange(this.DicRooms[cloneRoom.Id].ListDeviceMac);
+ cloneRoom.ListSceneId.AddRange(this.DicRooms[cloneRoom.Id].ListSceneId);
+ }
+
+ //璁╄澶囧拰鍦烘櫙涓嶉噸澶嶆坊鍔犵殑涓滆タ
+ var listCheck = new HashSet<string>();
+
+ //鐒跺悗鎶婂満鏅拰璁惧浠庤繖涓厠闅嗙殑瀵硅薄閲岄潰绉婚櫎鎺�(鐪熷疄鐗╃悊璁惧鐨勬埧闂翠笉鐢ㄧ悊)
+ foreach (var device in i_listDevice)
+ {
+ string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ cloneRoom.ListDevice.Remove(mainKey);
+
+ listCheck.Add(mainKey);
+ }
+ foreach (var secne in i_listScene)
+ {
+ cloneRoom.ListSceneId.Remove(secne.Id);
+
+ listCheck.Add(secne.Id.ToString());
+ }
+ //濡傛灉閮界Щ闄ゅ畬鐨勮瘽,鍒欑洿鎺ヨ蛋鍒犻櫎鍒嗕韩鎴块棿鐨勬柟娉�
+ if (cloneRoom.ListDevice.Count == 0 && cloneRoom.ListSceneId.Count == 0)
+ {
+ //鎵ц鏁翠釜鎴块棿鍒犻櫎鐨勬柟娉�
+ return this.DeleteSharedRoom(i_ChildAccountId, new List<Room> { i_nowRoom });
+ }
+ //鑾峰彇鍦烘櫙閲岄潰宓屽鐨勫瓙璁惧鍜屽瓙鍦烘櫙
+ foreach (var sceneTemp in i_listScene)
+ {
+ //浠庣紦瀛樿幏鍙栧満鏅殑鎵ц鐩爣
+ this.GetSceneAdjustTargetListFromShard(sceneTemp, listCheck, i_listScene, i_listDevice);
+ }
+ //鍦ㄥ垹闄や竴涓埧闂翠腑鐨勪竴浜涜澶囩殑妯″紡涓�,妫�娴嬭澶囧拰鍦烘櫙鏄惁鑳藉鍒犻櫎(鏈夊彲鑳藉畠杩樺湪鍒殑鎴块棿鎴栬�呭満鏅綋涓�)
+ var listDelDevice = new List<CommonDevice>();
+ var listDelScene = new List<SceneUI>();
+ this.CheckDeviceAndSceneCanDeleteOnDeleteSome(i_listDevice, i_listScene, ref listDelDevice, ref listDelScene, cloneRoom);
+
+ //鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭(杩欓噷涓嶇敤鍒犻櫎鎴块棿)
+ var binfFileContent = this.CreatShardBinContentOnDelete(new List<Room>(), listDelDevice, listDelScene);
+
+ //涓婁紶bin鏂囦欢
+ var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent));
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ ProgressBar.SetValue(1);
+
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ binfFileContent = null;
+
+ //濡傛灉鍏ㄩ儴鎴愬姛浜嗙殑璇�,瑕嗙洊缂撳瓨
+ this.DicDevices.Clear();
+ this.DicScenes.Clear();
+ this.DicRooms.Clear();
+ this.DicFloor.Clear();
+ this.AdjustBinFileContent(binfFileContent);
+
+ //鍒犻櫎宸茬粡涓嶅啀鍒嗕韩鐨勫浘鐗�
+ this.DeleteNotShardPictrue();
+
+ ProgressBar.Close();
+
+ return true;
+ }
+
+ /// <summary>
+ /// 绉婚櫎鎸囧畾鍒嗕韩鍐呭(鏁翠釜鎴块棿鍒犻櫎)
+ /// </summary>
+ /// <param name="i_ChildAccountId">鎴愬憳ID</param>
+ /// <param name="i_listRoom">闇�瑕佹暣涓垹闄ょ殑鎴块棿</param>
+ /// <returns></returns>
+ public bool DeleteSharedRoom(string i_ChildAccountId, List<Room> i_listRoom)
+ {
+ //鎵撳紑杩涘害鏉�
+ ProgressBar.Show();
+ //璁剧疆鏈�澶у��
+ ProgressBar.SetMaxValue(1);
+
+ //鑾峰彇鍒犻櫎鎴块棿鐨勫叏閮ㄥ叏閮ㄨ澶囧拰鍦烘櫙
+ var listDevice = new List<CommonDevice>();
+ var listScene = new List<SceneUI>();
+ this.GetDeleteRoomAllDeviceAndScene(i_listRoom, ref listDevice, ref listScene);
+
+ //鍒犻櫎鐨勬埧闂碔D
+ var listDeleteRoom = new List<string>();
+ foreach (var room in i_listRoom)
+ {
+ //鍒ゆ柇鍦烘櫙鍜岃澶囨槸鍚﹁兘鍒犻櫎鏃朵娇鐢�
+ listDeleteRoom.Add(room.Id);
+ }
+ //鍦ㄥ垹闄ゆ暣涓埧闂寸殑妯″紡涓�,妫�娴嬭澶囧拰鍦烘櫙鏄惁鑳藉鍒犻櫎(鏈夊彲鑳藉畠杩樺湪鍒殑鎴块棿鎴栬�呭満鏅綋涓�)
+ var listDelDevice = new List<CommonDevice>();
+ var listDelScene = new List<SceneUI>();
+ this.CheckDeviceAndSceneCanDeleteOnDeleteRoom(listDevice, listScene, ref listDelDevice, ref listDelScene, listDeleteRoom);
+
+ //鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭
+ var binfFileContent = this.CreatShardBinContentOnDelete(i_listRoom, listDelDevice, listDelScene);
+
+ //涓婁紶bin鏂囦欢
+ var fileKey = this.DoUploadShardContent(i_ChildAccountId, SHARED_BIN_FILE, Encoding.UTF8.GetBytes(binfFileContent));
+ if (fileKey == null)
+ {
+ ProgressBar.Close();
+ return false;
+ }
+ ProgressBar.SetValue(1);
+
+ //璁板綍涓婚敭
+ this.DicShardKeys[SHARED_BIN_FILE] = fileKey;
+ binfFileContent = null;
+
+ //濡傛灉鍏ㄩ儴鎴愬姛浜嗙殑璇�,瑕嗙洊缂撳瓨
+ this.DicDevices.Clear();
+ this.DicScenes.Clear();
+ this.DicRooms.Clear();
+ this.DicFloor.Clear();
+ this.AdjustBinFileContent(binfFileContent);
+
+ //鍒犻櫎宸茬粡涓嶅啀鍒嗕韩鐨勫浘鐗�
+ this.DeleteNotShardPictrue();
+
+ ProgressBar.Close();
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鎵ц绉婚櫎鍒嗕韩鏁版嵁
+ /// </summary>
+ /// <param name="listDelFile">鍒犻櫎鐨勬枃浠�</param>
+ /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+ /// <returns></returns>
+ private bool DoDeleteSharedContent(List<string> listDelFile, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+ {
+ if (listDelFile.Count == 0)
+ {
+ return true;
+ }
+ foreach (var fileName in listDelFile)
+ {
+ if (this.DicShardKeys.ContainsKey(fileName) == false)
+ {
+ //鎴戜篃涓嶇煡閬撲负浠�涔堜細鎵句笉鍒颁富閿�
+ continue;
+ }
+ var pra = new { homeId = Config.Instance.Home.Id, homeShareId = this.DicShardKeys[fileName] };
+ //鎵ц鍒犻櫎
+ var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/share/delete", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+ //妫�娴嬬姸鎬佺爜
+ if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+ {
+ return false;
+ }
+ //绉婚櫎缂撳瓨
+ this.DicShardKeys.Remove(fileName);
+ }
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鍒犻櫎鍒嗕韩鍐呭杈呭姪鏂规硶_______________
+
+ /// <summary>
+ /// 鑾峰彇鍒犻櫎鎴块棿鐨勫叏閮ㄥ叏閮ㄨ澶囧拰鍦烘櫙
+ /// </summary>
+ /// <param name="i_listRoom">鍒犻櫎鐨勬埧闂�</param>
+ /// <param name="listDevice">鍏ㄩ儴璁惧(杩斿洖鍊�)</param>
+ /// <param name="listScene">鍏ㄩ儴鍦烘櫙(杩斿洖鍊�)</param>
+ private void GetDeleteRoomAllDeviceAndScene(List<Room> i_listRoom, ref List<CommonDevice> listDevice, ref List<SceneUI> listScene)
+ {
+ var listCheck = new HashSet<string>();
+ foreach (var room in i_listRoom)
+ {
+ //鑾峰彇璁惧
+ foreach (var mainkey in room.ListDevice)
+ {
+ if (listCheck.Contains(mainkey) == true) { continue; }
+ listCheck.Add(mainkey);
+
+ //鍒嗕韩鏁版嵁閲岄潰鏈夋墠娣诲姞
+ if (this.DicDevices.ContainsKey(mainkey) == true)
+ {
+ listDevice.Add(this.DicDevices[mainkey]);
+ }
+ }
+ //鐒跺悗鍐嶈幏鍙栧満鏅�
+ foreach (var sceneId in room.ListSceneId)
+ {
+ if (listCheck.Contains(sceneId.ToString()) == true) { continue; }
+ listCheck.Add(sceneId.ToString());
+
+ //鍒嗕韩鏁版嵁閲岄潰鏈夋墠娣诲姞
+ if (this.DicScenes.ContainsKey(sceneId) == true)
+ {
+ var sceneTemp = this.DicScenes[sceneId];
+ listScene.Add(sceneTemp);
+
+ //鑾峰彇鍦烘櫙閲岄潰宓屽鐨勫瓙璁惧鍜屽瓙鍦烘櫙
+ this.GetSceneAdjustTargetListFromShard(sceneTemp, listCheck, listScene, listDevice);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鍦ㄥ垹闄ゆ暣涓埧闂寸殑妯″紡涓�,妫�娴嬭澶囧拰鍦烘櫙鏄惁鑳藉鍒犻櫎(鏈夊彲鑳藉畠杩樺湪鍒殑鎴块棿鎴栬�呭満鏅綋涓�)
+ /// </summary>
+ /// <param name="i_listDevice">鐞嗚涓婅鍒犻櫎鐨勮澶�</param>
+ /// <param name="i_listScene">鐞嗚涓婅鍒犻櫎鐨勫満鏅�</param>
+ /// <param name="listDeleteDevice">鐪熷疄鑳藉鍒犻櫎鐨勮澶�(杩斿洖鍊�)</param>
+ /// <param name="listDeleteScene">鐪熷疄鑳藉鍒犻櫎鐨勫満鏅�(杩斿洖鍊�)</param>
+ /// <param name="i_listDelleteRoom">鍒犻櫎鐨勬埧闂�</param>
+ private void CheckDeviceAndSceneCanDeleteOnDeleteRoom(List<CommonDevice> i_listDevice, List<SceneUI> i_listScene,
+ ref List<CommonDevice> listDeleteDevice, ref List<SceneUI> listDeleteScene, List<string> i_listNotCheckRoom)
+ {
+ //娉ㄦ剰锛氳繖涓嚱鏁板拰涓嬮潰鐨凜heckDeviceAndSceneCanDeleteOnDeleteSome鏈夋湰璐ㄥ尯鍒�
+ //杩欎釜鍙槸瀹屽叏鍒犻櫎涓�涓埧闂村唴鐨勮澶囨垨鑰呭満鏅�,鍥犳鍙渶瑕佸幓鍒ゆ柇鍒犻櫎浠ュ鐨勫氨鍙互浜�
+
+ //鑾峰彇鐞嗚涓婇渶瑕佸垹闄ょ殑鍦烘櫙ID
+ var listSceneId = new List<int>();
+ foreach (var scene in i_listScene)
+ {
+ listSceneId.Add(scene.Id);
+ }
+ var listShardDevice = new HashSet<string>();
+ var listShardScene = new HashSet<int>();
+ //鑾峰彇闄や簡鐞嗚涓婇渶瑕佸垹闄ょ殑鍦烘櫙涔嬪锛岀洰鍓嶈繕鍒嗕韩鐨勫満鏅殑鎵ц鐩爣閲岄潰鐨勮澶�
+ foreach (var scene in this.DicScenes.Values)
+ {
+ //杩欎釜鏄鍒犻櫎鐨勫満鏅�
+ if (listSceneId.Contains(scene.Id) == true) { continue; }
+
+ foreach (var data in scene.AdjustTargetList)
+ {
+ //璁惧
+ if (data.Type == 0)
+ {
+ var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ listShardDevice.Add(mainkey);
+ }
+ }
+ //瀛愬満鏅�
+ else if (data.Type == 1)
+ {
+ if (listShardScene.Contains(data.ElseScenesId) == false)
+ {
+ listShardScene.Add(data.ElseScenesId);
+ }
+ }
+ }
+ }
+ //鑾峰彇闄や簡鐞嗚涓婇渶瑕佸垹闄ょ殑鎴块棿涔嬪锛岀洰鍓嶈繕鍒嗕韩鐨勮澶�
+ foreach (var room in this.DicRooms.Values)
+ {
+ //杩欎釜鏄鍒犻櫎鐨勬埧闂�
+ if (i_listNotCheckRoom.Contains(room.Id) == true) { continue; }
+
+ foreach (var mainkey in room.ListDevice)
+ {
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ listShardDevice.Add(mainkey);
+ }
+ }
+ foreach (var sceneId in room.ListSceneId)
+ {
+ if (listShardScene.Contains(sceneId) == false)
+ {
+ listShardScene.Add(sceneId);
+ }
+ }
+ }
+
+ //鍒ゆ柇瀹為檯鑳藉鍒犻櫎鐨勮澶�
+ foreach (var device in i_listDevice)
+ {
+ var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ //杩欎釜璁惧宸茬粡涓嶅湪鍒嗕韩
+ listDeleteDevice.Add(device);
+ }
+ }
+ //鍒ゆ柇瀹為檯鑳藉鍒犻櫎鐨勫満鏅�
+ foreach (var scene in i_listScene)
+ {
+ if (listShardScene.Contains(scene.Id) == false)
+ {
+ //杩欎釜鍦烘櫙宸茬粡涓嶅湪鍒嗕韩
+ listDeleteScene.Add(scene);
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鍦ㄥ垹闄や竴涓埧闂翠腑鐨勪竴浜涜澶囩殑妯″紡涓�,妫�娴嬭澶囧拰鍦烘櫙鏄惁鑳藉鍒犻櫎(鏈夊彲鑳藉畠杩樺湪鍒殑鎴块棿鎴栬�呭満鏅綋涓�)
+ /// </summary>
+ /// <param name="i_listDevice">鐞嗚涓婅鍒犻櫎鐨勮澶�</param>
+ /// <param name="i_listScene">鐞嗚涓婅鍒犻櫎鐨勫満鏅�</param>
+ /// <param name="listDeleteDevice">鐪熷疄鑳藉鍒犻櫎鐨勮澶�(杩斿洖鍊�)</param>
+ /// <param name="listDeleteScene">鐪熷疄鑳藉鍒犻櫎鐨勫満鏅�(杩斿洖鍊�)</param>
+ /// <param name="i_nowCloneRoom">褰撳墠鎴块棿(鍏嬮殕)</param>
+ private void CheckDeviceAndSceneCanDeleteOnDeleteSome(List<CommonDevice> i_listDevice, List<SceneUI> i_listScene,
+ ref List<CommonDevice> listDeleteDevice, ref List<SceneUI> listDeleteScene, Room i_nowCloneRoom)
+ {
+ //娉ㄦ剰锛氳繖涓嚱鏁板拰涓婇潰鐨凜heckDeviceAndSceneCanDeleteOnDeleteRoom鏈夋湰璐ㄥ尯鍒�
+ //杩欎釜鍙槸鍒犻櫎涓�涓埧闂村唴鐨勯儴鍒嗚澶囨垨鑰呭満鏅�,鍥犳瀹冩湁鍙兘鑷韩灏卞祵濂楃潃瑕佸垹闄ょ殑璁惧鎴栬�呭満鏅�
+
+ //鍏堣幏鍙栫洰鍓嶈繕鍦ㄥ垎浜殑璁惧鍜屽満鏅�
+ var listShardDevice = new HashSet<string>();
+ var listShardScene = new HashSet<int>();
+
+ foreach (var roomId in this.DicRooms.Keys)
+ {
+ //濡傛灉鏄綋鍓嶅厠闅嗙殑鎴块棿,鍒欑敤鍏嬮殕鐨勬埧闂存潵澶勭悊,鍏嬮殕鐨勬埧闂村凡缁忔妸鐞嗚涓婅鍒犻櫎鐨勮澶囧拰鍦烘櫙閮藉垹闄や簡
+ var room = i_nowCloneRoom.Id != roomId ? this.DicRooms[roomId] : i_nowCloneRoom;
+ //杩樺湪鍒嗕韩鐨勮澶�
+ foreach (var mainkey in room.ListDevice)
+ {
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ listShardDevice.Add(mainkey);
+ }
+ }
+ //杩樺湪鍒嗕韩鐨勫満鏅�
+ foreach (var sceneId in room.ListSceneId)
+ {
+ if (listShardScene.Contains(sceneId) == false)
+ {
+ listShardScene.Add(sceneId);
+ }
+ //浠庡満鏅殑鎵ц鐩爣褰撳墠鑾峰彇
+ if (this.DicScenes.ContainsKey(sceneId) == true)
+ {
+ foreach (var data in this.DicScenes[sceneId].AdjustTargetList)
+ {
+ //瀛愯澶�
+ if (data.Type == 0)
+ {
+ var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ listShardDevice.Add(mainkey);
+ }
+ }
+ //瀛愬満鏅�
+ else if (data.Type == 1)
+ {
+ if (listShardScene.Contains(data.ElseScenesId) == false)
+ {
+ listShardScene.Add(data.ElseScenesId);
+ }
+ }
+ }
+ }
+ }
+ }
+ //鍒ゆ柇瀹為檯鑳藉鍒犻櫎鐨勮澶�
+ foreach (var device in i_listDevice)
+ {
+ var mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ if (listShardDevice.Contains(mainkey) == false)
+ {
+ //杩欎釜璁惧宸茬粡涓嶅湪鍒嗕韩
+ listDeleteDevice.Add(device);
+ }
+ }
+ //鍒ゆ柇瀹為檯鑳藉鍒犻櫎鐨勫満鏅�
+ foreach (var scene in i_listScene)
+ {
+ if (listShardScene.Contains(scene.Id) == false)
+ {
+ //杩欎釜鍦烘櫙宸茬粡涓嶅湪鍒嗕韩
+ listDeleteScene.Add(scene);
+ }
+ }
+ }
+
+ /// <summary>
+ /// 浠庡垎浜暟鎹噷闈㈣幏鍙栧満鏅噷闈㈢殑鎵ц鐩爣鍒楄〃
+ /// </summary>
+ /// <param name="scene">鍦烘櫙</param>
+ /// <param name="listCheck">閲嶅妫�娴嬬敤</param>
+ /// <param name="listSceneUI">娣诲姞鍒嗕韩鐨勫満鏅垪琛�</param>
+ /// <param name="listDevice">娣诲姞鍒嗕韩鐨勮澶囧垪琛�</param>
+ /// <returns></returns>
+ private void GetSceneAdjustTargetListFromShard(SceneUI scene, HashSet<string> listCheck, List<SceneUI> listSceneUI, List<CommonDevice> listDevice)
+ {
+ foreach (var data in scene.AdjustTargetList)
+ {
+ //璁惧
+ if (data.Type == 0)
+ {
+ string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
+ if (listCheck.Contains(mainKeys) == true)
+ {
+ //涓嶉噸澶嶆坊鍔�
+ continue;
+ }
+ listCheck.Add(mainKeys);
+ if (this.DicDevices.ContainsKey(mainKeys) == true)
+ {
+ listDevice.Add(this.DicDevices[mainKeys]);
+ }
+ }
+ //鍦烘櫙
+ else if (data.Type == 1)
+ {
+ string mainKeys = data.ElseScenesId.ToString();
+ if (listCheck.Contains(mainKeys) == true)
+ {
+ //涓嶉噸澶嶆坊鍔�
+ continue;
+ }
+ listCheck.Add(mainKeys);
+
+ //鑾峰彇鍦烘櫙瀵硅薄
+ if (this.DicScenes.ContainsKey(data.ElseScenesId) == true)
+ {
+ var sceneUi = this.DicScenes[data.ElseScenesId];
+ listSceneUI.Add(sceneUi);
+
+ //閫掑綊鑾峰彇鎵ц鐩爣
+ this.GetSceneAdjustTargetListFromShard(sceneUi, listCheck, listSceneUI, listDevice);
+ }
+ }
+ }
+ }
+
+
+ #endregion
+
+
+ #region 鈻� 鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭________________
+
+ /// <summary>
+ /// 鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭(鏂板妯″紡)
+ /// </summary>
+ /// <param name="i_listNewRoom">鏂扮殑鎴块棿瀵硅薄闆嗗悎(涔熷氨鏄彉鏇翠簡鐨勬埧闂�)</param>
+ /// <param name="i_listDevice">杩欎釜鏄渶瑕佽拷鍔犵殑鍒嗕韩璁惧</param>
+ /// <param name="i_listScene">杩欎釜鏄渶瑕佽拷鍔犵殑鍒嗕韩鍦烘櫙</param>
+ /// <param name="i_listChirdDevice">杩欎釜鏄敱鍦烘櫙鐨勬墽琛岀洰鏍囨潵鐨�</param>
+ /// <param name="i_listChirdScene">杩欎釜鏄敱鍦烘櫙鐨勬墽琛岀洰鏍囨潵鐨�</param>
+ /// <returns></returns>
+ private string CreatShardBinContentOnAdd(List<Room> i_listNewRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene,
+ List<CommonDevice> i_listChirdDevice, List<SceneUI> i_listChirdScene)
+ {
+ string writeText = string.Empty;
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囧璞℃暟鎹��
+ this.CreatWriteCommonDeviceData(i_listDevice, i_listChirdDevice, false, ref writeText);
+
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
+ this.CreatWriteSceneData(i_listScene, i_listChirdScene, false, ref writeText);
+
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
+ this.CrearWriteRoomData(i_listNewRoom, false, ref writeText);
+
+ return writeText;
+ }
+
+ /// <summary>
+ /// 鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭(鍒犻櫎妯″紡)
+ /// </summary>
+ /// <param name="i_listDelRoom">瑕佸垹闄ょ殑鎴块棿</param>
+ /// <param name="i_listDevice">杩欎釜鏄渶瑕佸垹闄ょ殑鍒嗕韩璁惧</param>
+ /// <param name="i_listScene">杩欎釜鏄渶瑕佸垹闄ょ殑鍒嗕韩鍦烘櫙</param>
+ /// <returns></returns>
+ private string CreatShardBinContentOnDelete(List<Room> i_listDelRoom, List<CommonDevice> i_listDevice, List<SceneUI> i_listScene)
+ {
+ string writeText = string.Empty;
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囧璞℃暟鎹��
+ this.CreatWriteCommonDeviceData(i_listDevice, new List<CommonDevice>(), true, ref writeText);
+
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
+ this.CreatWriteSceneData(i_listScene, new List<SceneUI>(), true, ref writeText);
+
+ //鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
+ this.CrearWriteRoomData(i_listDelRoom, true, ref writeText);
+
+ return writeText;
+ }
+
+ /// <summary>
+ /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囧璞℃暟鎹��
+ /// </summary>
+ /// <param name="writeText"></param>
+ private void CreatWriteCommonDeviceData(List<CommonDevice> i_listDevice, List<CommonDevice> i_listChirdDevice, bool i_isDel, ref string writeText)
+ {
+ //鍚堝苟璁惧鍒颁竴涓柊鐨勫璞″綋涓�
+ var dicNewDevice = this.MergeNewShardDevices(i_listDevice, i_listChirdDevice, i_isDel);
+ var listCheck = new HashSet<string>();
+ foreach (var device in dicNewDevice.Values)
+ {
+ //璁惧绔偣
+ writeText += "#DeviceInfo START#" + (int)device.Type + "\r\n";
+ string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(device);
+ writeText += dataInfo + "\r\n";
+ writeText += "#DeviceInfo END#\r\n\r\n";
+
+ //娣诲姞Ota璁惧瀵硅薄鐨勭紦瀛�
+ if (listCheck.Contains(device.DeviceAddr) == false)
+ {
+ listCheck.Add(device.DeviceAddr);
+ var otaDevice = HdlDeviceCommonLogic.Current.GetOTADevice(device.DeviceAddr);
+ if (otaDevice != null)
+ {
+ writeText += "#DeviceInfo START#" + (int)otaDevice.Type + "\r\n";
+ string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(otaDevice);
+ writeText += dataInfo2 + "\r\n";
+ writeText += "#DeviceInfo END#\r\n\r\n";
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
+ /// </summary>
+ /// <param name="i_listScene">杩欎釜鏄渶瑕佽拷鍔犵殑鍒嗕韩鍦烘櫙</param>
+ /// <param name="i_listChirdScene">杩欎釜鏄敱鍦烘櫙鐨勬墽琛岀洰鏍囨潵鐨�</param>
+ /// <param name="writeText"></param>
+ private void CreatWriteSceneData(List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene, bool i_isDel, ref string writeText)
+ {
+ //鍚堝苟鍦烘櫙鍒颁竴涓柊鐨勫璞″綋涓�
+ var dicNewScene = this.MergeNewShardScenes(i_listScene, i_listChirdScene, i_isDel);
+
+ foreach (var scene in dicNewScene.Values)
+ {
+ writeText += "#START#\r\n";
+ string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(scene);
+ writeText += dataInfo + "\r\n";
+ writeText += "#SceneTemplate END#\r\n\r\n";
+ }
+ }
+
+ /// <summary>
+ /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愭埧闂存ā鏉挎暟鎹��
+ /// </summary>
+ /// <param name="i_listNewRoom">鏂扮殑鎴块棿瀵硅薄闆嗗悎(涔熷氨鏄彉鏇翠簡鐨勬埧闂�)</param>
+ /// <param name="writeText"></param>
+ private void CrearWriteRoomData(List<Room> i_listNewRoom, bool i_isDel, ref string writeText)
+ {
+ var dicNewFloor = new Dictionary<string, string>();
+ //鍚堝苟鍒嗕韩鐨勬埧闂村埌涓�涓柊鐨勫璞′腑
+ var dicNewRoom = this.MergeNewShardRooms(i_listNewRoom, i_isDel);
+ foreach (var room in dicNewRoom.Values)
+ {
+ writeText += "#START#\r\n";
+ string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(room);
+ writeText += dataInfo2 + "\r\n";
+ writeText += "#RoomInfo END#\r\n\r\n";
+
+ if (room.FloorId != string.Empty)
+ {
+ dicNewFloor[room.FloorId] = HdlResidenceLogic.Current.GetFloorNameById(room.FloorId);
+ }
+ }
+ //妤煎眰鏁版嵁
+ writeText += "#START#\r\n";
+ string dataInfo1 = Newtonsoft.Json.JsonConvert.SerializeObject(dicNewFloor);
+ writeText += dataInfo1 + "\r\n";
+ writeText += "#FloorInfo END#\r\n\r\n";
+ }
+
+ #endregion
+
+ #region 鈻� 鐢熸垚鍒嗕韩Bin鏂囦欢鍐呭杈呭姪鏂规硶________
+
+ /// <summary>
+ /// 鍚堝苟鍒嗕韩鐨勮澶囧埌涓�涓柊鐨勫璞′腑
+ /// </summary>
+ /// <param name="i_listDevice">杩欎釜鏄渶瑕佽拷鍔犵殑鍒嗕韩璁惧</param>
+ /// <param name="i_listChirdDevice">杩欎釜鏄敱鍦烘櫙鐨勬墽琛岀洰鏍囨潵鐨�</param>
+ /// <param name="i_isDel">鏄惁鏄垹闄ゅ垎浜ā寮�</param>
+ /// <returns></returns>
+ private Dictionary<string, CommonDevice> MergeNewShardDevices(List<CommonDevice> i_listDevice, List<CommonDevice> i_listChirdDevice, bool i_isDel)
+ {
+ var dicNewDevice = new Dictionary<string, CommonDevice>();
+ //鍏堝悎骞跺師鏉ョ殑
+ foreach (var key in this.DicDevices.Keys)
+ {
+ dicNewDevice[key] = this.DicDevices[key];
+ }
+ //鍐嶅悎骞舵柊娣诲姞鐨�
+ foreach (var device in i_listDevice)
+ {
+ string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ if (i_isDel == false)
+ {
+ //鐩存帴瑕嗙洊,娌¢棶棰�
+ dicNewDevice[mainkey] = device;
+ }
+ else
+ {
+ //鍒犻櫎妯″紡
+ dicNewDevice.Remove(mainkey);
+ }
+ }
+ foreach (var device in i_listChirdDevice)
+ {
+ string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+ //鐩存帴瑕嗙洊,娌¢棶棰�
+ dicNewDevice[mainkey] = device;
+ }
+ return dicNewDevice;
+ }
+
+ /// <summary>
+ /// 鍚堝苟鍒嗕韩鐨勫満鏅埌涓�涓柊鐨勫璞′腑
+ /// </summary>
+ /// <param name="i_listScene">杩欎釜鏄渶瑕佽拷鍔犵殑鍒嗕韩鍦烘櫙</param>
+ /// <param name="i_listChirdScene">杩欎釜鏄敱鍦烘櫙鐨勬墽琛岀洰鏍囨潵鐨�</param>
+ /// <param name="i_isDel">鏄惁鏄垹闄ゅ垎浜ā寮�</param>
+ /// <returns></returns>
+ private Dictionary<int, SceneUI> MergeNewShardScenes(List<SceneUI> i_listScene, List<SceneUI> i_listChirdScene, bool i_isDel)
+ {
+ var dicNewScene = new Dictionary<int, SceneUI>();
+ //鍏堝悎骞跺師鏉ョ殑
+ foreach (var key in this.DicScenes.Keys)
+ {
+ dicNewScene[key] = this.DicScenes[key];
+ }
+ //鍐嶅悎骞舵柊娣诲姞鐨�
+ foreach (var scene in i_listScene)
+ {
+ if (i_isDel == false)
+ {
+ //鐩存帴瑕嗙洊,娌¢棶棰�
+ dicNewScene[scene.Id] = scene;
+ }
+ else
+ {
+ //鍒犻櫎妯″紡
+ dicNewScene.Remove(scene.Id);
+ }
+ }
+ foreach (var scene in i_listChirdScene)
+ {
+ //鐩存帴瑕嗙洊,娌¢棶棰�
+ dicNewScene[scene.Id] = scene;
+ }
+ return dicNewScene;
+ }
+
+ /// <summary>
+ /// 鍚堝苟鍒嗕韩鐨勬埧闂村埌涓�涓柊鐨勫璞′腑
+ /// </summary>
+ /// <param name="i_listNewRoom">鏂扮殑鎴块棿瀵硅薄闆嗗悎(涔熷氨鏄彉鏇翠簡鐨勬埧闂�)</param>
+ /// <param name="i_isDel">鏄惁鏄垹闄ゅ垎浜ā寮�</param>
+ /// <returns></returns>
+ private Dictionary<string, Room> MergeNewShardRooms(List<Room> i_listNewRoom, bool i_isDel)
+ {
+ var dicNewRoom = new Dictionary<string, Room>();
+ //鍏堝悎骞跺師鏉ョ殑
+ foreach (var key in this.DicRooms.Keys)
+ {
+ dicNewRoom[key] = this.DicRooms[key];
+ }
+ //鍐嶅悎骞舵柊娣诲姞鐨�
+ foreach (var room in i_listNewRoom)
+ {
+ if (i_isDel == false)
+ {
+ //鐩存帴瑕嗙洊,娌¢棶棰�
+ dicNewRoom[room.Id] = room;
+ }
+ else
+ {
+ //鍒犻櫎妯″紡
+ dicNewRoom.Remove(room.Id);
+ }
+ }
+ return dicNewRoom;
+ }
+
+ #endregion
+
+
+ #region 鈻� 鑾峰彇鍒嗕韩缂撳瓨鏂规硶___________________
+
+ /// <summary>
+ /// 浠庣紦瀛樺綋涓幏鍙栧垎浜殑璁惧
+ /// </summary>
+ /// <param name="i_deviceKey">璁惧鐨勪富閿�</param>
+ /// <returns></returns>
+ public CommonDevice GetShardDeviceFromMemory(string i_deviceKey)
+ {
+ if (this.DicDevices.ContainsKey(i_deviceKey) == true)
+ {
+ return this.DicDevices[i_deviceKey];
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// 浠庣紦瀛樺綋涓幏鍙栧垎浜殑鍦烘櫙
+ /// </summary>
+ /// <param name="i_sceneId">鍦烘櫙ID</param>
+ /// <returns></returns>
+ public SceneUI GetShardSceneFromMemory(int i_sceneId)
+ {
+ if (this.DicScenes.ContainsKey(i_sceneId) == true)
+ {
+ return this.DicScenes[i_sceneId];
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// 浠庣紦瀛樺綋涓幏鍙栧垎浜殑鎴块棿
+ /// </summary>
+ /// <returns></returns>
+ public Dictionary<string, Room> GetShardRoomFromMemory()
+ {
+ return this.DicRooms;
+ }
+
+ /// <summary>
+ /// 浠庣紦瀛樺綋涓幏鍙栧垎浜殑鎴块棿
+ /// </summary>
+ /// <param name="i_roomId">鎴块棿ID</param>
+ /// <returns></returns>
+ public Room GetShardRoomFromMemory(string i_roomId)
+ {
+ if (this.DicRooms.ContainsKey(i_roomId) == true)
+ {
+ return this.DicRooms[i_roomId];
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// 浠庣紦瀛樺綋涓幏鍙栧垎浜殑妤煎眰
+ /// </summary>
+ /// <returns></returns>
+ public Dictionary<string, string> GetShardFloorFormMemory()
+ {
+ return this.DicFloor;
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 鑾峰彇鍒嗕韩鏂囦欢鐨勫唴瀹�
+ /// </summary>
+ /// <param name="fileName">鏂囦欢鍚嶇О(涓嶆槸鍏ㄨ矾寰�)</param>
+ /// <returns></returns>
+ private byte[] GetShardFileContent(string fileName)
+ {
+ string fullName = System.IO.Path.Combine(HdlFileNameResourse.DownLoadShardDirectory, fileName);
+ if (System.IO.File.Exists(fullName) == false)
+ {
+ return null;
+ }
+ var varByte = HdlFileLogic.Current.ReadFileByteContent(fullName);
+ return varByte;
+ }
+
+ /// <summary>
+ /// 娓呯┖鍏变韩缂撳瓨
+ /// </summary>
+ public void Dispone()
+ {
+ this.DicDevices = null;
+ this.DicScenes.Clear();
+ this.DicRooms.Clear();
+ this.DicShardKeys.Clear();
+ this.DicFloor.Clear();
+
+ //娓呯┖鏂囦欢澶�
+ string strDir = HdlFileNameResourse.DownLoadShardDirectory;
+ HdlFileLogic.Current.CreateDirectory(strDir, true);
+
+ m_Current = null;
+ }
+
+ #endregion
+
+ #region 鈻� 缁撴瀯浣撶被___________________________
+
+ /// <summary>
+ /// 鎺ユ敹鍒嗕韩鏁版嵁
+ /// </summary>
+ private class ReceiveShardInfoResult
+ {
+ /// <summary>
+ /// 鏂囦欢鍚嶅瓧
+ /// </summary>
+ public string FileName = string.Empty;
+ /// <summary>
+ /// 鏇存柊鏃堕棿
+ /// </summary>
+ public string CreateTime = string.Empty;
+ /// <summary>
+ /// 涓婚敭
+ /// </summary>
+ public string Id = string.Empty;
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0