Esempio n. 1
0
 private void AddHashInDB()
 {
     try
     {
         using (var db = new DataContext(Log.connection))
         {
             while (_hashQueue.Status != StatusWork.Complite)
             {
                 while (_hashQueue.TryDequeue(out var resultFile))
                 {
                     var dbRow = new HashInfo
                     {
                         NameFile = resultFile.FileName,
                         HashSum  = resultFile.HashSum
                     };
                     db.HashInfoes.Add(dbRow);
                     db.SaveChanges();
                 }
             }
             _hashQueue.AutoResetEvent.WaitOne();
         }
     }
     catch (Exception e)
     {
         var log = new CustomStorage("", e.Message, e.StackTrace);
         Log.BuildLogMessage(log);
     }
 }
Esempio n. 2
0
 public bool CheckDir(string dirPath)
 {
     if (!Directory.Exists(dirPath))
     {
         var log = new CustomStorage(dirPath, "You enter incorrect dir");
         Log.BuildLogMessage(log);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
 public void Start()
 {
     if (_fileinfo != null)
     {
         _hashQueue = new CustomQueue <CustomStorage>(_autoResetEvent);
         _thread    = new Thread(GetHash);
         _thread.Start();
     }
     else
     {
         var log = new CustomStorage("", "FileQueue is null");
         Log.BuildLogMessage(log);
     }
 }
Esempio n. 4
0
 private void PrepAdd()
 {
     if (_hashQueue != null)
     {
         AddHashInDB();
         Console.WriteLine("3 thread complete");
         Log.AutoResetEvent.Set();
     }
     else
     {
         var log = new CustomStorage("", "HashQueue is null");
         Log.BuildLogMessage(log);
     }
 }
Esempio n. 5
0
 private void Scan(string dirPath)
 {
     try
     {
         foreach (var dir in Directory.EnumerateDirectories(dirPath))
         {
             Scan(dir);
         }
         foreach (var item in Directory.GetFiles(dirPath))
         {
             ListFileName.Add(item);
             FileQueue.Enqueue(item);
         }
     }
     catch (Exception e)
     {
         var log = new CustomStorage(dirPath, e.Message, e.StackTrace);
         Log.BuildLogMessage(log);
     }
 }
Esempio n. 6
0
 private void Calc()
 {
     try
     {
         while (_fileinfo.Status != StatusWork.Complite)
         {
             while (_fileinfo.TryDequeue(out var resultFile))
             {
                 using (var md5Hash = MD5.Create())
                 {
                     using (var stream = File.OpenRead(resultFile))
                     {
                         var hash = new CustomStorage(resultFile, BitConverter.ToInt32(md5Hash.ComputeHash(stream), 0));
                         _hashQueue.Enqueue(hash);
                     }
                 }
             }
             _fileinfo.AutoResetEvent.WaitOne();
         }
         while (_fileinfo.TryDequeue(out var resultFile))
         {
             using (var md5Hash = MD5.Create())
             {
                 using (var stream = File.OpenRead(resultFile))
                 {
                     var hash = new CustomStorage(resultFile, BitConverter.ToInt32(md5Hash.ComputeHash(stream), 0));
                     _hashQueue.Enqueue(hash);
                 }
             }
         }
     }
     catch (Exception e)
     {
         var log = new CustomStorage("", e.Message, e.StackTrace);
         Log.BuildLogMessage(log);
     }
 }
Esempio n. 7
0
 public static void BuildLogMessage(CustomStorage log)
 {
     LogQueue.Enqueue(log);
     AutoResetEvent.Set();
 }