From dc6493db59dcb0893eac50b72122f94c24056b3f Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 12 十月 2020 14:35:39 +0800
Subject: [PATCH] 新版本

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs |  231 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 119 insertions(+), 112 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
index 99c3486..f7c6441 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
@@ -19,35 +19,11 @@
         #region 鈻� 涓婁紶澶囦唤___________________________
 
         /// <summary>
-        /// 鎵ц涓婁紶鑷姩澶囦唤鏁版嵁(0:娌℃湁鍙笂浼犵殑鑷姩澶囦唤鏁版嵁 1:鎴愬姛 -1锛氬け璐�)
+        /// 鎵嬪姩鎵ц涓婁紶鑷姩澶囦唤鏁版嵁(0:娌℃湁鍙笂浼犵殑鑷姩澶囦唤鏁版嵁 1:鎴愬姛 -1锛氬け璐�)
         /// </summary>
         /// <returns></returns>
-        public static int DoUpLoadAutoBackupData()
+        public static int DoUpLoadAutoBackupDataByHand()
         {
-            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
-            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
-            if (data == null)
-            {
-                return -1;
-            }
-
-            if (data.Count == 0)
-            {
-                //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢
-                DeleteAllAutoBackupFile();
-                //濡傛灉娌℃湁鑷姩澶囦唤鏁版嵁,鍒欐妸鏈湴鍏ㄩ儴涓滆タ涓婁紶
-                var pathTemp = DirNameResourse.AutoBackupDirectory;
-                //澶嶅埗鏈湴鎵�鏈夋枃浠惰繃鍘�
-                List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
-                foreach (string fileName in listAllFile)
-                {
-                    string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
-                    string newFile = System.IO.Path.Combine(pathTemp, fileName);
-                    //澶嶅埗鏂囦欢
-                    HdlFileLogic.Current.CopyFile(oldFile, newFile);
-                }
-            }
-
             //缂栬緫鏂囦欢
             List<string> listEditor = GetAutoBackupEditorFile();
             //鍒犻櫎鏂囦欢
@@ -86,27 +62,59 @@
         /// <summary>
         /// 涓婁紶鏂囦欢鍒颁簯绔�
         /// </summary>
-        /// <param name="listFile"></param>
+        /// <param name="listFile">缂栬緫鎴栬�呮坊鍔犵殑鏂囦欢(鐩墠宸茬粡涓嶆槸涓婁紶瀹冧簡)</param>
         /// <returns></returns>
         private static bool UpLoadBackupFileToDB(List<string> listFile)
         {
-            int listFileCount = listFile.Count;
-            string backUpDir = DirNameResourse.AutoBackupDirectory;
-            for (int i = 0; i < listFile.Count; i++)
+            string localPath = Config.Instance.FullPath;
+
+            //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑
+            var templateName = TemplateData.TemplateCommonLogic.Current.GetNewTemplateFileName(new DateTime(2000, 12, 31, 12, 59, 57));
+            var templateFile = TemplateData.TemplateCommonLogic.Current.SaveTemplateDataToFile(templateName, "HomeTemplate");
+
+            //灏嗘ā鏉縝in鏂囦欢绉诲姩鍒板浠芥枃浠跺す涓�
+            var localTemplateName = System.IO.Path.Combine(localPath, templateName);
+            try { System.IO.File.Move(templateFile, localTemplateName); }
+            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex, "绉诲姩妯℃澘澶辫触"); }
+
+            //鑾峰彇鏈湴鏂囦欢
+            var listAllFile = HdlFileLogic.Current.GetRootPathListFile();
+            var listUpFile = new List<string>();
+            foreach (string fileName in listAllFile)
             {
-                string file = listFile[i];
+                //鍒ゆ柇鎸囧畾鏂囦欢鏄惁闇�瑕佷笂浼�(鏍圭洰褰曠殑鎵嶅垽鏂�)
+                if (HdlBackupLogic.Current.IsNotUpLoadFile(fileName) == true)
+                {
+                    continue;
+                }
+                //鍏朵粬鍥剧墖鐨勮祫婧愭枃浠�,鍙湁鍦ㄥ彉鏇翠簡鐨勬椂鍊�,鎵嶄笂浼�
+                if (fileName.EndsWith(".png") == true && listFile.Contains(fileName) == false)
+                {
+                    continue;
+                }
+                listUpFile.Add(fileName);
+            }
+
+            int listFileCount = listUpFile.Count;
+            for (int i = 0; i < listUpFile.Count; i++)
+            {
+                string file = listUpFile[i];
                 var datainfo = new FileInfoData();
                 datainfo.BackupFileName = file;
-                datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(backUpDir, file));
+                datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(localPath, file));
                 if (datainfo.BackupFileContent == null)
                 {
                     continue;
                 }
