From e90209beae6a4e822cecb18e6889f8bda23f630e Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 14 十二月 2020 11:16:06 +0800 Subject: [PATCH] 合并了晾衣架(非新云端) --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs | 514 +++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 359 insertions(+), 155 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs similarity index 75% rename from ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs rename to ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlShardLogic.cs index e8b39fe..8bd809a 100644 --- a/ZigbeeApp/Shared/Phone/Common/Logic/HdlShardLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/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> /// 灏嗗垎浜殑鏁版嵁瀛樺叆鏈湴,杩斿洖鐨勬槸鏂囦欢鍚嶅瓧(寮傚父鏃惰繑鍥瀗ull),璋冪敤 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">浜戠涓婇潰鍒嗕韩鐨勬枃浠�,涓篘ull鏃朵粠鏂拌幏鍙� key:鏂囦欢鍚� value:涓婚敭</param> + /// <param name="listShardFile">浜戠涓婇潰鍒嗕韩鐨勬枃浠�,涓篘ull鏃朵粠鏂拌幏鍙�</param> /// <param name="dicUpdateTime">鍒嗕韩鏂囦欢鐨勬洿鏂版椂闂�,涓篘ull鏃朵粠鏂拌幏鍙�</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">璐﹀彿鐨刬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/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) { //鎬ц兘浼樺寲锛氬鏋滄湰鍦版嫢鏈夎繖涓枃浠剁殑璇�,鐩存帴浣跨敤閭d釜鏂囦欢 - 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); } //灏嗗垎浜殑鏁版嵁瀛樺叆鏈湴,杩斿洖鐨勬槸鏂囦欢鍚嶅瓧(寮傚父鏃惰繑鍥瀗ull) - 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; + } + //杩欓噷鏈夌偣鐗规畩锛屾帴鍙f槸鐩存帴杩斿洖涓婚敭鍥炴潵鐨勶紝鑰屼笉鏄疛soin + 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) + { + //杩欓噷鏈夌偣鐗规畩锛屾帴鍙f槸鐩存帴杩斿洖涓婚敭鍥炴潵鐨勶紝鑰屼笉鏄疛soin + 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 -- Gitblit v1.8.0