Refactor data providers and update abstractions
- Removed obsolete data providers: `AnchorCollectionDataProvider`, `ContentsDataProvider`, and others, consolidating logic into new composable providers. - Added `ComposeDataProviders`, `SelectDataProvider`, and `RelationalDataProvider` for improved flexibility and reusability. - Introduced `IManySelectionComposableDataProvider` interface to support multiple-node selection. - Enhanced `UnitDownloader` with more robust progress tracking. - Updated package references and project dependencies for consistency. - Improved error handling in `StealthConfig` initialization for better fallback on browser drivers. - Incremented project version to 2.4.5.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Beam.Abstractions;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace Beam.Dynamic;
|
||||
|
||||
public enum RelationType {
|
||||
Parent,
|
||||
Child,
|
||||
}
|
||||
|
||||
public class RelationalDataProvider : IComposableDataProvider<HtmlNode?> {
|
||||
|
||||
public RelationType RelationType { get; set; } = RelationType.Parent;
|
||||
public IBinding? Content { get; set; }
|
||||
|
||||
public HtmlNode? Get(HtmlDocument document) {
|
||||
return Select(document);
|
||||
}
|
||||
public HtmlNode? Get(HtmlNode node) {
|
||||
return Select(node);
|
||||
}
|
||||
public HtmlNode? Select(HtmlDocument doc) {
|
||||
return Select(Content?.Select(doc) ?? doc.DocumentNode);
|
||||
}
|
||||
public HtmlNode? Select(HtmlNode node) {
|
||||
return RelationType switch {
|
||||
RelationType.Parent => node.ParentNode,
|
||||
RelationType.Child => node.FirstChild,
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user