Files
Beam/Beam.Dynamic/DataProviders/RelationalDataProvider.cs
T
qwsdcvghyu89 18c5ad83da 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.
2025-11-14 03:41:13 +11:00

32 lines
868 B
C#

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()
};
}
}