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:
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Beam.Abstract</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="aeqw89.DataKeys" Version="2.1.0" />
|
||||
<PackageReference Include="aeqw89.PersistentData" Version="1.3.3" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IArticleData : IDocumentMetaData, IEquatable<IArticleData?> {
|
||||
string? Name { get; set; }
|
||||
string[] Authors { get; set; }
|
||||
string? Language { get; set; }
|
||||
string[] Categories { get; set; }
|
||||
string? Version { get; set; }
|
||||
string? Description { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Beam.Dynamic;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IDataBindings {
|
||||
IDataProvider<string>? Title { get; set; }
|
||||
IDataProvider<string[]>? Authors { get; set; }
|
||||
IDataProvider<string>? Description { get; set; }
|
||||
IDataProvider<string>? Content { get; set; }
|
||||
IDataProvider<string[]>? Language { get; set; }
|
||||
IDataProvider<string[]>? Tags { get; set; }
|
||||
IDataProvider<string>? Publisher { get; set; }
|
||||
IDataProvider<DateTimeOffset>? PublicationDate { get; set; }
|
||||
IDataProvider<string>? ISBN { get; set; }
|
||||
IDataProvider<int>? PageCount { get; set; }
|
||||
IDataProvider<string>? CoverImage { get; set; }
|
||||
IDataProvider<string[]>? Series { get; set; }
|
||||
IDataProvider<int>? Edition { get; set; }
|
||||
IDataProvider<string[]>? Contributors { get; set; }
|
||||
IDataProvider<string[]>? Subjects { get; set; }
|
||||
IDataProvider<string>? Rights { get; set; }
|
||||
IDataProvider<string[]>? TableOfContents { get; set; }
|
||||
IDataProvider<string[]>? PagesDropDown { get; set; }
|
||||
IDataProvider<string>? NextPageButton { get; set; }
|
||||
IDataProvider<string>? PreviousPageButton { get; set; }
|
||||
Dictionary<string, IDataProvider?> Providers { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using HtmlAgilityPack;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Beam.Dynamic;
|
||||
|
||||
public interface IDataProvider {
|
||||
public string GetString(HtmlDocument document)
|
||||
=> (this as IDataProvider<object>)?.Get(document)?.ToString() ?? "";
|
||||
}
|
||||
|
||||
public interface IDataProvider<out T> : IDataProvider {
|
||||
public T Get(HtmlDocument document);
|
||||
//public HtmlNode? GetNode(HtmlDocument document);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using aeqw89.DataKeys;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IDocument {
|
||||
/// <summary>
|
||||
/// The file name of the document. Must be valid in both <c>UNIX</c>,
|
||||
/// <c>WINDOWS</c>, <c>APPLE</c>, and <c>ANDROID</c> file systems.
|
||||
/// </summary>
|
||||
string Filename { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional descriptive data
|
||||
/// </summary>
|
||||
IDictionary<IDataKey<IDocumentMetaData>, IDocumentMetaData> MetaData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the binary representation for the <see cref="IDocument"/>
|
||||
/// </summary>
|
||||
/// <returns>Binary representation of the <see cref="IDocument"/></returns>
|
||||
byte[] ToBytes();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the string representation for the <see cref="IDocument"/>
|
||||
/// </summary>
|
||||
/// <returns>String representation of the <see cref="IDocument"/></returns>
|
||||
string ToString();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IDocumentMetaData {
|
||||
string AsJson(JsonSerializerOptions? options = null);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IDownloadReport { }
|
||||
@@ -0,0 +1,11 @@
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface ILinkBuilder {
|
||||
/// <summary>
|
||||
/// Produces a concrete <see cref="SourceLink"/> using values from an external <see cref="State"/> object.
|
||||
/// </summary>
|
||||
/// <param name="parameterValues">Object providing positional values.</param>
|
||||
string Build(IReadOnlyState parameterValues);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IOrdered<out T> {
|
||||
T Data { get; }
|
||||
int Order { get; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Beam.Models;
|
||||
|
||||
public interface IReadOnlyState {
|
||||
public string[] GetState();
|
||||
IReadOnlyState Copy();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IResourceDictionary { }
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IRetryReport {
|
||||
int TryNumber { get; }
|
||||
string Link { get; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IState : IReadOnlyState {
|
||||
void SetState(string[] state);
|
||||
new IState Copy();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Beam.Models;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Defines how a url template should should be updated, in what order, and by how much
|
||||
/// </summary>
|
||||
public interface IStateChangeBehaviour {
|
||||
public void Apply(IState state, object stimulus);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IStateChangerFactory { }
|
||||
@@ -0,0 +1,8 @@
|
||||
using aeqw89.DataKeys;
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface ITemplate : IKeyed<ITemplate> {
|
||||
IStateChangerFactory Factory { get; set; }
|
||||
ILinkBuilder Builder { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
namespace Beam.Abstractions;
|
||||
|
||||
public interface IUnitDownloader<T> {
|
||||
public int LinksPerDownload { get; }
|
||||
public Task<(bool, T?)> TryDownload(IOrdered<string>[] link, CancellationToken ct, int maximumRetryCount = 7, IProgress<IRetryReport>? tryProgress = null);
|
||||
}
|
||||
Reference in New Issue
Block a user