849bdcd089
- Removed BindingType enum and all related logic from Binding. - Made Binding implement new IBinding and IKeyed interfaces. - Moved node selection logic to IBinding.Select; removed Resolve* methods from Binding. - Added new IBinding interface for XPath/CssPath selection. - Refactored IDataProvider to generic IDataProvider<T>; removed GetNode. - Updated ListContentDataProvider and ParagraphedContentDataProvider to use IBinding. - Added new ContentsDataProvider, ContentsArrayDataProvider, and DropDownDataProvider for flexible data extraction. - Updated DataBindings to use IDataProvider<T> properties instead of Binding. - Updated all usages to new interfaces and patterns.
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using HtmlAgilityPack;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Beam.Dynamic {
|
|
public class DropDownDataProvider
|
|
: IDataProvider<string>,
|
|
IDataProvider<string[]>,
|
|
IDataProvider<SourceLink[]> {
|
|
public IBinding? Content { get; set; }
|
|
|
|
public SourceLink[] Get(HtmlDocument document) {
|
|
if (Content is null)
|
|
return [];
|
|
var node = Content.Select(document);
|
|
if (node is null)
|
|
return [];
|
|
List<SourceLink> links = [];
|
|
foreach (var child in node.ChildNodes.Where(x => x.Name == "option")) {
|
|
var childValue = child.GetAttributeValue("value", null);
|
|
if (!Uri.TryCreate(childValue, UriKind.Absolute, out _))
|
|
continue;
|
|
links.Add(new SourceLink(childValue));
|
|
}
|
|
|
|
return links.ToArray();
|
|
}
|
|
|
|
string[] IDataProvider<string[]>.Get(HtmlDocument document) {
|
|
return this.Get(document).Select(x => x.Link.AbsoluteUri).ToArray();
|
|
}
|
|
|
|
string IDataProvider<string>.Get(HtmlDocument document) {
|
|
return JsonSerializer.Serialize(this.Get(document));
|
|
}
|
|
}
|
|
}
|