Forráskód Böngészése

기능 : .pdf 파일이 아닌 파일들에 대해서는 [di_policy_history] 테이블에 test_no, work_emp 를 수집하지 않는다.
기능
1. 실패시 재시도 삭제 : 실패이유가 경로에 없는 문제라면 재시도 중지 / 다른 문제라면 재시도 시도 변경필요
2. HASH 값 비교 변경 : HASH 값 과 파일이름으로 비교를 해야하지만 다른 것으로 비교하다보니 동일파일이 업로드 되는 현상

cms 4 hónapja
szülő
commit
a63166ba44
1 módosított fájl, 92 hozzáadás és 60 törlés
  1. 92 60
      DI/Agent/Services/PolicyService.cs

+ 92 - 60
DI/Agent/Services/PolicyService.cs

@@ -524,7 +524,6 @@ namespace Agent.Services
                 if (!File.Exists(policy.Path))
                 {
                     log.Error($"[FILE]백업 대상이 경로에 없음 (PolicyTid={policy.Tid})");
-
                     return -1;
                 }
 
@@ -532,7 +531,6 @@ namespace Agent.Services
                 if (null == policyDirectoryPathId)
                 {
                     log.Error($"[FILE]정책 디렉터리 생성 실패 (PolicyTid={policy.Tid})");
-
                     return -1;
                 }                
 
@@ -545,19 +543,21 @@ namespace Agent.Services
                         var policyIndex = GetPolicyIndex(con, transaction, policy.Tid, policy.Path);
                         if (null == policyIndex)
                         {
+                            transaction.Rollback();
                             log.Error($"[FILE]인덱스 생성 실패 (PolicyTid={policy.Tid})");
-
                             return -1;
                         }
 
-                        if (isHashCheck && FileUploadHashChk(con, transaction, policy.Tid, policyIndex.Tid, policyIndex.Path))
+                        if (isHashCheck && FileUploadHashChk(con, transaction, policy.Tid, policyIndex.Tid, policyIndex.Path, policyIndex.Name))
                         {
+                            transaction.Rollback();
                             log.Info($"[FILE]중복 업로드 제한 (PolicyTid={policy.Tid})");
                             return 2;
                         }
 
                         if (isLimit && FileUploadLimitChk(con, transaction, policyIndex.Path, policy.Tid, policyIndex.Tid))
                         {
+                            transaction.Rollback();
                             log.Info($"[FILE]대용량 업로드 일일 제한 (PolicyTid={policy.Tid})");
                             return 3;
                         }
@@ -565,18 +565,19 @@ namespace Agent.Services
                         var policyHistoryDirectoryPathId = _fileTableService.CreateDirectory(con, transaction, policyDirectoryPathId);
                         if (null == policyHistoryDirectoryPathId)
                         {
+                            transaction.Rollback();
                             log.Error($"[FILE]정책 히스토리 디렉터리 생성 실패 (PolicyTid={policy.Tid}");
-
                             return -1;
                         }
 
                         var fileStreamId = _fileTableService.UploadFile(con, transaction, policyIndex.Path, policyHistoryDirectoryPathId);
                         if (Guid.Empty == fileStreamId)
                         {
+                            transaction.Rollback();
                             log.Error($"[FILE]백업 대상 업로드에 실패 (PolicyTid={policy.Tid})");
-
                             return -1;
                         }
+
                         //var info = new FileInfo(policy.Path);
                         //policy.Create_Date = info.LastWriteTime;
  
@@ -594,7 +595,6 @@ namespace Agent.Services
                         }
 
                         transaction.Commit();
-
                         return 1;
                     }
                 }
@@ -707,16 +707,31 @@ namespace Agent.Services
                     var info = new FileInfo(file);
                     
                     policyCreate_Date = info.LastWriteTime;
