From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期二, 30 八月 2022 09:37:38 +0800 Subject: [PATCH] 合并了IOS的代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs | 1860 ++++++++++++++++++++++++++++++----------------------------- 1 files changed, 942 insertions(+), 918 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs old mode 100755 new mode 100644 index 04a86a6..098a278 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs @@ -1,921 +1,945 @@ -锘縰sing Shared.Common; -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; -using System.Net; -using System.Text; - -namespace Shared.Phone.UserCenter -{ - /// <summary> - /// 澶囦唤涓氬姟鐨勯�昏緫 - /// </summary> - public class HdlBackupLogic - { - #region 鈻� 鍙橀噺澹版槑___________________________ - - /// <summary> - /// 澶囦唤涓氬姟鐨勯�昏緫 +锘縰sing Shared.Common; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Net; +using System.Text; + +namespace Shared.Phone.UserCenter +{ + /// <summary> + /// 澶囦唤涓氬姟鐨勯�昏緫 + /// </summary> + public class HdlBackupLogic + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 澶囦唤涓氬姟鐨勯�昏緫 /// </summary> private static HdlBackupLogic m_Current = null; - /// <summary> - /// 澶囦唤涓氬姟鐨勯�昏緫 + /// <summary> + /// 澶囦唤涓氬姟鐨勯�昏緫 /// </summary> - public static HdlBackupLogic Current - { - get - { - if (m_Current == null) - { - m_Current = new HdlBackupLogic(); - } - return m_Current; - } - } - - #endregion - - #region 鈻� 鑾峰彇澶囦唤鍚嶅瓧鍒楄〃___________________ - - /// <summary> - /// 浠庝簯绔幏鍙栧浠芥暟鎹殑鍚嶅瓧鍒楄〃 - /// </summary> - /// <param name="ZigbeeBackupType">0:App鎵嬪姩澶囦唤 1: App 鑷姩澶囦唤 2锛氱綉鍏虫墜鍔ㄥ浠� 3:缃戝叧鑷姩澶囦唤</param> - /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,鑾峰彇缃戝叧澶囦唤闇�瑕�</param> - /// <param name="getOptionBackup">鏄惁鑾峰彇鍔熻兘澶囦唤</param> - /// <returns></returns> - public List<BackupListNameInfo> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false) - { - //澶囦唤鍚嶅瓧寰堝皯鐨勫唴瀛橈紝鍙互鐩存帴涓�娆℃�у叏閮ㄥ彇瀹� - var pra = new GetBackupListPra(); - pra.BackupType = ZigbeeBackupType; - pra.GatewayUniqueId = ZigbeeUniqueId; - pra.PageSetting.Page = 1; - pra.PageSetting.PageSize = 99999; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - //璁块棶鎺ュ彛 - string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupPagger", true, pra); - if (string.IsNullOrEmpty(result) == true) - { - return null; - } - - var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult>(result); - var list = new List<BackupListNameInfo>(); - foreach (var data2 in data.PageData) - { - if (ZigbeeUniqueId != null && data2.GatewayUniqueId != ZigbeeUniqueId) - { - continue; - } - if (getOptionBackup == false && data2.BackupName == DirNameResourse.OptionBackupName) - { - //涓嶈幏鍙栧姛鑳藉浠� - continue; - } - list.Add(data2); - } - return list; - } - - /// <summary> - /// <para>浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�</para> - /// <para>杩斿洖鏂囦欢澶瑰悕瀛�(閲岄潰瀛樻斁鐫�鍏ㄩ儴鐨勬枃浠�),杩斿洖null鏃讹紝浠h〃澶辫触</para> - /// </summary> - /// <param name="BackupClassId">BackupClassId</param> - /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param> - /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param> - /// <returns></returns> - public string GetBackFileFromDBAndSetToLocation(string BackupClassId, bool IsGatewayAutoBackup = false, string ZigbeeUniqueId = null) - { - //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭 - Shared.Common.CommonPage.BackKeyCanClick = false; - UserCenterResourse.AccountOption.AppCanSignout = false; - - //棣栧厛鍏堝垱寤轰竴涓复鏃舵枃浠跺す,瀛樺湪鏂囦欢鍒欐竻绌� - string newDir = DirNameResourse.DownLoadBackupTempDirectory; - HdlFileLogic.Current.CreateDirectory(newDir, true); - - //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢 - List<string> listFile = GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId); - if (listFile == null) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - return null; - } - - var pra = new LoadBackInfoPra(); - pra.BackupClassId = BackupClassId; - pra.IsGatewayAutoBackup = IsGatewayAutoBackup; - pra.GatewayUniqueId = ZigbeeUniqueId; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - //涓�涓釜鐨勪笅杞芥枃浠� - int listFileCount = listFile.Count; - for (int i = 0; i < listFile.Count; i++) - { - string fileName = listFile[i]; - //璐﹀彿宸茬粡閫�鍑� - if (HdlCheckLogic.Current.IsAccountLoginOut() == true) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - return null; - } - - //鈽呰缃渶瑕佽幏鍙栫殑鏂囦欢鍚嶅瓧鈽� - pra.BackupFileName = fileName; - var result = UserCenterLogic.GetByteResponseDataByRequestHttps("App/DownloadSomeDataBackup", true, pra, null, true); - if (result == null) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - return null; - } - //灏嗚緭鍏ュ啓鍏ユ湰鍦扮殑涓存椂鏂囦欢澶� - HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(newDir, fileName), result); - //璁剧疆杩涘害鍊� - ProgressFormBar.Current.SetValue(i + 1, listFileCount); - } - - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - - return newDir; - } - - /// <summary> - /// 浠庝簯绔幏鍙栧叏閮ㄧ殑澶囦唤鏂囦欢鐨勫悕瀛� - /// </summary> - /// <param name="BackupClassId">BackupClassId</param> - /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param> - /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param> - /// <returns></returns> - private List<string> GetBackFileIDFromDB(string BackupClassId, bool IsGatewayAutoBackup, string ZigbeeUniqueId) - { - var pra = new LoadBackInfoPra(); - pra.BackupClassId = BackupClassId; - pra.PageSetting.PageSize = 999999; - pra.PageSetting.Page = 1; - pra.IsGatewayAutoBackup = IsGatewayAutoBackup; - pra.GatewayUniqueId = ZigbeeUniqueId; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - //棣栧厛鍏堣幏鍙栦簯绔湁浠�涔堟枃浠� - string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupUploadListPagger", true, pra); - if (string.IsNullOrEmpty(result) == true) - { - return null; - } - var fileListData = Newtonsoft.Json.JsonConvert.DeserializeObject<LoadBackInfoResult>(result); - - //鑾峰彇鏂囦欢鍚嶅瓧 - List<string> listFileName = new List<string>(); - foreach (LoadBackupFileNameInfo file in fileListData.PageData) - { - listFileName.Add(file.BackupFileName); - } - return listFileName; - } - - #endregion - - #region 鈻� 鍒涘缓澶囦唤___________________________ - - /// <summary> - /// 鍒涘缓涓�涓浠藉悕瀛�(鎴愬姛鏃惰繑鍥炲浠界殑涓婚敭ID锛屽け璐ユ椂杩斿洖null) - /// </summary> - /// <param name="backupName">澶囦唤鍚嶅瓧</param> - /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> - /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,褰揗anualBackupType=2鏃�,姝ゅ�间笉鑳戒负绌�!</param> - /// <returns></returns> - public string CreatNewBackupNameToDB(string backupName, int ManualBackupType = 0, string ZigbeeUniqueId = null) - { - var pra = new AddBackUpNamePra(); - pra.BackupName = backupName; - pra.ManualBackupType = ManualBackupType; - pra.GatewayUniqueId = ZigbeeUniqueId; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - var result = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHomeAppGatewayName", true, pra); - if (string.IsNullOrEmpty(result) == true) - { - return null; - } - var data = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult>(result); - - return data.BackupClassId; - } - - #endregion - - #region 鈻� 涓婁紶澶囦唤___________________________ - - /// <summary> - /// 涓婁紶鏈湴鎵�鏈夋枃浠跺埌浜戠(鍑芥暟鍐呴儴鏈夎繘搴︽潯) - /// </summary> - /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> - /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> - /// <param name="upPath">鎸囧畾涓婁紶鐨勬槸鍝釜鏂囦欢澶圭殑鏂囦欢(鍏ㄨ矾寰�),涓嶆寚瀹氭椂锛屼笂浼犵殑鏄湰鍦拌矾寰勪笅鐨勬枃浠�</param> - /// <param name="showBar">鏄惁璁剧疆鏄剧ず杩涘害鏉�</param> - /// <returns></returns> - public bool UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true) - { - List<string> listAllFile = null; - //鏂囦欢澶圭殑鍏ㄨ矾寰� - string fullDir = string.Empty; - string localTemplateName = string.Empty; - if (upPath == string.Empty) - { - //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑 - var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(); - var templateFile = TemplateData.TemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate"); - - //灏嗘ā鏉縝in鏂囦欢绉诲姩鍒板浠芥枃浠跺す涓� - localTemplateName = System.IO.Path.Combine(Config.Instance.FullPath, templateName); - try { System.IO.File.Move(templateFile, localTemplateName); } - catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "绉诲姩妯℃澘澶辫触"); } - - //鑾峰彇鏈湴鏂囦欢 - listAllFile = HdlFileLogic.Current.GetRootPathListFile(); - fullDir = Common.Config.Instance.FullPath; - } - else - { - listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath); - fullDir = upPath; - } - if (listAllFile.Count == 0) - { - return true; - } - - //鏅�氭枃浠讹紝鍙互涓�娆℃�т笂浼犲涓殑 - List<string> listNormalFile = new List<string>(); - //鍥剧墖鏂囦欢锛岃繖涓笢瑗垮緢澶э紝闇�瑕佺嫭绔嬪嚭鏉� - List<string> listPicFile = new List<string>(); - - foreach (string fileName in listAllFile) - { - //鍒ゆ柇鎸囧畾鏂囦欢鏄惁闇�瑕佷笂浼�(鏍圭洰褰曠殑鎵嶅垽鏂�) - if (upPath == string.Empty && this.IsNotUpLoadFile(fileName) == true) - { - continue; - } - if (fileName.EndsWith(".png") == true - || fileName.EndsWith(".bin") == true) - { - //鍥剧墖鏂囦欢 - listPicFile.Add(fileName); - continue; - } - listNormalFile.Add(fileName); - } - - //寮�鍚繘搴︽潯 - int listFileCount = listPicFile.Count + listNormalFile.Count; - if (showBar == true) - { - //寮�鍚繘搴︽潯 姝e湪涓婁紶澶囦唤鏂囦欢 - ProgressFormBar.Current.Start(); - ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading)); - } - - //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭 - Shared.Common.CommonPage.BackKeyCanClick = false; - UserCenterResourse.AccountOption.AppCanSignout = false; - - //浣犺涓轰粈涔堣繖閲屼笉鍒嗕竴涓嚱鏁板嚭鏉ワ紙鐞嗚涓婃槸鍒嗗嚱鏁板嚭鏉ョ殑锛� - //鏄洜涓哄鏋滃垎鍑芥暟鐨勮瘽锛屼細鍑虹幇鍙岄噸寮傛锛屽鑷翠富绾跨▼鐨勮繘搴︽潯鐨勭櫨鍒嗘瘮姘歌繙瀹氭0% - for (int i = 0; i < listNormalFile.Count; i++) - { - string file = listNormalFile[i]; - //璐﹀彿宸茬粡閫�鍑� - if (HdlCheckLogic.Current.IsAccountLoginOut() == true) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - if (localTemplateName != string.Empty) - { - //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� - HdlFileLogic.Current.DeleteFile(localTemplateName); - } - return false; - } - //鏁寸悊鏁版嵁 - var datainfo = new FileInfoData(); - datainfo.BackupFileName = file; - string fullFileName = System.IO.Path.Combine(fullDir, file); - datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(fullFileName); - - var list = new List<FileInfoData>(); - list.Add(datainfo); - - //鎵ц涓婁紶 - bool falge = DoUpLoadInfoToDB(BackupClassId, list, ManualBackupType); - if (falge == false) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - if (localTemplateName != string.Empty) - { - //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� - HdlFileLogic.Current.DeleteFile(localTemplateName); - } - return false; - } - //璁剧疆杩涘害鍊� - ProgressFormBar.Current.SetValue(i + 1, listFileCount); - } - - for (int i = 0; i < listPicFile.Count; i++) - { - string file = listPicFile[i]; - //璐﹀彿宸茬粡閫�鍑� - if (HdlCheckLogic.Current.IsAccountLoginOut() == true) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - if (localTemplateName != string.Empty) - { - //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� - HdlFileLogic.Current.DeleteFile(localTemplateName); - } - return false; - } - - var listPic = new List<string>(); - listPic.Add(file); - - //涓婁紶鏈湴鍥剧墖鏂囦欢鍒颁簯绔� - bool result = UpLoadBigBackupFileToDB(fullDir, listPic, BackupClassId, ManualBackupType); - if (result == false) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - if (localTemplateName != string.Empty) - { - //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� - HdlFileLogic.Current.DeleteFile(localTemplateName); - } - return false; - } - //璁剧疆杩涘害鍊� - ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount); - } - - if (localTemplateName != string.Empty) - { - //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� - HdlFileLogic.Current.DeleteFile(localTemplateName); - } - - //杩涘害鏉″叧闂� - ProgressFormBar.Current.Close(); - //鍏佽鎸夌郴缁熺殑杩斿洖閿� - Shared.Common.CommonPage.BackKeyCanClick = true; - UserCenterResourse.AccountOption.AppCanSignout = true; - - return true; - } - - /// <summary> - /// 鎵ц涓婁紶鍒颁簯绔� - /// </summary> - /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> - /// <param name="listData">涓婁紶鐨勬暟鎹�</param> - /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> - /// <returns></returns> - private bool DoUpLoadInfoToDB(string BackupClassId, List<FileInfoData> listData, int ManualBackupType = 0) - { - var upData = new UpLoadDataPra(); - upData.ManualBackupType = ManualBackupType; - upData.BackupClassId = BackupClassId; - upData.UploadSubFileLists = listData; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/UploadHomeAppGatewaySubFiles", true, upData, null, true); - if (falge == false) - { - return false; - } - return true; - } - - /// <summary> - /// 涓婁紶鏈湴鍥剧墖鏂囦欢鍒颁簯绔� - /// </summary> - /// <param name="fullDir">鏂囦欢澶圭殑鍏ㄨ矾寰�</param> - /// <param name="listPicFile">鍥剧墖鏂囦欢鍒楄〃</param> - /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> - /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> - /// <returns></returns> - private bool UpLoadBigBackupFileToDB(string fullDir, List<string> listPicFile, string BackupClassId, int ManualBackupType = 0) - { - foreach (string fileName in listPicFile) - { - string fullName = System.IO.Path.Combine(fullDir, fileName); - - NameValueCollection nvc = new NameValueCollection(); - nvc.Add("RequestVersion", Common.CommonPage.RequestVersion); - nvc.Add("LoginAccessToken", UserCenterLogic.GetConnectMainToken()); - nvc.Add("HomeId", Shared.Common.Config.Instance.Home.Id); - nvc.Add("BackupClassId", BackupClassId); - nvc.Add("ManualBackupType", ManualBackupType.ToString()); - nvc.Add("IsOtherAccountCtrl", Common.Config.Instance.Home.IsOthreShare.ToString()); - - string base64 = GetBase64Text(fullName); - nvc.Add("UploadSubFileLists[0].BackupFileName", fileName); - nvc.Add("UploadSubFileLists[0].BackupFileContent", base64); - - bool result = UpLoadBigBackupFileToDB("App/UploadHomeAppGatewaySubFiles", fullName, nvc); - if (result == false) - { - return false; - } - } - return true; - } - - /// <summary> - /// 涓婁紶澶ф枃浠� - /// </summary> - /// <param name="RequestName">璇锋眰鎺ュ彛</param> - /// <param name="fullFileName">鏂囦欢鍚嶅瓧(鍚矾寰�)</param> - /// <param name="nvc"></param> - /// <returns></returns> - private bool UpLoadBigBackupFileToDB(string RequestName, string fullFileName, NameValueCollection nvc) - { - string paramName = "file"; - string contentType = "application/octet-stream"; - string requestUrl = string.Empty; - //鍚敤绠$悊鍛樻潈闄� - if (Config.Instance.Home.IsOthreShare == 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"); - - HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(requestUrl); - wr.ContentType = "multipart/form-data; boundary=" + boundary; - wr.Method = "POST"; - wr.KeepAlive = true; - wr.Credentials = System.Net.CredentialCache.DefaultCredentials; - - Stream 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); - - FileStream 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); - - return UserCenterLogic.CheckNotEorrorMsg(data, requestUrl); - } - catch - { - return false; - } - finally - { - if (wresp != null) - { - wresp.Close(); - wresp = null; - } - wr = null; - } - } - - #endregion - - #region 鈻� 涓婁紶Log澶囦唤________________________ - - /// <summary> - /// 涓婁紶Log澶囦唤(闅愬尶鍔熻兘) - /// </summary> - /// <returns></returns> - public bool UpLoadLogBackup() - { - string upPath = DirNameResourse.LogDirectory; - if (HdlFileLogic.Current.GetFileFromDirectory(upPath).Count == 0) - { - //娌℃湁Log鏂囦欢 - return true; - } - - ProgressFormBar.Current.Start(); - ProgressFormBar.Current.SetMsg("姝e湪涓婁紶Log鏂囦欢"); - - //浠庝簯绔幏鍙栨暟鎹� - var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true); - if (pageData == null) - { - ProgressFormBar.Current.Close(); - return false; - } - string backId = string.Empty; - for (int i = 0; i < pageData.Count; i++) - { - if (pageData[i].BackupName == DirNameResourse.OptionBackupName) - { - //鑾峰彇鍔熻兘澶囦唤鐨処D - backId = pageData[i].Id; - break; - } - } - if (backId == string.Empty) - { - //鍒涘缓鏂扮殑澶囦唤 - backId = HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName); - if (backId == null) - { - ProgressFormBar.Current.Close(); - return false; - } - } - //涓婁紶Log鏂囦欢 - bool result = this.UpLoadBackupFileToDB(backId, 0, upPath, false); - if (result == true) - { - try - { - var listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath); - if (listAllFile.Count > 10) - { - listAllFile.Sort(); - while (listAllFile.Count >= 10) - { - System.IO.File.Delete(listAllFile[0]); - listAllFile.RemoveAt(0); - } - } - } - catch { } - } - ProgressFormBar.Current.Close(); - - HdlThreadLogic.Current.RunMain(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, "Log涓婁紶鎴愬姛"); - contr.Show(); - }); - - return result; - } - - /// <summary> - /// 涓婁紶涓滆タ鍒伴殣鍖垮姛鑳藉浠� - /// </summary> - /// <param name="fileName"></param> - /// <param name="byteData"></param> - /// <returns></returns> - public bool UpLoadByteDataToOptionBackup(string fileName, byte[] byteData) - { - ProgressFormBar.Current.Start(); - ProgressFormBar.Current.SetMsg("姝e湪涓婁紶鏂囦欢"); - - //浠庝簯绔幏鍙栨暟鎹� - var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true); - if (pageData == null) - { - ProgressFormBar.Current.Close(); - HdlThreadLogic.Current.RunMain(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, "鑾峰彇鍔熻兘澶囦唤澶辫触"); - contr.Show(); - }); - return false; - } - string backId = string.Empty; - for (int i = 0; i < pageData.Count; i++) - { - if (pageData[i].BackupName == DirNameResourse.OptionBackupName) - { - //鑾峰彇鍔熻兘澶囦唤鐨処D - backId = pageData[i].Id; - break; - } - } - if (backId == string.Empty) - { - //鍒涘缓鏂扮殑澶囦唤 - backId = this.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName); - if (backId == null) - { - ProgressFormBar.Current.Close(); - HdlThreadLogic.Current.RunMain(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, "鍒涘缓鍔熻兘澶囦唤澶辫触"); - contr.Show(); - }); - return false; - } - } - //涓婁紶Log鏂囦欢 - var datainfo = new FileInfoData(); - datainfo.BackupFileName = fileName; - datainfo.BackupFileContent = byteData; - - var list = new List<FileInfoData>(); - list.Add(datainfo); - - //鎵ц涓婁紶 - bool falge = DoUpLoadInfoToDB(backId, list, 0); - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - - if (falge == false) - { - HdlThreadLogic.Current.RunMain(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛"); - contr.Show(); - }); - return false; - } - HdlThreadLogic.Current.RunMain(() => - { - var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛"); - contr.Show(); - }); - - return true; - } - - #endregion - - #region 鈻� 璇诲彇闅愬尶鍔熻兘閰嶇疆___________________ - - /// <summary> - /// 璇诲彇闅愬尶鍔熻兘閰嶇疆(涓嶈鍦ㄦ剰杩斿洖鍊�) - /// </summary> - /// <returns></returns> - public bool LoadHideOption() - { - //鍏堝垵濮嬪寲 - UserCenterResourse.HideOption = new HideOptionInfo(); - if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2) - { - return true; - } - - //鏃犺閿欒 - IMessageCommon.Current.IgnoreError = true; - //浠庝簯绔幏鍙栨暟鎹� - var pageData = this.GetBackupListNameFromDB(0, null, true); - if (pageData == null) - { - //鎭㈠ - IMessageCommon.Current.IgnoreError = false; - return false; - } - string backId = string.Empty; - for (int i = 0; i < pageData.Count; i++) - { - if (pageData[i].BackupName == DirNameResourse.OptionBackupName) - { - //鑾峰彇鍔熻兘澶囦唤鐨処D - backId = pageData[i].Id; - break; - } - } - if (backId == string.Empty) - { - //娌℃湁鍔熻兘閰嶇疆 - IMessageCommon.Current.IgnoreError = false; - return true; - } - //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢 - List<string> listFile = GetBackFileIDFromDB(backId, false, null); - if (listFile == null) - { - //鎭㈠ - IMessageCommon.Current.IgnoreError = false; - return false; - } - if (listFile.Count == 0) - { - //鎭㈠ - IMessageCommon.Current.IgnoreError = false; - return true; - } - - //妫�娴� - string checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.ShowOptionMenuFile + UserCenterResourse.UserInfo.Account); - if (listFile.Contains(checkKeys) == true) - { - //鏄剧ず涓婚〉闅愯棌鑿滃崟(Debug鐢�) - UserCenterResourse.HideOption.CenterHideMenu = 1; - } - checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.DetailedLogFile + UserCenterResourse.UserInfo.Account); - if (listFile.Contains(checkKeys) == true) - { - //鍑哄姏璇︾粏Log(Debug鐢�) - UserCenterResourse.HideOption.DetailedLog = 1; - } - checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.DeviceHistoryFile + UserCenterResourse.UserInfo.Account); - if (listFile.Contains(checkKeys) == true) - { - //鏄剧ず璁惧鍘嗗彶鐗堟湰(Debug鐢�) - UserCenterResourse.HideOption.DeviceHistory = 1; - } - checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.StartDebugAppFile + UserCenterResourse.UserInfo.Account); - if (listFile.Contains(checkKeys) == true) - { - //寮�鍚悗鍙拌皟璇旳pp鍔熻兘(Debug鐢�) - UserCenterResourse.HideOption.StartDebugApp = 1; - } - checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.CheckDeviceTypeFile + UserCenterResourse.UserInfo.Account); - if (listFile.Contains(checkKeys) == true) - { - //寮�鍚娴嬭澶嘥ype鐨�(Debug鐢�) - UserCenterResourse.HideOption.CheckDeviceType = 1; - } - - //鎭㈠ - IMessageCommon.Current.IgnoreError = false; - return true; - } - - #endregion - - #region 鈻� 璇诲彇澶囦唤___________________________ - - /// <summary> - /// 璇诲彇APP澶囦唤鏂囨。(鍑芥暟鍐呴儴鏈夎繘搴︽潯) - /// </summary> - /// <param name="BackupClassId"></param> - public bool LoadAppBackupInfo(string BackupClassId) - { - //鎵撳紑杩涘害鏉� 姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃 - ProgressFormBar.Current.Start(); - ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); - - //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦扮殑涓存椂鏂囦欢澶� - string tempDirectory = GetBackFileFromDBAndSetToLocation(BackupClassId); - if (tempDirectory == null) - { - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - return false; - } - - //娓呯┖鍏ㄩ儴鎴块棿 - HdlRoomLogic.Current.DeleteAllRoom(); - //娓呯┖鏈湴鍏ㄩ儴鐨勫満鏅暟鎹� - HdlSceneLogic.Current.DeleteAllLocalScene(); - //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠� - HdlFileLogic.Current.DeleteAllLocationFile(false); - - //娓呯悊鏈湴鐨勬ā鏉挎枃浠� - TemplateData.TemplateCommonLogic.Current.DeleteAllLocalFile(); - - //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰 - HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDirectory, true); - - //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�) - HdlAutoBackupLogic.DeleteAllAutoBackupFile(); - - //鍒锋柊鏈湴缂撳瓨 - UserCenterLogic.RefreshAllMemory(); - - //鍏抽棴杩涘害鏉� - ProgressFormBar.Current.Close(); - - return true; - } - - #endregion - - #region 鈻� 鍒犻櫎澶囦唤___________________________ - - /// <summary> - /// 鍒犻櫎浜戠澶囦唤 - /// </summary> - /// <param name="BackupClassId">澶囦唤鐨勪富閿�</param> - /// <returns></returns> - public bool DeleteDbBackupData(string BackupClassId) - { - var Pra = new LoadBackInfoPra(); - Pra.BackupClassId = BackupClassId; - //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken - Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); - - bool success = UserCenterLogic.GetResultStatuByRequestHttps("App/DelHomeAppGatewayName", true, Pra); - - return success; - } - - #endregion - - #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// 鍒ゆ柇鏄惁鏄簲璇ヤ笂浼犵殑鏂囦欢 - /// </summary> - /// <param name="file"></param> - /// <returns></returns> - private bool IsNotUpLoadFile(string file) - { - if (file.StartsWith("Device_") == true - || file.StartsWith("Gateway_") == true - || file.StartsWith("Room_") == true - || file.StartsWith("Scene_") == true) - { - //璁惧,缃戝叧,鎴块棿,鍦烘櫙鏂囦欢涓嶉渶瑕佷笂浼�,瀹冨凡缁忎繚瀛樺湪bin妯℃澘鏂囦欢涓� - return true; - } - return false; - } - - /// <summary> - /// 灏嗘枃浠惰浆涓築ase64瀛楃涓� - /// </summary> - /// <param name="fileName"></param> - /// <returns></returns> - private string GetBase64Text(string fileName) - { - string path = Config.Instance.FullPath; - string fullName = System.IO.Path.Combine(path, fileName); - - FileStream fs = File.OpenRead(fullName); - byte[] buff = new byte[fs.Length]; - fs.Read(buff, 0, buff.Length); - fs.Close(); - - string base64 = Convert.ToBase64String(buff); - return base64; - } - - #endregion - } -} + public static HdlBackupLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlBackupLogic(); + } + return m_Current; + } + } + + #endregion + + #region 鈻� 鑾峰彇澶囦唤鍚嶅瓧鍒楄〃___________________ + + /// <summary> + /// 浠庝簯绔幏鍙栧浠芥暟鎹殑鍚嶅瓧鍒楄〃 + /// </summary> + /// <param name="ZigbeeBackupType">0:App鎵嬪姩澶囦唤 1: App 鑷姩澶囦唤 2锛氱綉鍏虫墜鍔ㄥ浠� 3:缃戝叧鑷姩澶囦唤</param> + /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,鑾峰彇缃戝叧澶囦唤闇�瑕�</param> + /// <param name="getOptionBackup">鏄惁鑾峰彇鍔熻兘澶囦唤</param> + /// <returns></returns> + public List<BackupListNameInfo> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false) + { + //澶囦唤鍚嶅瓧寰堝皯鐨勫唴瀛橈紝鍙互鐩存帴涓�娆℃�у叏閮ㄥ彇瀹� + var pra = new GetBackupListPra(); + pra.BackupType = ZigbeeBackupType; + pra.GatewayUniqueId = ZigbeeUniqueId; + pra.PageSetting.Page = 1; + pra.PageSetting.PageSize = 99999; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + //璁块棶鎺ュ彛 + string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupPagger", true, pra); + if (string.IsNullOrEmpty(result) == true) + { + return null; + } + + var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult>(result); + var list = new List<BackupListNameInfo>(); + foreach (var data2 in data.PageData) + { + if (ZigbeeUniqueId != null && data2.GatewayUniqueId != ZigbeeUniqueId) + { + continue; + } + if (getOptionBackup == false && data2.BackupName == DirNameResourse.OptionBackupName) + { + //涓嶈幏鍙栧姛鑳藉浠� + continue; + } + list.Add(data2); + } + return list; + } + + /// <summary> + /// <para>浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�</para> + /// <para>杩斿洖鏂囦欢澶瑰悕瀛�(閲岄潰瀛樻斁鐫�鍏ㄩ儴鐨勬枃浠�),杩斿洖null鏃讹紝浠h〃澶辫触</para> + /// </summary> + /// <param name="BackupClassId">BackupClassId</param> + /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param> + /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param> + /// <returns></returns> + public string GetBackFileFromDBAndSetToLocation(string BackupClassId, bool IsGatewayAutoBackup = false, string ZigbeeUniqueId = null) + { + //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭 + Shared.Common.CommonPage.BackKeyCanClick = false; + UserCenterResourse.AccountOption.AppCanSignout = false; + + //棣栧厛鍏堝垱寤轰竴涓复鏃舵枃浠跺す,瀛樺湪鏂囦欢鍒欐竻绌� + string newDir = DirNameResourse.DownLoadBackupTempDirectory; + HdlFileLogic.Current.CreateDirectory(newDir, true); + + //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢 + List<string> listFile = GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId); + if (listFile == null) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + return null; + } + + var pra = new LoadBackInfoPra(); + pra.BackupClassId = BackupClassId; + pra.IsGatewayAutoBackup = IsGatewayAutoBackup; + pra.GatewayUniqueId = ZigbeeUniqueId; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + //涓�涓釜鐨勪笅杞芥枃浠� + int listFileCount = listFile.Count; + for (int i = 0; i < listFile.Count; i++) + { + string fileName = listFile[i]; + //璐﹀彿宸茬粡閫�鍑� + if (HdlCheckLogic.Current.IsAccountLoginOut() == true) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + return null; + } + + //鈽呰缃渶瑕佽幏鍙栫殑鏂囦欢鍚嶅瓧鈽� + pra.BackupFileName = fileName; + var result = UserCenterLogic.GetByteResponseDataByRequestHttps("App/DownloadSomeDataBackup", true, pra, null, true); + if (result == null) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + return null; + } + //灏嗚緭鍏ュ啓鍏ユ湰鍦扮殑涓存椂鏂囦欢澶� + HdlFileLogic.Current.SaveByteToFile(System.IO.Path.Combine(newDir, fileName), result); + //璁剧疆杩涘害鍊� + ProgressFormBar.Current.SetValue(i + 1, listFileCount); + } + + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + + return newDir; + } + + /// <summary> + /// 浠庝簯绔幏鍙栧叏閮ㄧ殑澶囦唤鏂囦欢鐨勫悕瀛� + /// </summary> + /// <param name="BackupClassId">BackupClassId</param> + /// <param name="IsGatewayAutoBackup">褰撳墠鑾峰彇鏄惁涓虹綉鍏宠嚜鍔ㄥ浠�</param> + /// <param name="ZigbeeUniqueId">ZigbeeUniqueId 缃戝叧鐨勫敮涓�Id(褰揑sGatewayBackup=true鏃讹紝姝ゅ弬鏁板繀椤绘彁渚�</param> + /// <returns></returns> + private List<string> GetBackFileIDFromDB(string BackupClassId, bool IsGatewayAutoBackup, string ZigbeeUniqueId) + { + var pra = new LoadBackInfoPra(); + pra.BackupClassId = BackupClassId; + pra.PageSetting.PageSize = 999999; + pra.PageSetting.Page = 1; + pra.IsGatewayAutoBackup = IsGatewayAutoBackup; + pra.GatewayUniqueId = ZigbeeUniqueId; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + //棣栧厛鍏堣幏鍙栦簯绔湁浠�涔堟枃浠� + string result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDataBackupUploadListPagger", true, pra); + if (string.IsNullOrEmpty(result) == true) + { + return null; + } + var fileListData = Newtonsoft.Json.JsonConvert.DeserializeObject<LoadBackInfoResult>(result); + + //鑾峰彇鏂囦欢鍚嶅瓧 + List<string> listFileName = new List<string>(); + foreach (LoadBackupFileNameInfo file in fileListData.PageData) + { + listFileName.Add(file.BackupFileName); + } + return listFileName; + } + + #endregion + + #region 鈻� 鍒涘缓澶囦唤___________________________ + + /// <summary> + /// 鍒涘缓涓�涓浠藉悕瀛�(鎴愬姛鏃惰繑鍥炲浠界殑涓婚敭ID锛屽け璐ユ椂杩斿洖null) + /// </summary> + /// <param name="backupName">澶囦唤鍚嶅瓧</param> + /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> + /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,褰揗anualBackupType=2鏃�,姝ゅ�间笉鑳戒负绌�!</param> + /// <returns></returns> + public string CreatNewBackupNameToDB(string backupName, int ManualBackupType = 0, string ZigbeeUniqueId = null) + { + var pra = new AddBackUpNamePra(); + pra.BackupName = backupName; + pra.ManualBackupType = ManualBackupType; + pra.GatewayUniqueId = ZigbeeUniqueId; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + var result = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHomeAppGatewayName", true, pra); + if (string.IsNullOrEmpty(result) == true) + { + return null; + } + var data = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult>(result); + + return data.BackupClassId; + } + + #endregion + + #region 鈻� 涓婁紶澶囦唤___________________________ + + /// <summary> + /// 涓婁紶鏈湴鎵�鏈夋枃浠跺埌浜戠(鍑芥暟鍐呴儴鏈夎繘搴︽潯) + /// </summary> + /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> + /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> + /// <param name="upPath">鎸囧畾涓婁紶鐨勬槸鍝釜鏂囦欢澶圭殑鏂囦欢(鍏ㄨ矾寰�),涓嶆寚瀹氭椂锛屼笂浼犵殑鏄湰鍦拌矾寰勪笅鐨勬枃浠�</param> + /// <param name="showBar">鏄惁璁剧疆鏄剧ず杩涘害鏉�</param> + /// <returns></returns> + public bool UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true) + { + List<string> listAllFile = null; + //鏂囦欢澶圭殑鍏ㄨ矾寰� + string fullDir = string.Empty; + string localTemplateName = string.Empty; + if (upPath == string.Empty) + { + //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑 + var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(); + var templateFile = TemplateData.TemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate"); + + //灏嗘ā鏉縝in鏂囦欢绉诲姩鍒板浠芥枃浠跺す涓� + localTemplateName = System.IO.Path.Combine(Config.Instance.FullPath, templateName); + try { System.IO.File.Move(templateFile, localTemplateName); } + catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "绉诲姩妯℃澘澶辫触"); } + + //鑾峰彇鏈湴鏂囦欢 + listAllFile = HdlFileLogic.Current.GetRootPathListFile(); + fullDir = Common.Config.Instance.FullPath; + } + else + { + listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath); + fullDir = upPath; + } + if (listAllFile.Count == 0) + { + return true; + } + + //鏅�氭枃浠讹紝鍙互涓�娆℃�т笂浼犲涓殑 + List<string> listNormalFile = new List<string>(); + //鍥剧墖鏂囦欢锛岃繖涓笢瑗垮緢澶э紝闇�瑕佺嫭绔嬪嚭鏉� + List<string> listPicFile = new List<string>(); + + foreach (string fileName in listAllFile) + { + //鍒ゆ柇鎸囧畾鏂囦欢鏄惁闇�瑕佷笂浼�(鏍圭洰褰曠殑鎵嶅垽鏂�) + if (upPath == string.Empty && this.IsNotUpLoadFile(fileName) == true) + { + continue; + } + if (fileName.EndsWith(".png") == true + || fileName.EndsWith(".bin") == true) + { + //鍥剧墖鏂囦欢 + listPicFile.Add(fileName); + continue; + } + listNormalFile.Add(fileName); + } + + //寮�鍚繘搴︽潯 + int listFileCount = listPicFile.Count + listNormalFile.Count; + if (showBar == true) + { + //寮�鍚繘搴︽潯 姝e湪涓婁紶澶囦唤鏂囦欢 + ProgressFormBar.Current.Start(); + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading)); + } + + //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭 + Shared.Common.CommonPage.BackKeyCanClick = false; + UserCenterResourse.AccountOption.AppCanSignout = false; + + //浣犺涓轰粈涔堣繖閲屼笉鍒嗕竴涓嚱鏁板嚭鏉ワ紙鐞嗚涓婃槸鍒嗗嚱鏁板嚭鏉ョ殑锛� + //鏄洜涓哄鏋滃垎鍑芥暟鐨勮瘽锛屼細鍑虹幇鍙岄噸寮傛锛屽鑷翠富绾跨▼鐨勮繘搴︽潯鐨勭櫨鍒嗘瘮姘歌繙瀹氭0% + for (int i = 0; i < listNormalFile.Count; i++) + { + string file = listNormalFile[i]; + //璐﹀彿宸茬粡閫�鍑� + if (HdlCheckLogic.Current.IsAccountLoginOut() == true) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + if (localTemplateName != string.Empty) + { + //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� + HdlFileLogic.Current.DeleteFile(localTemplateName); + } + return false; + } + //鏁寸悊鏁版嵁 + var datainfo = new FileInfoData(); + datainfo.BackupFileName = file; + string fullFileName = System.IO.Path.Combine(fullDir, file); + datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(fullFileName); + + var list = new List<FileInfoData>(); + list.Add(datainfo); + + //鎵ц涓婁紶 + bool falge = DoUpLoadInfoToDB(BackupClassId, list, ManualBackupType); + if (falge == false) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + if (localTemplateName != string.Empty) + { + //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� + HdlFileLogic.Current.DeleteFile(localTemplateName); + } + return false; + } + //璁剧疆杩涘害鍊� + ProgressFormBar.Current.SetValue(i + 1, listFileCount); + } + + for (int i = 0; i < listPicFile.Count; i++) + { + string file = listPicFile[i]; + //璐﹀彿宸茬粡閫�鍑� + if (HdlCheckLogic.Current.IsAccountLoginOut() == true) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + if (localTemplateName != string.Empty) + { + //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� + HdlFileLogic.Current.DeleteFile(localTemplateName); + } + return false; + } + + var listPic = new List<string>(); + listPic.Add(file); + + //涓婁紶鏈湴鍥剧墖鏂囦欢鍒颁簯绔� + bool result = UpLoadBigBackupFileToDB(fullDir, listPic, BackupClassId, ManualBackupType); + if (result == false) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + if (localTemplateName != string.Empty) + { + //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� + HdlFileLogic.Current.DeleteFile(localTemplateName); + } + return false; + } + //璁剧疆杩涘害鍊� + ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount); + } + + if (localTemplateName != string.Empty) + { + //鍒犻櫎鎺夎繖涓ā鏉挎枃浠� + HdlFileLogic.Current.DeleteFile(localTemplateName); + } + + //杩涘害鏉″叧闂� + ProgressFormBar.Current.Close(); + //鍏佽鎸夌郴缁熺殑杩斿洖閿� + Shared.Common.CommonPage.BackKeyCanClick = true; + UserCenterResourse.AccountOption.AppCanSignout = true; + + return true; + } + + /// <summary> + /// 鎵ц涓婁紶鍒颁簯绔� + /// </summary> + /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> + /// <param name="listData">涓婁紶鐨勬暟鎹�</param> + /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> + /// <returns></returns> + private bool DoUpLoadInfoToDB(string BackupClassId, List<FileInfoData> listData, int ManualBackupType = 0) + { + var upData = new UpLoadDataPra(); + upData.ManualBackupType = ManualBackupType; + upData.BackupClassId = BackupClassId; + upData.UploadSubFileLists = listData; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/UploadHomeAppGatewaySubFiles", true, upData, null, true); + if (falge == false) + { + return false; + } + return true; + } + + /// <summary> + /// 涓婁紶鏈湴鍥剧墖鏂囦欢鍒颁簯绔� + /// </summary> + /// <param name="fullDir">鏂囦欢澶圭殑鍏ㄨ矾寰�</param> + /// <param name="listPicFile">鍥剧墖鏂囦欢鍒楄〃</param> + /// <param name="BackupClassId">澶囦唤涓婚敭ID</param> + /// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param> + /// <returns></returns> + private bool UpLoadBigBackupFileToDB(string fullDir, List<string> listPicFile, string BackupClassId, int ManualBackupType = 0) + { + foreach (string fileName in listPicFile) + { + string fullName = System.IO.Path.Combine(fullDir, fileName); + + NameValueCollection nvc = new NameValueCollection(); + nvc.Add("RequestVersion", Common.CommonPage.RequestVersion); + nvc.Add("LoginAccessToken", UserCenterLogic.GetConnectMainToken()); + nvc.Add("HomeId", Shared.Common.Config.Instance.Home.Id); + nvc.Add("BackupClassId", BackupClassId); + nvc.Add("ManualBackupType", ManualBackupType.ToString()); + nvc.Add("IsOtherAccountCtrl", Common.Config.Instance.Home.IsOthreShare.ToString()); + + string base64 = GetBase64Text(fullName); + nvc.Add("UploadSubFileLists[0].BackupFileName", fileName); + nvc.Add("UploadSubFileLists[0].BackupFileContent", base64); + + bool result = UpLoadBigBackupFileToDB("App/UploadHomeAppGatewaySubFiles", fullName, nvc); + if (result == false) + { + return false; + } + } + return true; + } + + /// <summary> + /// 涓婁紶澶ф枃浠� + /// </summary> + /// <param name="RequestName">璇锋眰鎺ュ彛</param> + /// <param name="fullFileName">鏂囦欢鍚嶅瓧(鍚矾寰�)</param> + /// <param name="nvc"></param> + /// <returns></returns> + private bool UpLoadBigBackupFileToDB(string RequestName, string fullFileName, NameValueCollection nvc) + { + string paramName = "file"; + string contentType = "application/octet-stream"; + string requestUrl = string.Empty; + //鍚敤绠$悊鍛樻潈闄� + if (Config.Instance.Home.IsOthreShare == 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"); + + HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(requestUrl); + wr.ContentType = "multipart/form-data; boundary=" + boundary; + wr.Method = "POST"; + wr.KeepAlive = true; + wr.Credentials = System.Net.CredentialCache.DefaultCredentials; + + Stream 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); + + FileStream 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); + + return UserCenterLogic.CheckNotEorrorMsg(data, requestUrl); + } + catch + { + return false; + } + finally + { + if (wresp != null) + { + wresp.Close(); + wresp = null; + } + wr = null; + } + } + + #endregion + + #region 鈻� 涓婁紶Log澶囦唤________________________ + + /// <summary> + /// 涓婁紶Log澶囦唤(闅愬尶鍔熻兘) + /// </summary> + /// <returns></returns> + public bool UpLoadLogBackup() + { + string upPath = DirNameResourse.LogDirectory; + if (HdlFileLogic.Current.GetFileFromDirectory(upPath).Count == 0) + { + //娌℃湁Log鏂囦欢 + return true; + } + + ProgressFormBar.Current.Start(); + ProgressFormBar.Current.SetMsg("姝e湪涓婁紶Log鏂囦欢"); + + //浠庝簯绔幏鍙栨暟鎹� + var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true); + if (pageData == null) + { + ProgressFormBar.Current.Close(); + return false; + } + string backId = string.Empty; + for (int i = 0; i < pageData.Count; i++) + { + if (pageData[i].BackupName == DirNameResourse.OptionBackupName) + { + //鑾峰彇鍔熻兘澶囦唤鐨処D + backId = pageData[i].Id; + break; + } + } + if (backId == string.Empty) + { + //鍒涘缓鏂扮殑澶囦唤 + backId = HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName); + if (backId == null) + { + ProgressFormBar.Current.Close(); + return false; + } + } + //涓婁紶Log鏂囦欢 + bool result = this.UpLoadBackupFileToDB(backId, 0, upPath, false); + if (result == true) + { + try + { + var listAllFile = HdlFileLogic.Current.GetFileFromDirectory(upPath); + if (listAllFile.Count > 10) + { + listAllFile.Sort(); + while (listAllFile.Count >= 10) + { + System.IO.File.Delete(listAllFile[0]); + listAllFile.RemoveAt(0); + } + } + } + catch { } + } + ProgressFormBar.Current.Close(); + + HdlThreadLogic.Current.RunMain(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, "Log涓婁紶鎴愬姛"); + contr.Show(); + }); + + return result; + } + + /// <summary> + /// 涓婁紶涓滆タ鍒伴殣鍖垮姛鑳藉浠� + /// </summary> + /// <param name="fileName"></param> + /// <param name="byteData"></param> + /// <returns></returns> + public bool UpLoadByteDataToOptionBackup(string fileName, byte[] byteData) + { + ProgressFormBar.Current.Start(); + ProgressFormBar.Current.SetMsg("姝e湪涓婁紶鏂囦欢"); + + //浠庝簯绔幏鍙栨暟鎹� + var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, true); + if (pageData == null) + { + ProgressFormBar.Current.Close(); + HdlThreadLogic.Current.RunMain(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, "鑾峰彇鍔熻兘澶囦唤澶辫触"); + contr.Show(); + }); + return false; + } + string backId = string.Empty; + for (int i = 0; i < pageData.Count; i++) + { + if (pageData[i].BackupName == DirNameResourse.OptionBackupName) + { + //鑾峰彇鍔熻兘澶囦唤鐨処D + backId = pageData[i].Id; + break; + } + } + if (backId == string.Empty) + { + //鍒涘缓鏂扮殑澶囦唤 + backId = this.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName); + if (backId == null) + { + ProgressFormBar.Current.Close(); + HdlThreadLogic.Current.RunMain(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, "鍒涘缓鍔熻兘澶囦唤澶辫触"); + contr.Show(); + }); + return false; + } + } + //涓婁紶Log鏂囦欢 + var datainfo = new FileInfoData(); + datainfo.BackupFileName = fileName; + datainfo.BackupFileContent = byteData; + + var list = new List<FileInfoData>(); + list.Add(datainfo); + + //鎵ц涓婁紶 + bool falge = DoUpLoadInfoToDB(backId, list, 0); + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + + if (falge == false) + { + HdlThreadLogic.Current.RunMain(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛"); + contr.Show(); + }); + return false; + } + HdlThreadLogic.Current.RunMain(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, "鏂囦欢涓婁紶鎴愬姛"); + contr.Show(); + }); + + return true; + } + + #endregion + + #region 鈻� 璇诲彇闅愬尶鍔熻兘閰嶇疆___________________ + + /// <summary> + /// 璇诲彇闅愬尶鍔熻兘閰嶇疆(涓嶈鍦ㄦ剰杩斿洖鍊�) + /// </summary> + /// <returns></returns> + public bool LoadHideOption() + { + //鍏堝垵濮嬪寲 + UserCenterResourse.HideOption = new HideOptionInfo(); + if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2) + { + return true; + } + + //鏃犺閿欒 + IMessageCommon.Current.IgnoreError = true; + //浠庝簯绔幏鍙栨暟鎹� + var pageData = this.GetBackupListNameFromDB(0, null, true); + if (pageData == null) + { + //鎭㈠ + IMessageCommon.Current.IgnoreError = false; + return false; + } + string backId = string.Empty; + for (int i = 0; i < pageData.Count; i++) + { + if (pageData[i].BackupName == DirNameResourse.OptionBackupName) + { + //鑾峰彇鍔熻兘澶囦唤鐨処D + backId = pageData[i].Id; + break; + } + } + if (backId == string.Empty) + { + //娌℃湁鍔熻兘閰嶇疆 + IMessageCommon.Current.IgnoreError = false; + return true; + } + //鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢 + List<string> listFile = GetBackFileIDFromDB(backId, false, null); + if (listFile == null) + { + //鎭㈠ + IMessageCommon.Current.IgnoreError = false; + return false; + } + if (listFile.Count == 0) + { + //鎭㈠ + IMessageCommon.Current.IgnoreError = false; + return true; + } + + //妫�娴� + string checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.ShowOptionMenuFile + UserCenterResourse.UserInfo.Account); + if (listFile.Contains(checkKeys) == true) + { + //鏄剧ず涓婚〉闅愯棌鑿滃崟(Debug鐢�) + UserCenterResourse.HideOption.CenterHideMenu = 1; + } + checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.DetailedLogFile + UserCenterResourse.UserInfo.Account); + if (listFile.Contains(checkKeys) == true) + { + //鍑哄姏璇︾粏Log(Debug鐢�) + UserCenterResourse.HideOption.DetailedLog = 1; + } + checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.DeviceHistoryFile + UserCenterResourse.UserInfo.Account); + if (listFile.Contains(checkKeys) == true) + { + //鏄剧ず璁惧鍘嗗彶鐗堟湰(Debug鐢�) + UserCenterResourse.HideOption.DeviceHistory = 1; + } + checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.StartDebugAppFile + UserCenterResourse.UserInfo.Account); + if (listFile.Contains(checkKeys) == true) + { + //寮�鍚悗鍙拌皟璇旳pp鍔熻兘(Debug鐢�) + UserCenterResourse.HideOption.StartDebugApp = 1; + } + checkKeys = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, DirNameResourse.CheckDeviceTypeFile + UserCenterResourse.UserInfo.Account); + if (listFile.Contains(checkKeys) == true) + { + //寮�鍚娴嬭澶嘥ype鐨�(Debug鐢�) + UserCenterResourse.HideOption.CheckDeviceType = 1; + } + + //鎭㈠ + IMessageCommon.Current.IgnoreError = false; + return true; + } + + #endregion + + #region 鈻� 璇诲彇澶囦唤___________________________ + + /// <summary> + /// 璇诲彇APP澶囦唤鏂囨。(鍑芥暟鍐呴儴鏈夎繘搴︽潯) + /// </summary> + /// <param name="BackupClassId"></param> + public bool LoadAppBackupInfo(string BackupClassId) + { + //鎵撳紑杩涘害鏉� 姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃 + ProgressFormBar.Current.Start(); + ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting)); + + //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦扮殑涓存椂鏂囦欢澶� + string tempDirectory = GetBackFileFromDBAndSetToLocation(BackupClassId); + if (tempDirectory == null) + { + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + return false; + } + + //鍏堣幏鍙栨湰鍦板叏閮ㄧ綉鍏崇殑鐗堟湰淇℃伅 + var listOldGateway = HdlGatewayLogic.Current.GetAllLocalGateway(); + + //娓呯┖鍏ㄩ儴鎴块棿 + HdlRoomLogic.Current.DeleteAllRoom(); + //娓呯┖鏈湴鍏ㄩ儴鐨勫満鏅暟鎹� + HdlSceneLogic.Current.DeleteAllLocalScene(); + //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠� + HdlFileLogic.Current.DeleteAllLocationFile(false); + + //娓呯悊鏈湴鐨勬ā鏉挎枃浠� + TemplateData.TemplateCommonLogic.Current.DeleteAllLocalFile(); + + //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰 + HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDirectory, true); + + //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�) + HdlAutoBackupLogic.DeleteAllAutoBackupFile(); + + //鍒锋柊鏈湴缂撳瓨 + UserCenterLogic.RefreshAllMemory(); + + //閲嶆柊鍔犺浇缂撳瓨涔嬪悗,鍐嶈繕鍘熺綉鍏崇殑鐗堟湰淇℃伅 + foreach (var gw in listOldGateway) + { + var newGw = HdlGatewayLogic.Current.GetLocalGateway(gw.GwId); + if (newGw != null) + { + //杩樺師鐗堟湰淇℃伅 + newGw.GwName = gw.GwName; + newGw.GwIP = gw.GwIP; + newGw.LinuxHardVersion = gw.LinuxHardVersion; + newGw.LinuxImageType = gw.LinuxImageType; + newGw.LinuxFirmwareVersion = gw.LinuxFirmwareVersion; + newGw.CoordinatorFirmwareVersion = gw.CoordinatorFirmwareVersion; + newGw.CoordinatorHardVersion = gw.CoordinatorHardVersion; + newGw.CoordinatorImageId = gw.CoordinatorImageId; + newGw.DriveCodeList.Clear(); + newGw.DriveCodeList.AddRange(gw.DriveCodeList); + newGw.ReSave(); + } + } + + //鍏抽棴杩涘害鏉� + ProgressFormBar.Current.Close(); + + return true; + } + + #endregion + + #region 鈻� 鍒犻櫎澶囦唤___________________________ + + /// <summary> + /// 鍒犻櫎浜戠澶囦唤 + /// </summary> + /// <param name="BackupClassId">澶囦唤鐨勪富閿�</param> + /// <returns></returns> + public bool DeleteDbBackupData(string BackupClassId) + { + var Pra = new LoadBackInfoPra(); + Pra.BackupClassId = BackupClassId; + //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken + Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); + + bool success = UserCenterLogic.GetResultStatuByRequestHttps("App/DelHomeAppGatewayName", true, Pra); + + return success; + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鍒ゆ柇鏄惁鏄簲璇ヤ笂浼犵殑鏂囦欢 + /// </summary> + /// <param name="file"></param> + /// <returns></returns> + public bool IsNotUpLoadFile(string file) + { + if (file.StartsWith("Device_") == true + || file.StartsWith("Gateway_") == true + || file.StartsWith("Room_") == true + || file.StartsWith("Scene_") == true) + { + //璁惧,缃戝叧,鎴块棿,鍦烘櫙鏂囦欢涓嶉渶瑕佷笂浼�,瀹冨凡缁忎繚瀛樺湪bin妯℃澘鏂囦欢涓� + return true; + } + return false; + } + + /// <summary> + /// 灏嗘枃浠惰浆涓築ase64瀛楃涓� + /// </summary> + /// <param name="fileName"></param> + /// <returns></returns> + private string GetBase64Text(string fileName) + { + string path = Config.Instance.FullPath; + string fullName = System.IO.Path.Combine(path, fileName); + + FileStream fs = File.OpenRead(fullName); + byte[] buff = new byte[fs.Length]; + fs.Read(buff, 0, buff.Length); + fs.Close(); + + string base64 = Convert.ToBase64String(buff); + return base64; + } + + #endregion + } +} -- Gitblit v1.8.0