Ejemplo n.º 1
0
        public async Task <FileCheckReport> Execute(ImportFilesRequest request, CancellationToken cancellationToken = default)
        {
            State.Status = ImportFilesStatus.Scanning;

            var fileInfos = new FileInformation[request.Files.Count];
            var counter   = -1; // as we always increment and the first index is zero

            await TaskCombinators.ThrottledAsync(request.Files, async (filename, _) =>
            {
                var index = Interlocked.Increment(ref counter);
                try
                {
                    var file = request.Directory.GetFile(filename);
                    if (file == null)
                    {
                        return;               // not found
                    }
                    fileInfos[index] = await _fileInformationLoader.Load(file);
                }
                finally
                {
                    State.Progress = (double)counter / request.Files.Count;
                }
            }, cancellationToken, 4);

            State.Status = ImportFilesStatus.Querying;
            _checkFilesWorker.State.PropertyChanged += (_, __) => State.Progress = _checkFilesWorker.State.Progress;

            return(await _checkFilesWorker.Execute(new CheckFilesRequest(fileInfos.Where(x => x != null).ToList(), request.Directory), cancellationToken));
        }
        public async ValueTask <FileInformation> Load(IFile file)
        {
            if (_cachedResults.TryGetValue(file.Filename, out var fileInformation))
            {
                return(fileInformation);
            }

            var result = await _fileInformationLoader.Load(file);

            _cachedResults.TryAdd(file.Filename, result);

            return(result);
        }
Ejemplo n.º 3
0
        private async Task <(IndexedFile, bool fromBb)> GetFileInformation(IFile file, IIndexedFileRepository repository)
        {
            var fileHash    = ComputeHash(file);
            var indexedFile = await repository.FirstOrDefaultBySpecs(new FindByFileHashSpec(fileHash),
                                                                     new IncludeFileLocationsSpec());

            if (indexedFile != null)
            {
                return(indexedFile, true);
            }

            var info = await _fileInformationLoader.Load(file);

            indexedFile = new IndexedFile(info.Hash, info.Length, info.FileCreatedOn, info.PhotoProperties);
            return(indexedFile, false);
        }