public async Task LoadAsync(CollectionPath[] paths, Func<FileInfo, bool> filePredicate, ITargetBlock<Tuple<AnnotatedPath, IFileFingerprint>> joinedTargetBlock, CancellationToken cancellationToken) { await _fileFingerprintManager.LoadAsync(cancellationToken).ConfigureAwait(false); await GenerateFileFingerprintsAsync(paths, filePredicate, joinedTargetBlock, cancellationToken) .ConfigureAwait(false); }
async Task GenerateFileFingerprintsAsync(CollectionPath[] paths, Func<FileInfo, bool> filePredicate, ITargetBlock<Tuple<AnnotatedPath, IFileFingerprint>> joinedTargetBlock, CancellationToken cancellationToken) { try { var annotatedPathBroadcastBlock = new BroadcastBlock<AnnotatedPath[]>(aps => aps, new DataflowBlockOptions { CancellationToken = cancellationToken }); var joiner = new LinkFingerprintJoiner(joinedTargetBlock); annotatedPathBroadcastBlock.LinkTo(joiner.AnnotatedPathsBlock, new DataflowLinkOptions { PropagateCompletion = true }); var fileFingerprintBroadcastBlock = new BroadcastBlock<IFileFingerprint>(ff => ff, new DataflowBlockOptions { CancellationToken = cancellationToken }); fileFingerprintBroadcastBlock.LinkTo(joiner.FileFingerprintBlock, new DataflowLinkOptions { PropagateCompletion = true }); var fingerprintGeneratorTask = _fileFingerprintManager .GenerateFileFingerprintsAsync(annotatedPathBroadcastBlock, fileFingerprintBroadcastBlock, cancellationToken); try { await DirectoryScanner.GenerateAnnotatedPathsAsync(paths, filePredicate, annotatedPathBroadcastBlock, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { } catch (Exception ex) { Console.Write("Path scan failed: " + ex.Message); } await fingerprintGeneratorTask.ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine("GenerateFileFingerprintsAsync() failed: " + ex.Message); } finally { Debug.WriteLine("BlobManager.GenerateFileFingerprintsAsync() is done"); } }