7ed05abdb8
- 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.
40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
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();
|
|
});
|
|
|
|
|
|
}
|
|
}
|