From 48ba446936b51fffafa7c3600c0dadc6ac0e8c20 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 七月 2020 10:52:13 +0800
Subject: [PATCH] 2020-07-10-01

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs |  200 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 139 insertions(+), 61 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
index cb7d026..7a1f143 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlBackupLogic.cs
@@ -35,11 +35,6 @@
             }
         }
 
-        /// <summary>
-        /// Log澶囦唤鐨勫悕瀛�
-        /// </summary>
-        private string LogBackupName = "##Log##";
-
         #endregion
 
         #region 鈻� 鑾峰彇澶囦唤鍚嶅瓧鍒楄〃___________________
@@ -49,9 +44,9 @@
         /// </summary>
         /// <param name="ZigbeeBackupType">0:App鎵嬪姩澶囦唤 1: App 鑷姩澶囦唤 2锛氱綉鍏虫墜鍔ㄥ浠� 3:缃戝叧鑷姩澶囦唤</param>
         /// <param name="ZigbeeUniqueId">缃戝叧鐨勫敮涓�Id,鑾峰彇缃戝叧澶囦唤闇�瑕�</param>
-        /// <param name="getLogBackup">鏄惁鑾峰彇Log澶囦唤</param>
+        /// <param name="getOptionBackup">鏄惁鑾峰彇鍔熻兘澶囦唤</param>
         /// <returns></returns>
-        public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getLogBackup = false)
+        public async Task<List<BackupListNameInfo>> GetBackupListNameFromDB(int ZigbeeBackupType = 0, string ZigbeeUniqueId = null, bool getOptionBackup = false)
         {
             //澶囦唤鍚嶅瓧寰堝皯鐨勫唴瀛橈紝鍙互鐩存帴涓�娆℃�у叏閮ㄥ彇瀹�
             var pra = new GetBackupListPra();
@@ -78,9 +73,9 @@
                 {
                     continue;
                 }
-                if (getLogBackup == false && data2.BackupName == LogBackupName)
+                if (getOptionBackup == false && data2.BackupName == DirNameResourse.OptionBackupName)
                 {
-                    //涓嶈幏鍙朙og澶囦唤
+                    //涓嶈幏鍙栧姛鑳藉浠�
                     continue;
                 }
                 list.Add(data2);
@@ -100,7 +95,7 @@
         {
             //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭
             Shared.Common.CommonPage.BackKeyCanClick = false;
-            UserCenterResourse.Option.AppCanSignout = false;
+            UserCenterResourse.AccountOption.AppCanSignout = false;
 
             //棣栧厛鍏堝垱寤轰竴涓复鏃舵枃浠跺す,瀛樺湪鏂囦欢鍒欐竻绌�
             string newDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadBackupTempDirectory);
@@ -114,7 +109,7 @@
                 ProgressFormBar.Current.Close();
                 //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                 Shared.Common.CommonPage.BackKeyCanClick = true;
-                UserCenterResourse.Option.AppCanSignout = true;
+                UserCenterResourse.AccountOption.AppCanSignout = true;
                 return null;
             }
 
@@ -137,7 +132,7 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return null;
                 }
 
@@ -150,7 +145,7 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return null;
                 }
                 //灏嗚緭鍏ュ啓鍏ユ湰鍦扮殑涓存椂鏂囦欢澶�
@@ -162,7 +157,7 @@
             ProgressFormBar.Current.Close();
             //鍏佽鎸夌郴缁熺殑杩斿洖閿�
             Shared.Common.CommonPage.BackKeyCanClick = true;
-            UserCenterResourse.Option.AppCanSignout = true;
+            UserCenterResourse.AccountOption.AppCanSignout = true;
 
             return newDir;
         }
@@ -292,7 +287,7 @@
 
             //涓嶅厑璁告寜绯荤粺鐨勮繑鍥為敭
             Shared.Common.CommonPage.BackKeyCanClick = false;