-                    String[] strfileName = fileName.Split('_');
-                    if (strfileName.Length > 2)
+
+                    // 데이터베이스에 넣기전 파싱하는 부분 (시험번호, 사용자) 명명규칙
+
+                    string sFiletype = fileName.Substring(fileName.LastIndexOf('.') + 1);
+
+                    if (sFiletype == "pdf")
                     {
-                        policyWork_Emp = strfileName[0].ToString();
-                        policyTest_No = strfileName[1].ToString();
-                    }else
+                        String[] strfileName = fileName.Split('_');
+                        if (strfileName.Length > 2)
+                        {
+                            policyWork_Emp = strfileName[0].ToString();
+                            policyTest_No = strfileName[1].ToString();
+                        }
+                        else
+                        {
+                            policyWork_Emp = null;
+                            policyTest_No = null;
+                        }
+                    }
+                    else
                     {
                         policyWork_Emp = null;
                         policyTest_No = null;
                     }
+
                     //성공
                     int result = BackupDirectoryPolicyChild(file, directoryPath, policyTid, policyEquip_Cd, policyTest_No, policyCreate_Date, policyWork_Emp, isHashCheck, isLimit);
                     if (0 < result)
@@ -727,10 +742,10 @@ namespace Agent.Services
                             _reportService.AddBackupReport(policyTid, fileName, file, true);
                         }
 
-                        if (2 == result || 3 == result)
-                        {
-                            results.Duplicate++;
-                        }
+                        //if (2 == result || 3 == result)
+                        //{
+                        //    results.Duplicate++;
+                        //}
 
                         continue;
                     }
@@ -738,28 +753,28 @@ namespace Agent.Services
                     //실패
                     _reportService.AddBackupReport(policyTid, fileName, file, false);
 
-                    //재시도 (재시도 옵션 활성화)
-                    result = BackupDirectoryPolicyChild(file, directoryPath, policyTid, policyEquip_Cd, policyTest_No, policyCreate_Date, policyWork_Emp, isHashCheck, isLimit);
-                    if (isRetry && 0 < result)
-                    {
-                        results.Success++;
-                        _reportService.AddRetryReport(policyTid, fileName, file, true);
+                    ////재시도 (재시도 옵션 활성화)
+                    //result = BackupDirectoryPolicyChild(file, directoryPath, policyTid, policyEquip_Cd, policyTest_No, policyCreate_Date, policyWork_Emp, isHashCheck, isLimit);
+                    //if (isRetry && 0 < result)
+                    //{
+                    //    results.Success++;
+                    //    _reportService.AddRetryReport(policyTid, fileName, file, true);
 
-                        if (2 == result || 3 == result)
-                        {
-                            results.Duplicate++;
-                        }
+                    //    if (2 == result || 3 == result)
+                    //    {
+                    //        results.Duplicate++;
+                    //    }
 
-                        continue;
-                    }
+                    //    continue;
+                    //}
 
-                    //재시도 실패 (재시도 옵션 활성화)
-                    if (isRetry)
-                    {
-                        _reportService.AddRetryReport(policyTid, fileName, file, false);
+                    ////재시도 실패 (재시도 옵션 활성화)
+                    //if (isRetry)
+                    //{
+                    //    _reportService.AddRetryReport(policyTid, fileName, file, false);
 
-                        continue;
-                    }
+                    //    continue;
+                    //}
                 }
 
                 var directories = Directory.GetDirectories(srcPath).ToList();
@@ -819,7 +834,7 @@ namespace Agent.Services
                             return -1;
                         }
 
