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 void Deny(ComparisonPair currentComparison)
 {
     using (var context = new DatabaseContext())
     {
         var item = context.DuplicateFiles.Find(currentComparison.DuplicateFile.Id);
         item.NotDuplicate = true;
         context.SaveChanges();
     }
 }
Exemplo n.º 3
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.º 4
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;
        }