-                var list = new List<FileInfoData>();
-                list.Add(datainfo);
+
+                var upData = new UpLoadDataPra();
+                upData.HomeId = Config.Instance.Home.Id;
+                upData.UploadSubFileLists = new List<FileInfoData> { datainfo };
+                //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+                upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
 
                 //鎵ц鏄笂浼�
-                bool falge = DoUpLoadInfoToDB(list);
+                bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
                 if (falge == false)
                 {
                     return false;
@@ -114,6 +122,18 @@
                 //璁剧疆杩涘害鍊�
                 ProgressFormBar.Current.SetValue(i + 1, listFileCount);
             }
+
+            //鍒犻櫎鎺夎繖涓ā鏉挎枃浠�
+            HdlFileLogic.Current.DeleteFile(localTemplateName);
+
+            //鍒犻櫎鏂囦欢
+            var backPath = DirNameResourse.AutoBackupDirectory;
+            foreach (var file in listFile)
+            {
+                string fullName = System.IO.Path.Combine(backPath, file);
+                HdlFileLogic.Current.DeleteFile(fullName);
+            }
+
             return true;
         }
 
@@ -137,11 +157,10 @@
             }
             //鑷姩澶囦唤鍙湁涓�涓�
             var autoBackupId = data[0].Id;
-            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
 
             var upData = new DeleteFilePra();
             upData.BackupClassId = autoBackupId;
-            upData.HomeId = nowZigbeeNumHomeId;
+            upData.HomeId = Config.Instance.Home.Id;
             upData.DeleteFileNameLists = listData;
             //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
             upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
@@ -159,38 +178,6 @@
                 string fullName = System.IO.Path.Combine(backPath, file);
                 HdlFileLogic.Current.DeleteFile(fullName);
             }
-            return true;
-        }
-
-        /// <summary>
-        /// 鎵ц涓婁紶鏂囦欢鍒颁簯绔�
-        /// </summary>
-        /// <param name="listData">涓婁紶鐨勬暟鎹�</param>
-        /// <returns></returns>
-        private static bool DoUpLoadInfoToDB(List<FileInfoData> listData)
-        {
-            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
-
-            var upData = new UpLoadDataPra();
-            upData.HomeId = nowZigbeeNumHomeId;
-            upData.UploadSubFileLists = listData;
-            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
-            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
-
-            bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
-            if (falge == false)
-            {
-                return false;
-            }
-
-            //鍒犻櫎鏂囦欢
-            var backPath = DirNameResourse.AutoBackupDirectory;
-            foreach (var file in listData)
-            {
-                string fullName = System.IO.Path.Combine(backPath, file.BackupFileName);
-                HdlFileLogic.Current.DeleteFile(fullName);
-            }
-
             return true;
         }
 
@@ -281,25 +268,19 @@
         /// <returns></returns>
         public static int SynchronizeDbAutoBackupData()
         {
-            //鍒ゆ柇鏄惁鑳藉鍚屾鏁版嵁
-            string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
-            //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
-            if (System.IO.File.Exists(checkFile) == true)
-            {
-                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
-                HdlShardLogic.Current.SynchronizeDbSharedContent();
-                return 0;
-            }
-
             //鏆傛椂涓嶆敮鎸佹垚鍛�
             if (UserCenterResourse.UserInfo.AuthorityNo == 3)
             {
                 //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
                 HdlShardLogic.Current.SynchronizeDbSharedContent();
-                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
-                var file = System.IO.File.Create(checkFile);
-                file.Close();
                 return 1;
+            }
+            //鍒ゆ柇鏄惁鑳藉鍚屾鏁版嵁
+            string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
+            //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
+            if (System.IO.File.Exists(checkFile) == true)
+            {
+                return 0;
             }
 
             //鑾峰彇app鐨勮嚜鍔ㄥ浠�
@@ -310,8 +291,6 @@
             }
             if (data.Count == 0)
             {
-                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
-                HdlShardLogic.Current.SynchronizeDbSharedContent();
                 //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
                 var file = System.IO.File.Create(checkFile);
                 file.Close();
@@ -419,29 +398,66 @@
                 return;
             }
 
