Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
            }

        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 6
0
 public static Guid LastScanId()
 {
     using (var context = new DatabaseContext())
     {
         return context.SearchFiles.OrderByDescending(item => item.Id).First().ScanId;
     }
 }
Exemplo n.º 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();
     }
 }