Пример #1
0
        public Guid Scan()
        {
            var searchedFiles = Directory.EnumerateFiles(this.path, "*.*", SearchOption.AllDirectories);

            var scanId = Guid.NewGuid();

            foreach (var file in searchedFiles)
            {
                if (FileShouldBeExcluded(file)) continue;
                var info = new FileInfo(file);
                this.files.Add(new DataFile { ScanId = scanId, FileNameFull = file, Size = info.Length });
            }
            _total = this.files.Count();

            using (var context = new DatabaseContext())
            {
                var skip = 0;
                var toSave = this.files.Take(100);
                while (toSave != null && toSave.Count() > 0)
                {
                    context.SearchFiles.AddRange(toSave);
                    context.SaveChanges();
                    skip = skip + 100;
                    _current = _current + 100;
                    toSave = this.files.Skip(skip).Take(100);
                }
            }

            return scanId;
        }
Пример #2
0
        public Guid Hash(Guid scanId)
        {
            _current = 0;
            using (var context = new DatabaseContext())
            {
                var allUnHashedfiles = context.SearchFiles.Where(item => item.ScanId == scanId && string.IsNullOrEmpty(item.Hash)).OrderBy(ord => ord.Size);
                _total = allUnHashedfiles.Count();

                var skip = 0;
                var toSave = allUnHashedfiles.Take(100);
                while (toSave != null && toSave.Count() > 0)
                {
                    Parallel.ForEach(toSave, (file) =>
                    {
                        var hash = FileHashCreator.GetMD5Hash(file.FileNameFull);
                        file.Hash = hash;
                        _current++;
                    });
                    context.SaveChanges();
                    skip = skip + 100;
                    toSave = allUnHashedfiles.Skip(skip).Take(100);
                }
            }

            return scanId;
        }
Пример #3
0
 public void Deny(ComparisonPair currentComparison)
 {
     using (var context = new DatabaseContext())
     {
         var item = context.DuplicateFiles.Find(currentComparison.DuplicateFile.Id);
         item.NotDuplicate = true;
         context.SaveChanges();
     }
 }
Пример #4
0
        private void PersistScan()
        {
            using (var context = new DatabaseContext())
            {
                context.DuplicationOwners.AddRange(this.state.Where(suspect => suspect.Owner != null).Select(item => item.Owner));
                context.SaveChanges();
            }

        }
Пример #5
0
 public ComparisonPair NextComparison()
 {
     using (var context = new DatabaseContext())
     {
         var dup = context.DuplicateFiles.Include("Datafile").FirstOrDefault(item => item.ScanId == this.scanId && !item.Confirmed && !item.NotDuplicate);
         if (dup == null) return null;
         var toFind = context.DuplicationOwners.Include("Owner").FirstOrDefault(owner => owner.DuplicateFiles.Any(suspect => suspect.DataFile.Id == dup.DataFileId));
         return new ComparisonPair(toFind, dup);
     }
 }
Пример #6
0
 public static Guid LastScanId()
 {
     using (var context = new DatabaseContext())
     {
         return context.SearchFiles.OrderByDescending(item => item.Id).First().ScanId;
     }
 }
Пример #7
0
 private void BuildInitialState()
 {
     using (var context = new DatabaseContext())
     {
         this.state = context.SearchFiles.Where(item => item.ScanId == this.scanId).Select(res => new ScanState { DataFile = res }).ToList();
     }
 }