Added constant state changers to represent singular/repeating states. Added a DownloadContextBuilder to support fluent building patterns. Changed RetryReporter and DownloadReporter to use RetryReport and DownloadReport structs to simplify type declarations. Made MainArchitecture obsolete by supporting a fluent downloads with DownloadBuilder. Created a 'budge' OpenAI bridge for proof-of-concept translation.
This commit is contained in:
@@ -5,8 +5,16 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Beam {
|
||||
public class Parameter(string name) {
|
||||
[Flags]
|
||||
public enum Position {
|
||||
Before = 0b01,
|
||||
After = 0b10,
|
||||
BeforeAndAfter = 0b11
|
||||
}
|
||||
|
||||
public class Parameter(string name, Position position = Position.Before) {
|
||||
public string Name { get; set; } = name;
|
||||
public Position Position { get; set; } = position;
|
||||
}
|
||||
|
||||
public class LinkSegment(string name, string separator = "", string suffix = "") {
|
||||
@@ -14,6 +22,16 @@ namespace Beam {
|
||||
public List<Parameter> Parameters { get; set; } = [];
|
||||
public string Separator { get; set; } = separator;
|
||||
public string Suffix { get; set; } = suffix;
|
||||
|
||||
public LinkSegment WithParameters(params string[] parameters) {
|
||||
Parameters = parameters.Select((x) => new Parameter(x)).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LinkSegment WithParameters(params (string, Position)[] parameters) {
|
||||
Parameters = parameters.Select((x) => new Parameter(x.Item1, x.Item2)).ToList();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class SourceLinkBuilder(string host, string protocol = "https") {
|
||||
@@ -64,6 +82,26 @@ namespace Beam {
|
||||
Segments.Add(new LinkSegment(name, separator));
|
||||
}
|
||||
|
||||
public SourceLinkBuilder WithSegments(params IEnumerable<string> segments) {
|
||||
Segments = segments.Select((x) => new LinkSegment(x)).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceLinkBuilder WithSegments(int count)
|
||||
=> WithSegments(Enumerable.Repeat("", count));
|
||||
|
||||
public SourceLinkBuilder WithParameters(int i, params string[] parameters) {
|
||||
Segments[i]
|
||||
.WithParameters(parameters);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceLinkBuilder WithParameters(int i, params (string, Position)[] parameters) {
|
||||
Segments[i]
|
||||
.WithParameters(parameters);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void AddParameters(int segmentIndex, params string[] parameters) {
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(segmentIndex, Segments.Count);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(segmentIndex);
|
||||
@@ -97,6 +135,9 @@ namespace Beam {
|
||||
return count;
|
||||
}
|
||||
|
||||
public SourceLink Build(State parameterValues)
|
||||
=> Build(parameterValues.GetState());
|
||||
|
||||
public SourceLink Build(params object[] parameterValues) {
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(parameterValues.Length, GetParameterCount());
|
||||
|
||||
@@ -109,8 +150,11 @@ namespace Beam {
|
||||
link.Append('/');
|
||||
link.Append(segment.Name);
|
||||
for (int i = 0; i < segment.Parameters.Count; i++) {
|
||||
link.Append(segment.Parameters[i].Name);
|
||||
if (segment.Parameters[i].Position.HasFlag(Position.Before))
|
||||
link.Append(segment.Parameters[i].Name);
|
||||
link.Append(parameterValues[pvC++]);
|
||||
if (segment.Parameters[i].Position.HasFlag(Position.After))
|
||||
link.Append(segment.Parameters[i].Name);
|
||||
if (i + 1 < segment.Parameters.Count && segment.Separator is not null)
|
||||
link.Append(segment.Separator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user