-                        if (isHashCheck && FileUploadHashChk(con, transaction, policyTid, policyIndex.Tid, filePath))
+                        if (isHashCheck && FileUploadHashChk(con, transaction, policyTid, policyIndex.Tid, filePath, policyIndex.Name))
                         {
                             transaction.Rollback();
                             log.Info($"[DIRECTORY]중복 업로드 제한 (PolicyTid={policyTid})");
@@ -1089,12 +1104,26 @@ namespace Agent.Services
                     var info = new FileInfo(policy.Path);
                     
                     policy.Create_Date = info.LastWriteTime;
-                    String[] strfileName = fileName.Split('_');
-                    if (strfileName.Length > 2)
+
+                    // 데이터베이스에 넣기전 파싱하는 부분 (시험번호, 사용자) 명명규칙
+
+                    string sFiletype = fileName.Substring(fileName.LastIndexOf('.') + 1);
+
+                    if (sFiletype == "pdf")
                     {
-                        policy.Work_Emp = strfileName[0].ToString();
-                        policy.Test_No = strfileName[1].ToString();
-                    }else
+                        String[] strfileName = fileName.Split('_');
+                        if (strfileName.Length > 2)
+                        {
+                            policy.Work_Emp = strfileName[0].ToString();
+                            policy.Test_No = strfileName[1].ToString();
+                        }
+                        else
+                        {
+                            policy.Work_Emp = null;
+                            policy.Test_No = null;
+                        }
+                    }
+                    else
                     {
                         policy.Work_Emp = null;
                         policy.Test_No = null;
@@ -1115,22 +1144,22 @@ namespace Agent.Services
                     //실패
                     _reportService.AddBackupReport(policy.Tid, fileName, policy.Path, false);
 
-                    //재시도 (재시도 옵션 활성화)
-                    if (isRetry && 0 < AddFilePolicyHistory(policy, isHashCheck, isLimit))
-                    {
-                        successFile++;
-                        _reportService.AddRetryReport(policy.Tid, fileName, policy.Path, true);
+                    ////재시도 (재시도 옵션 활성화)
+                    //if (isRetry && 0 < AddFilePolicyHistory(policy, isHashCheck, isLimit))
+                    //{
+                    //    successFile++;
+                    //    _reportService.AddRetryReport(policy.Tid, fileName, policy.Path, true);
 
-                        continue;
-                    }
+                    //    continue;
+                    //}
 
-                    //재시도 실패 (재시도 옵션 활성화)
-                    if (isRetry)
-                    {
-                        _reportService.AddRetryReport(policy.Tid, fileName, policy.Path, false);
+                    ////재시도 실패 (재시도 옵션 활성화)
+                    //if (isRetry)
+                    //{
+                    //    _reportService.AddRetryReport(policy.Tid, fileName, policy.Path, false);
 
-                        continue;
-                    }
+                    //    continue;
+                    //}
                 }catch(Exception e)
                 {
                     log.Error($"File 백업 오류(PolicyTid={policy.Tid})" + ",  " + e.Message.ToString());
@@ -1204,7 +1233,6 @@ namespace Agent.Services
                             //File.SetCreationTime(tmpDstPath, File.GetCreationTime(tmpDstPath));
                             if (File.Exists(indexPath))
                             {
-                                
                                 File.Delete(indexPath);
                             }
                             File.Move(tmpDstPath, indexPath);
@@ -1448,7 +1476,7 @@ namespace Agent.Services
         /// <param name="policyIndexTid"></param>
         /// <param name="filePath"></param>
         /// <returns></returns>
-        public bool FileUploadHashChk(SqlConnection con, SqlTransaction transaction, int policyTid, int policyIndexTid, string filePath)
+        public bool FileUploadHashChk(SqlConnection con, SqlTransaction transaction, int policyTid, int policyIndexTid, string filePath, string fileName)
         {
             try
             {
@@ -1456,17 +1484,21 @@ namespace Agent.Services
 
                 var sql = @"
                     SELECT TOP 1 hash
-                    FROM [di_policy_history]
+                    FROM [di_policy_history] a
+                    INNER JOIN di_policy_index b ON a.policy_tid = b.policy_tid
                     WHERE 1=1
-                    AND policy_tid = @PolicyTid
-                    AND policy_index_tid = @PolicyIndexTid
-                    AND hash = @willUploadFileHash
+                        --AND policy_tid = @PolicyTid
+                        --AND policy_index_tid = @PolicyIndexTid
+                        AND hash = @willUploadFileHash
+                        AND name = @FileName
+                    
                     ORDER BY upload_date DESC
                 ";
 
                 //var willUploadFileHash = _hashService.FileToMD5(filePath);
 
-                return willUploadFileHash.Equals(con.Query<string>(sql, new { PolicyTid = policyTid, PolicyIndexTid = policyIndexTid, willUploadFileHash = willUploadFileHash }, transaction).SingleOrDefault());
+                return willUploadFileHash.Equals(con.Query<string>
+                    (sql, new { PolicyTid = policyTid, PolicyIndexTid = policyIndexTid, willUploadFileHash = willUploadFileHash, FileName = fileName }, transaction).SingleOrDefault());
             }
             catch (Exception e)
             {