refactor: modularize Beam into new projects and interfaces
- Introduced modularity by splitting Beam into new projects: Beam.Abstractions, Beam.Models, and Beam.Downloaders. - Refactored existing classes into appropriate namespaces and projects. - Replaced specific implementations with abstractions (e.g., SourceLinkBuilder to LinkBuilder, State to IState, etc.). - Updated interfaces: added ITemplate, IArticleData, IDownloadReport, and others for improved extensibility. - Removed deprecated classes like SourceLinkBuilder and StateChangerFactory. - Enhanced link handling in downloaders by refactoring to use `string` over `SourceLink`. - Consolidated shared logic under Beam.Abstractions.
This commit is contained in:
@@ -7,16 +7,19 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="aeqw89.DataKeys" Version="2.0.1" />
|
||||
<PackageReference Include="aeqw89.PersistentData" Version="1.1.0" />
|
||||
<PackageReference Include="aeqw89.PersistentData" Version="1.3.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.7" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Beam.Data\Beam.Data.csproj" />
|
||||
<ProjectReference Include="..\Beam.Downloaders\Beam.Downloaders.csproj" />
|
||||
<ProjectReference Include="..\Beam.Dynamic\Beam.Dynamic.csproj">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Beam.Exceptions\Beam.Exceptions.csproj" />
|
||||
<ProjectReference Include="..\Beam.Models\Beam.Models.csproj" />
|
||||
<ProjectReference Include="..\Beam.Playwright\Beam.Playwright.csproj">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -24,8 +27,6 @@
|
||||
<ProjectReference Include="..\Beam.Stealth\Beam.Stealth.csproj">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Beam\Beam.csproj">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Beam\Beam.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,10 @@
|
||||
using HtmlAgilityPack;
|
||||
using Beam.Abstractions;
|
||||
using Beam.Models;
|
||||
using HtmlAgilityPack;
|
||||
using Beam.Playwright;
|
||||
using Beam.Stealth;
|
||||
using Beam;
|
||||
using Beam.Downloaders;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
@@ -33,7 +37,7 @@ public static partial class DownloadBuilder<RawType, OutType> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IContextStage WithRetryReporter(IProgress<RetryReport> reporter) {
|
||||
public IContextStage WithRetryReporter(IProgress<IRetryReport> reporter) {
|
||||
_ctxBuilder.WithRetryReporter(reporter);
|
||||
return this;
|
||||
}
|
||||
@@ -163,7 +167,7 @@ public static partial class DownloadBuilder<RawType, OutType> {
|
||||
}
|
||||
|
||||
private IAsyncEnumerator<Ordered<OutType>> ConstructDownloader(DownloadContext<RawType> context) {
|
||||
var copyOfContext = context.CreateBuilder().Build();
|
||||
var copyOfContext = DownloadContextBuilder<RawType>.FromContext(context).Build();
|
||||
return _useFragments switch {
|
||||
true => new SequentialFragmentDownloader<RawType, OutType>(
|
||||
copyOfContext,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
namespace Beam.Fluent {
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
public interface IAlternativeLinkStage {
|
||||
IAlternativeTransformStage WithLinks(IEnumerable<SourceLink> links);
|
||||
IAlternativeTransformStage WithLinks(IEnumerable<string> links);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Beam.Fluent {
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
public interface IAlternativeTransformStage {
|
||||
IContextStage WithTransformer(AsyncTransformer<RawType, OutType> transformer);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Beam.Playwright;
|
||||
using Beam.Abstractions;
|
||||
using Beam.Downloaders;
|
||||
using Beam.Models;
|
||||
using Beam.Playwright;
|
||||
using Beam.Stealth;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
@@ -7,7 +10,7 @@ public static partial class DownloadBuilder<RawType, OutType> {
|
||||
IContextStage Configure(Action<DownloadContextBuilder<RawType>> configure);
|
||||
IContextStage WithParallelism(int degree);
|
||||
IContextStage WithTimeout(TimeSpan timeout);
|
||||
IContextStage WithRetryReporter(IProgress<RetryReport> reporter);
|
||||
IContextStage WithRetryReporter(IProgress<IRetryReport> reporter);
|
||||
DownloadEnumerable<OutType> Build();
|
||||
IContextStage UseFragments();
|
||||
IContextStage UsePlaywright(PlaywrightAsyncManipulator manipulator);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Beam.Dynamic;
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using Beam.Models;
|
||||
using Beam.Data;
|
||||
using Beam.Downloaders;
|
||||
using Beam.Dynamic;
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
public static partial class DownloadBuilder<RawType, OutType> {
|
||||
/* ──────────────────────────── Stage types ─────────────────────────── */
|
||||
|
||||
|
||||
private sealed record LinkStage(
|
||||
WebResource Source,
|
||||
State Initial,
|
||||
@@ -22,7 +23,7 @@ namespace Beam.Fluent {
|
||||
|
||||
public ITransformStage WithLinkGenerator() {
|
||||
var template = Data.Templates[Source.Key];
|
||||
var generator = SourceLinkEnumerable.FromGenerator(new OrderedSourceLinkGenerator(
|
||||
var generator = StringEnumerable.FromGenerator(new OrderedLinkGenerator(
|
||||
template.Builder,
|
||||
new NumberedStateChanger(template.Factory.Behavior),
|
||||
Initial, endState));
|
||||
@@ -31,7 +32,7 @@ namespace Beam.Fluent {
|
||||
return new TransformStage(Source, Data, CtxBuilder);
|
||||
}
|
||||
|
||||
public IAlternativeTransformStage WithLinks(IEnumerable<SourceLink> links) {
|
||||
public IAlternativeTransformStage WithLinks(IEnumerable<string> links) {
|
||||
CtxBuilder.WithLinks(links);
|
||||
return new TransformStage(Source, Data, CtxBuilder);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Beam.Dynamic;
|
||||
using Beam.Data;
|
||||
using Beam.Downloaders;
|
||||
using Beam.Dynamic;
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
|
||||
@@ -3,6 +3,8 @@ using Beam;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Beam.Data;
|
||||
using Beam.Downloaders;
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Fluent {
|
||||
@@ -22,7 +24,7 @@ namespace Beam.Fluent {
|
||||
|
||||
private static ILinkStage Create(DataKey<ResourceDictionary> resourceDict, BeamDataContext data, string kind) {
|
||||
var (source, initial) = Resolve(resourceDict, kind, data);
|
||||
var ctxBuilder = new DownloadContextBuilder<RawType>().WithLinks(Array.Empty<SourceLink>()); // placeholder, filled later.
|
||||
var ctxBuilder = new DownloadContextBuilder<RawType>().WithLinks([]); // placeholder, filled later.
|
||||
return new LinkStage(source, initial, data, ctxBuilder);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user