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;
        }
 public void Deny(ComparisonPair currentComparison)
 {
     using (var context = new DatabaseContext())
     {
         var item = context.DuplicateFiles.Find(currentComparison.DuplicateFile.Id);
         item.NotDuplicate = true;
         context.SaveChanges();
     }
 }
        private void PersistScan()
        {
            using (var context = new DatabaseContext())
            {
                context.DuplicationOwners.AddRange(this.state.Where(suspect => suspect.Owner != null).Select(item => item.Owner));
                context.SaveChanges();
            }

        }
        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;
        }