-            List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
-            List<string> listFile2 = GetAutoBackupDeleteFile();
-
-            if (listFile1.Count == 0 && listFile2.Count == 0)
+            //鍒ゆ柇鏄惁鏈夋枃浠跺彉鏇翠簡
+            if (CheckAutoBackupFileIsChanged() == false)
             {
                 return;
             }
-            if (listFile1.Count == 1 && listFile1[0] == "Room_Favorite.json")
-            {
-                //杩欎釜涓滆タ濂藉儚APP鍚姩鐨勬椂鍊欓兘浼氬垱寤虹殑鏍峰瓙
-                return;
-            }
-
-            //鏂囦欢鍏ㄨ矾寰�
-            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
-            if (System.IO.File.Exists(fullName) == false)
+            //鍒ゆ柇鑳藉惁鏄剧ず鑷姩澶囦唤鐨勭晫闈�
+            if (CheckCanShowAutoBackupForm() == true)
             {
                 HdlThreadLogic.Current.RunMain(() =>
                 {
                     var form = new HdlBackup.HdlAutoBackupForm();
                     form.AddForm();
                 });
-                return;
+            }
+        }
+
+        /// <summary>
+        /// 妫�娴嬭嚜鍔ㄥ浠芥枃浠舵槸鍚﹀彉鏇磋繃
+        /// </summary>
+        /// <returns></returns>
+        private static bool CheckAutoBackupFileIsChanged()
+        {
+            List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
+            List<string> listFile2 = GetAutoBackupDeleteFile();
+
+            if (listFile1.Count == 0 && listFile2.Count == 0)
+            {
+                //娌℃湁鏂囦欢鍙樻洿
+                return false;
+            }
+            if (listFile2.Count > 0)
+            {
+                //鏈夋枃浠惰鍒犻櫎
+                return true;
+            }
+            foreach (var fileName in listFile1)
+            {
+                //浣忓畢鍜屾敹钘忔枃浠�,涓嶄綔涓哄垽鏂爣鍑�
+                if (fileName.StartsWith("House_") == true
+                  || fileName == "Room_Favorite.json")
+                {
+                    continue;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 妫�娴嬭兘鍚︽樉绀鸿嚜鍔ㄥ浠界殑鐣岄潰
+        /// </summary>
+        /// <returns></returns>
+        private static bool CheckCanShowAutoBackupForm()
+        {
+            //鏂囦欢鍏ㄨ矾寰�
+            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
+            if (System.IO.File.Exists(fullName) == false)
+            {
+                //鏈湴娌℃湁瀛樺湪杩欎釜鏂囦欢
+                return true;
             }
             BackupNotPrompted info = null;
             var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
@@ -449,30 +465,21 @@
             if (info.NotPrompted == true)
             {
                 //涓嶅啀鎻愮ず
-                return;
+                return false;
             }
             if (info.Day == 0)
             {
-                HdlThreadLogic.Current.RunMain(() =>
-                {
-                    var form = new HdlBackup.HdlAutoBackupForm();
-                    form.AddForm();
-                });
-                return;
+                return true;
             }
 
             DateTime oldTime = Convert.ToDateTime(info.OldDay);
             int intDay = (DateTime.Now - oldTime).Days;
             //鏃堕棿宸茬粡瓒呰繃
-            if (intDay > info.Day)
+            if (intDay >= info.Day)
             {
-                HdlThreadLogic.Current.RunMain(() =>
-                {
-                    var form = new HdlBackup.HdlAutoBackupForm();
-                    form.AddForm();
-                });
-                return;
+                return true;
             }
+            return false;
         }
 
         #endregion

--
Gitblit v1.8.0