Exemplo n.º 1
0
 //-------------------------------------------------------------------------
 public Audit CreateAuditAndMoveToTempFolder(string fileName, string directory, bool delete = true)
 {
     string sourceSHA1Hash = GetSHA1FromFile(fileName);
     var tempFileName = directory + sourceSHA1Hash + Path.GetExtension(fileName);
     var tempAuditFileName = directory + sourceSHA1Hash + ".audit";
     Audit audit = new Audit(fileName, sourceSHA1Hash);
     if (CanAccess(fileName))
     {
         File.Copy(fileName, tempFileName, true);
         if (delete)
         {
             iOHelper.DeleteFile(fileName);
         }
         audit.Save(tempAuditFileName);
     }
     return audit;
 }
Exemplo n.º 2
0
 //-------------------------------------------------------------------------
 public void MoveFileFromTemp(string dir, string incomingFile, Audit audit, string destFileName)
 {
     string tempFileName = dir + Path.GetFileName(incomingFile);
     string tempAuditFileName = GetFileAuditName(tempFileName);
     string destAuditFileName = GetFileAuditName(destFileName);
     try
     {
         audit.Save(destAuditFileName);
         File.Copy(tempFileName, destFileName, true);
         iOHelper.DeleteFile(tempAuditFileName);
         iOHelper.DeleteFile(tempFileName);
     }
     catch (Exception ex)
     {
         log.LogMessage(ex);
     }
 }
Exemplo n.º 3
0
 //-------------------------------------------------------------------------
 public string GetFileForRecognize(string fileName, string tempdirectory, bool showLog = true)
 {
     //bool useErrFolder = false;
     if (string.IsNullOrEmpty(tempdirectory))
     {
         //useErrFolder = true;
         tempdirectory = OcrAppConfig.TempEdFolder;
     }
     if (showLog) log.LogMessage("Get file for recognize: " + fileName);
     if (!File.Exists(fileName))
     {
         if (showLog) log.LogMessage("File does not exist " + fileName);
         return null;
     }
     string fileNameAudit = GetFileAuditName(fileName);
     var sha1hash = GetSHA1FromFile(fileName);
     if (File.Exists(fileNameAudit) && fileName.Contains(sha1hash) && fileName.Contains(tempdirectory))
     {
         return fileName;
     }
     if (fileName.Contains(sha1hash) && fileName.Contains(tempdirectory))
     {
         iOHelper.DeleteFile(fileNameAudit);
         var audit = new Audit(fileName, GetSHA1FromFile(fileName));
         audit.Save(GetFileAuditName(fileName));
         return fileName;
     }
     string destfileName = tempdirectory + sha1hash + Path.GetExtension(fileName);
     string destfileNameAudit = GetFileAuditName(destfileName);//The file exists.
     if (File.Exists(fileNameAudit))// && fileName.Contains(sha1hash)
     {
         //try
         //{
         //    File.Move(fileName, destfileName);
         //    File.Move(fileNameAudit, destfileNameAudit);
         //}
         //catch (Exception ex)
         //{
         //    log.LogMessage(ex);
         //    return null;
         //}
         try
         {
             if (!File.Exists(destfileName))
             {
                 File.Move(fileName, destfileName);
             }
             else
             {
                 File.Delete(fileName);
             }
         }
         catch (Exception ex)
         {
             log.LogMessage(ex);
         }
         try
         {
             if (!File.Exists(destfileNameAudit))
             {
                 File.Move(fileNameAudit, destfileNameAudit);
             }
             else
             {
                 File.Delete(fileNameAudit);
             }
         }
         catch (Exception ex)
         {
             log.LogMessage(ex);
         }
         return destfileName;
     }
     else
     {
         log.LogMessage("File " + fileNameAudit + " not exists");
         FileInfo fi = new FileInfo(fileName);
         DateTime begEx = DateTime.Parse(fi.CreationTime.ToString());
         TimeSpan ts = DateTime.Now - begEx;
         if (ts.TotalSeconds < 2)
             return "";
     }
     CreateAuditAndMoveToTempFolder(fileName, tempdirectory);
     return destfileName;
 }