Refactor downloaders to use ByteDocument and add options builders
Replaces generic RawType with ByteDocument in downloaders and context classes, simplifying type usage. Adds builder classes for FailurePredicateOptions, FragmentOptions, SkipPredicateOptions, and UnitDownloaderOptions to improve configuration flexibility. Introduces DownloadTarget enum and SkipPredicate delegate for more granular download control. Refactors Fluent API interfaces and implementations to remove RawType generics and streamline usage. Adds Playwright and Stealth download strategies for extensibility.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Downloaders;
|
||||
|
||||
public class SkipPredicateOptions<OutType> {
|
||||
public required SkipPredicate<OutType>?[]? SkipPredicates { get; init; }
|
||||
public bool ProcessInParallel { get; init; } = false;
|
||||
public int? ParallelThreads { get; init; }
|
||||
}
|
||||
|
||||
public class SkipPredicateOptionsBuilder<OutType> {
|
||||
private List<SkipPredicate<OutType>?> _skipPredicates { get; set; } = [];
|
||||
private bool _processInParallel { get; set; } = false;
|
||||
private int? _parallelThreads { get; set; }
|
||||
|
||||
public SkipPredicateOptionsBuilder<OutType> WithSkipPredicate(SkipPredicate<OutType> predicate, bool replace=false) {
|
||||
if (replace)
|
||||
_skipPredicates.Clear();
|
||||
_skipPredicates.Add(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SkipPredicateOptionsBuilder<OutType> WithSkipPredicates(SkipPredicate<OutType>[] predicates,
|
||||
bool replace = true) {
|
||||
if (replace)
|
||||
_skipPredicates.Clear();
|
||||
_skipPredicates.AddRange(predicates);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SkipPredicateOptionsBuilder<OutType> ProcessInParallel(bool processInParallel = true) {
|
||||
_processInParallel = processInParallel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SkipPredicateOptionsBuilder<OutType> WithParallelThreads(int parallelThreads) {
|
||||
_parallelThreads = parallelThreads;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SkipPredicateOptions<OutType> Build() {
|
||||
return new SkipPredicateOptions<OutType>() {
|
||||
SkipPredicates = _skipPredicates.ToArray(),
|
||||
ParallelThreads = _parallelThreads,
|
||||
ProcessInParallel = _processInParallel
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user