Introduce Beam.Fluent and Beam.Models projects

Added new Beam.Fluent and Beam.Models projects with staged download builder and data context models. Refactored and moved model classes from Beam.Temporary.Cli to Beam.Models. Added new data providers and extended DataBindings in Beam.Dynamic. Renamed Beam.Puppeteer to Beam.Playwright and updated related classes. Updated project references and package versions. Removed obsolete and unused files from Beam.Temporary.Cli.
This commit is contained in:
qwsdcvghyu89
2025-09-18 18:32:25 +10:00
parent 849bdcd089
commit a7d148a96f
72 changed files with 2100 additions and 721 deletions
@@ -0,0 +1,39 @@
using Microsoft.Playwright;
namespace Beam.Playwright {
public class PlaywrightUnitDownloader<T> : UnitDownloaderBinary<T> {
public PlaywrightAsyncManipulator PuppetManipulator { get; }
public PlaywrightUnitDownloader(HttpClient client, PlaywrightAsyncManipulator puppetManipulator, AsyncTransformer<ByteDocument, T> asyncHtmlTransformer, AsyncDownloadFailurePredicate<ByteDocument>[] asyncDownloadFailurePredicates)
: base(client, asyncHtmlTransformer, asyncDownloadFailurePredicates) {
PuppetManipulator = puppetManipulator;
}
protected override async Task<(bool, T?)> TryDownloadWithNoRetries(string link, CancellationToken ct) {
var page = await PlaywrightContext.Browser.Value.NewPageAsync();
try {
await page.GotoAsync(link);
await PuppetManipulator(page);
var download = await page.WaitForDownloadAsync();
using var stream = await download.CreateReadStreamAsync();
byte[] content = new byte[stream.Length];
await stream.ReadExactlyAsync(content, ct);
ByteDocument doc = new ByteDocument(download.SuggestedFilename, content);
if (FailurePredicates is not null && await IsFailure(doc))
return (false, default);
var transformed = await Transformer(doc);
return (true, transformed);
} catch (Exception) {
return (false, default);
} finally {
if (!page.IsClosed)
await page.CloseAsync();
}
}
}
}