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,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Beam.Abstractions;
|
||||
|
||||
namespace Beam.Dynamic {
|
||||
public static class CommonStateChangers {
|
||||
public static IStateChangeBehaviour LastAsNumber => new NumberedStateChanger((x, i) => {
|
||||
object last = x.GetState()[^1];
|
||||
if (!int.TryParse(last.ToString(), out var number))
|
||||
throw new InvalidOperationException(Exceptions.Exceptions.state_change_error); // TODO use more specific exception
|
||||
x.GetState()[^1] = (number + i).ToString();
|
||||
});
|
||||
|
||||
public static IStateChangeBehaviour Constant => new ConstantStateChanger();
|
||||
|
||||
public static IStateChangeBehaviour NthAsNumber(Index n, bool keepSuffix = true)
|
||||
=> new NumberedStateChanger((x, i) => {
|
||||
string? nth = x.GetState()[n]?.ToString();
|
||||
string[] xState = x.GetState();
|
||||
if (nth is null)
|
||||
throw new InvalidOperationException(Exceptions.Exceptions.state_change_error); // TODO use more specific exception
|
||||
if (!int.TryParse(nth, out var number))
|
||||
if (keepSuffix) {
|
||||
string[] split = nth.Split('.');
|
||||
if (!int.TryParse(split[0], out number))
|
||||
throw new InvalidOperationException(Exceptions.Exceptions.state_change_error); // TODO use more specific exception
|
||||
xState[n] = (number + i) + split[1..].Aggregate((x, y) => $"{x}.{y}");
|
||||
return;
|
||||
} else
|
||||
throw new InvalidOperationException(Exceptions.Exceptions.state_change_error); // TODO use more specific exception
|
||||
xState[n] = (number + i).ToString();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user