From da9285368099529de4f6aa92be55297d05dc63dc Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 29 五月 2020 09:45:11 +0800
Subject: [PATCH] 2020-05-29-1
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs | 320 ++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 252 insertions(+), 68 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
index 04d01da..7a1f143 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
@@ -44,8 +44,9 @@
/// </summary>
/// <param name="ZigbeeBackupType">0:App鎵嬪姩澶囦唤 1: App 鑷姩澶囦唤 2锛氱綉鍏虫墜鍔ㄥ浠� 3:缃戝叧鑷姩澶囦唤</param>
/// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,鑾峰彇缃戝叧澶囦唤闇�瑕�</param>
+ /// <param name="getOptionBackup">鏄惁鑾峰彇鍔熻兘澶囦唤</param>
/// <returns></returns>
- public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null)
+ public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false)
{
//澶囦唤鍚嶅瓧寰堝皯鐨勫唴瀛橈紝鍙互鐩存帴涓�娆℃�у叏閮ㄥ彇瀹�
var pra = new GetBackupListPra();
@@ -65,24 +66,25 @@
}
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult>(result);
- if (ZigbeeUniqueId != null)
+ var list = new List<BackupListNameInfo>();
+ foreach (var data2 in data.PageData)
{
- var list = new List<BackupListNameInfo>();
- foreach (var data2 in data.PageData)
+ if (ZigbeeUniqueId != null && data2.GatewayUniqueId != ZigbeeUniqueId)
{
- if (data2.GatewayUniqueId == ZigbeeUniqueId)
- {
- list.Add(data2);
- }
+ continue;
}
- return list;
+ if (getOptionBackup == false && data2.BackupName == DirNameResourse.OptionBackupName)
+ {
+ //涓嶈幏鍙栧姛鑳藉浠�
+ continue;
+ }
+ list.Add(data2);
}
-
- return data.PageData;
+ return list;
}
/// <summary>
- /// <para>浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�(鍑芥暟鍐呴儴鏈夎繘搴︽潯)</para>
+ /// <para>浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�</para>
/// <para>杩斿洖鏂囦欢澶瑰悕瀛�(閲岄潰瀛樻斁鐫�鍏ㄩ儴鐨勬枃浠�),杩斿洖null鏃讹紝浠h〃澶辫触</para>
/// </summary>
/// <param name="BackupClassId">BackupClassId</param>
@@ -91,23 +93,25 @@
/// <returns></returns>
public async Task<string> GetBackFileFromDBAndSetToLocation(string BackupClassId, bool IsGatewayAutoBackup = false, string ZigbeeUniqueId = null)
{
+ //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭
+ Shared.Common.CommonPage.BackKeyCanClick = false;
+ UserCenterResourse.AccountOption.AppCanSignout = false;
+
//棣栧厛鍏堝垱寤轰竴涓复鏃舵枃浠跺す,瀛樺湪鏂囦欢鍒欐竻绌�
string newDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadBackupTempDirectory);
Global.CreateEmptyDirectory(newDir, true);
-
- //寮�鍚繘搴︽潯
- ProgressBar.Show();
//鑾峰彇杩欎釜澶囦唤涓嬮潰鏈夊灏戜釜鏂囦欢
List<string> listFile = await GetBackFileIDFromDB(BackupClassId, IsGatewayAutoBackup, ZigbeeUniqueId);
if (listFile == null)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return null;
}
- //璁剧疆鏈�澶у��
- ProgressBar.SetMaxValue(listFile.Count);
var pra = new LoadBackInfoPra();
pra.BackupClassId = BackupClassId;
@@ -117,13 +121,18 @@
pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
//涓�涓釜鐨勪笅杞芥枃浠�
- foreach (string fileName in listFile)
+ int listFileCount = listFile.Count;
+ for (int i = 0; i < listFile.Count; i++)
{
+ string fileName = listFile[i];
//璐﹀彿宸茬粡閫�鍑�
if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close(true);
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return null;
}
@@ -133,16 +142,22 @@
if (result == null)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return null;
}
//灏嗚緭鍏ュ啓鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
Global.WriteFileToDirectoryByBytes(newDir, fileName, result);
//璁剧疆杩涘害鍊�
- ProgressBar.SetValue(1);
+ ProgressFormBar.Current.SetValue(i + 1, listFileCount);
}
//鍏抽棴杩涘害鏉�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return newDir;
}
@@ -222,8 +237,9 @@
/// <param name="BackupClassId">澶囦唤涓婚敭ID</param>
/// <param name="ManualBackupType">鎵嬪姩澶囦唤绫诲瀷(0:App鎵嬪姩澶囦唤,2锛氱綉鍏虫墜鍔ㄥ浠�)</param>
/// <param name="upPath">鎸囧畾涓婁紶鐨勬槸鍝釜鏂囦欢澶圭殑鏂囦欢(鍏ㄨ矾寰�),涓嶆寚瀹氭椂锛屼笂浼犵殑鏄湰鍦拌矾寰勪笅鐨勬枃浠�</param>
+ /// <param name="showBar">鏄惁璁剧疆鏄剧ず杩涘害鏉�</param>
/// <returns></returns>
- public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "")
+ public async Task<bool> UpLoadBackupFileToDB(string BackupClassId, int ManualBackupType = 0, string upPath = "", bool showBar = true)
{
List<string> listAllFile = null;
//鏂囦欢澶圭殑鍏ㄨ矾寰�
@@ -261,18 +277,31 @@
}
//寮�鍚繘搴︽潯
- ProgressBar.SetMaxValue(listAllFile.Count);
- ProgressBar.Show();
+ int listFileCount = listAllFile.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%
- foreach (string file in listNormalFile)
+ for (int i = 0; i < listNormalFile.Count; i++)
{
+ string file = listNormalFile[i];
//璐﹀彿宸茬粡閫�鍑�
if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close(true);
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return false;
}
//鍒ゆ柇鏄惁鏄簲璇ヤ笂浼犵殑鏂囦欢
@@ -294,20 +323,27 @@
if (falge == false)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return false;
}
//璁剧疆杩涘害鍊�
- ProgressBar.SetValue(list.Count);
+ ProgressFormBar.Current.SetValue(i + 1, listFileCount);
}
- foreach (string file in listPicFile)
+ for (int i = 0; i < listPicFile.Count; i++)
{
+ string file = listPicFile[i];
//璐﹀彿宸茬粡閫�鍑�
if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close(true);
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return false;
}
@@ -319,14 +355,21 @@
if (result == false)
{
//鍏抽棴杩涘害鏉�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return false;
}
//璁剧疆杩涘害鍊�
- ProgressBar.SetValue(listPic.Count);
+ ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount);
}
+
//杩涘害鏉″叧闂�
- ProgressBar.Close();
+ ProgressFormBar.Current.Close();
+ //鍏佽鎸夌郴缁熺殑杩斿洖閿�
+ Shared.Common.CommonPage.BackKeyCanClick = true;
+ UserCenterResourse.AccountOption.AppCanSignout = true;
return true;
}
@@ -375,14 +418,11 @@
nvc.Add("HomeId", Shared.Common.Config.Instance.Home.Id);
nvc.Add("BackupClassId", BackupClassId);
nvc.Add("ManualBackupType", ManualBackupType.ToString());
- nvc.Add("IsOtherAccountCtrl", Common.Config.Instance.isAdministrator.ToString());
+ nvc.Add("IsOtherAccountCtrl", Common.Config.Instance.Home.IsOthreShare.ToString());
- for (int i = 0; i < listPicFile.Count; i++)
- {
- string base64 = GetBase64Text(fullName);
- nvc.Add("UploadSubFileLists[" + i + "].BackupFileName", fileName);
- nvc.Add("UploadSubFileLists[" + i + "].BackupFileContent", base64);
- }
+ 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)
@@ -406,7 +446,7 @@
string contentType = "application/octet-stream";
string requestUrl = string.Empty;
//鍚敤绠$悊鍛樻潈闄�
- if (Config.Instance.isAdministrator == true)
+ if (Config.Instance.Home.IsOthreShare == true)
{
requestUrl = $"{Config.Instance.AdminRequestBaseUrl}/{RequestName}";
}
@@ -483,6 +523,166 @@
#endregion
+ #region 鈻� 涓婁紶Log澶囦唤________________________
+
+ /// <summary>
+ /// 涓婁紶Log澶囦唤(闅愬尶鍔熻兘)
+ /// </summary>
+ /// <returns></returns>
+ public async Task<bool> UpLoadLogBackup()
+ {
+ string upPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory);
+ if (HdlAutoBackupLogic.GetFileFromDirectory(upPath).Count == 0)
+ {
+ //娌℃湁Log鏂囦欢
+ return true;
+ }
+
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg("姝e湪涓婁紶Log鏂囦欢");
+
+ //浠庝簯绔幏鍙栨暟鎹�
+ var pageData = await 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 = await HdlBackupLogic.Current.CreatNewBackupNameToDB(DirNameResourse.OptionBackupName);
+ if (backId == null)
+ {
+ ProgressFormBar.Current.Close();
+ return false;
+ }
+ }
+ //涓婁紶Log鏂囦欢
+ bool result = await this.UpLoadBackupFileToDB(backId, 0, upPath, false);
+ if (result == true)
+ {
+ try
+ {
+ var listAllFile = HdlAutoBackupLogic.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;
+ }
+
+ #endregion
+
+ #region 鈻� 璇诲彇闅愬尶鍔熻兘閰嶇疆___________________
+
+ /// <summary>
+ /// 璇诲彇闅愬尶鍔熻兘閰嶇疆(涓嶈鍦ㄦ剰杩斿洖鍊�)
+ /// </summary>
+ /// <returns></returns>
+ public async Task<bool> LoadHideOption()
+ {
+ //鍏堝垵濮嬪寲
+ UserCenterResourse.HideOption = new HideOptionInfo();
+ if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2)
+ {
+ return true;
+ }
+
+ //鏃犺閿欒
+ IMessageCommon.Current.IgnoreError = true;
+ //浠庝簯绔幏鍙栨暟鎹�
+ var pageData = await 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 = await 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;
+ }
+
+ //鎭㈠
+ IMessageCommon.Current.IgnoreError = false;
+ return true;
+ }
+
+ #endregion
+
#region 鈻� 璇诲彇澶囦唤___________________________
/// <summary>
@@ -491,12 +691,20 @@
/// <param name="BackupClassId"></param>
public async Task<bool> LoadAppBackupInfo(string BackupClassId)
{
+ //鎵撳紑杩涘害鏉� 姝e湪鑾峰彇澶囦唤鏂囦欢鍒楄〃
+ ProgressFormBar.Current.Start();
+ ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileListGetting));
+
//浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
string tempDirectory = await GetBackFileFromDBAndSetToLocation(BackupClassId);
if (tempDirectory == null)
{
+ //鍏抽棴杩涘害鏉�
+ ProgressFormBar.Current.Close();
return false;
}
+ //鍏抽棴杩涘害鏉�
+ ProgressFormBar.Current.Close();
//濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠�
UserCenterLogic.DeleteAllLocationFile(false);
@@ -511,30 +719,6 @@
UserCenterLogic.RefreshAllMemory();
return true;
- }
-
- /// <summary>
- /// 璇诲彇缃戝叧澶囦唤鏂囨。(鍑芥暟鍐呴儴鏈夎繘搴︽潯)
- /// </summary>
- /// <param name="BackupClassId"></param>
- /// <param name="zbGateway">缃戝叧瀵硅薄(璇蜂紶鍏ョ湡瀹炵墿鐞嗙綉鍏冲璞�)</param>
- /// <param name="listGatewayFile">缃戝叧鐜版湁鐨勬枃浠跺悕</param>
- public async Task<bool> LoadGatewayBackupInfo(string BackupClassId, ZigBee.Device.ZbGateway zbGateway, List<string> listGatewayFile)
- {
- //娣诲姞闄勫姞鎯呮姤:鑾峰彇澶囦唤鏁版嵁
- ProgressBar.SetAppendText(Language.StringByID(R.MyInternationalizationString.uGetBackupData));
- //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
- string tempDirectory = await GetBackFileFromDBAndSetToLocation(BackupClassId, false, HdlGatewayLogic.Current.GetGatewayId(zbGateway));
- //娓呯┖闄勫姞鎯呮姤
- ProgressBar.SetAppendText(string.Empty);
-
- if (tempDirectory == null)
- {
- return false;
- }
-
- //鎭㈠缃戝叧閰嶇疆
- return await HdlGatewayLogic.Current.RecoverGatewaySettion(zbGateway, listGatewayFile, tempDirectory);
}
#endregion
@@ -584,7 +768,7 @@
/// <returns></returns>
private string GetBase64Text(string fileName)
{
- string path = UserCenterResourse.LocalRootPath;
+ string path = Config.Instance.FullPath;
string fullName = System.IO.Path.Combine(path, fileName);
FileStream fs = File.OpenRead(fullName);
--
Gitblit v1.8.0