-            UserCenterResourse.Option.AppCanSignout = false;
+            UserCenterResourse.AccountOption.AppCanSignout = false;
 
             //浣犺涓轰粈涔堣繖閲屼笉鍒嗕竴涓嚱鏁板嚭鏉ワ紙鐞嗚涓婃槸鍒嗗嚱鏁板嚭鏉ョ殑锛�
             //鏄洜涓哄鏋滃垎鍑芥暟鐨勮瘽锛屼細鍑虹幇鍙岄噸寮傛锛屽鑷翠富绾跨▼鐨勮繘搴︽潯鐨勭櫨鍒嗘瘮姘歌繙瀹氭0%
@@ -306,7 +301,7 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return false;
                 }
                 //鍒ゆ柇鏄惁鏄簲璇ヤ笂浼犵殑鏂囦欢
@@ -331,7 +326,7 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return false;
                 }
                 //璁剧疆杩涘害鍊�
@@ -348,7 +343,7 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return false;
                 }
 
@@ -363,25 +358,18 @@
                     ProgressFormBar.Current.Close();
                     //鍏佽鎸夌郴缁熺殑杩斿洖閿�
                     Shared.Common.CommonPage.BackKeyCanClick = true;
-                    UserCenterResourse.Option.AppCanSignout = true;
+                    UserCenterResourse.AccountOption.AppCanSignout = true;
                     return false;
                 }
                 //璁剧疆杩涘害鍊�
                 ProgressFormBar.Current.SetValue(i + 1 + listNormalFile.Count, listFileCount);
             }
 
-            //涓婁紶Log澶囦唤
-            if (upPath != UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory))
-            {
-                //閲岄潰鏈変釜鍥炶皟鑷韩鐨勬柟娉�,鎵�浠ヨ繖閲屽姞涓垽鏂�,涓嶇劧浼氭寰幆
-                await this.UpLoadLogBackup();
-            }
-
             //杩涘害鏉″叧闂�
             ProgressFormBar.Current.Close();
             //鍏佽鎸夌郴缁熺殑杩斿洖閿�
             Shared.Common.CommonPage.BackKeyCanClick = true;
-            UserCenterResourse.Option.AppCanSignout = true;
+            UserCenterResourse.AccountOption.AppCanSignout = true;
 
             return true;
         }
@@ -430,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)
@@ -461,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}";
             }
@@ -541,10 +526,10 @@
         #region 鈻� 涓婁紶Log澶囦唤________________________
 
         /// <summary>
-        /// 涓婁紶Log澶囦唤
+        /// 涓婁紶Log澶囦唤(闅愬尶鍔熻兘)
         /// </summary>
         /// <returns></returns>
-        private async Task<bool> UpLoadLogBackup()
+        public async Task<bool> UpLoadLogBackup()
         {
             string upPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory);
             if (HdlAutoBackupLogic.GetFileFromDirectory(upPath).Count == 0)
@@ -553,54 +538,147 @@
                 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 HdlBackupLogic.Current.GetBackupListNameFromDB(0, null, 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 == LogBackupName)
+                if (pageData[i].BackupName == DirNameResourse.OptionBackupName)
                 {
-                    //鍒犻櫎鎺夎繖涓浠�
-                    bool flage = await this.DeleteDbBackupData(pageData[i].Id);
-                    if (flage == false)
-                    {
-                        //鎭㈠
-                        IMessageCommon.Current.IgnoreError = false;
-                        return false;
-                    }
+                    //鑾峰彇鍔熻兘澶囦唤鐨処D
+                    backId = pageData[i].Id;
                     break;
                 }
             }
-            //鍒涘缓鏂扮殑澶囦唤
-            string backupClassId = await HdlBackupLogic.Current.CreatNewBackupNameToDB(LogBackupName);
-            if (backupClassId == null)
+            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;
             }
-            //涓婁紶Log鏂囦欢
-            bool result = await this.UpLoadBackupFileToDB(backupClassId, 0, upPath, false);
-            if (result == true)
+            if (listFile.Count == 0)
             {
-                try
-                {
-                    //鍒犻櫎鏈湴鍏ㄩ儴Log
-                    Global.CreateEmptyDirectory(Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory), true);
-                }
-                catch { }
+                //鎭㈠
+                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 result;
+            return true;
         }
 
         #endregion

--
Gitblit v1.8.0