fix(schedules): corrected serialization of pathRegex
This commit is contained in:
parent
2e93ebdb7c
commit
185980b5c4
2 changed files with 16 additions and 6 deletions
|
@ -21,7 +21,7 @@ public partial class NumericalPathSchedule : ISchedule
|
||||||
{
|
{
|
||||||
public NumericalPathSchedule()
|
public NumericalPathSchedule()
|
||||||
{
|
{
|
||||||
this.PathRegex = new Regex(@"^.*(\d+)");
|
this.PathRegex = @"^.*(\d+)";
|
||||||
this.GetPath = entity => entity.Get<UPath>().ToString();
|
this.GetPath = entity => entity.Get<UPath>().ToString();
|
||||||
this.CaptureGroup = 1;
|
this.CaptureGroup = 1;
|
||||||
this.CaptureOffset = -1;
|
this.CaptureOffset = -1;
|
||||||
|
@ -47,7 +47,7 @@ public partial class NumericalPathSchedule : ISchedule
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the regular expression to identify a matching path.
|
/// Gets or sets the regular expression to identify a matching path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Regex? PathRegex { get; set; }
|
public string? PathRegex { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the period between each matching entity. The period is
|
/// Gets or sets the period between each matching entity. The period is
|
||||||
|
@ -83,7 +83,8 @@ public partial class NumericalPathSchedule : ISchedule
|
||||||
{
|
{
|
||||||
// Get the path and match it.
|
// Get the path and match it.
|
||||||
string? path = this.GetPath(entity);
|
string? path = this.GetPath(entity);
|
||||||
Match? match = this.PathRegex?.Match(path)
|
Regex? regex = this.GetRegex();
|
||||||
|
Match? match = regex?.Match(path)
|
||||||
?? throw new NullReferenceException(
|
?? throw new NullReferenceException(
|
||||||
"PathRegex was not configured for the "
|
"PathRegex was not configured for the "
|
||||||
+ this.GetType().Name
|
+ this.GetType().Name
|
||||||
|
@ -116,12 +117,20 @@ public partial class NumericalPathSchedule : ISchedule
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual bool CanApply(Entity entity)
|
public virtual bool CanApply(Entity entity)
|
||||||
{
|
{
|
||||||
string? path = this.GetPath(entity);
|
string path = this.GetPath(entity);
|
||||||
bool match = this.PathRegex?.IsMatch(path) ?? false;
|
Regex? regex = this.GetRegex();
|
||||||
|
bool match = regex?.IsMatch(path) ?? false;
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Regex? GetRegex()
|
||||||
|
{
|
||||||
|
return this.PathRegex == null
|
||||||
|
? null
|
||||||
|
: new Regex(this.PathRegex);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual Entity Apply(
|
protected virtual Entity Apply(
|
||||||
Entity entity,
|
Entity entity,
|
||||||
int number,
|
int number,
|
||||||
|
|
|
@ -47,7 +47,8 @@ public class NumericalPathScheduleTests : TemporalSchedulesTestBase
|
||||||
"---",
|
"---",
|
||||||
"access: custom",
|
"access: custom",
|
||||||
"schedules:",
|
"schedules:",
|
||||||
" - scheduleStart: 2023-01-01",
|
" - pathRegex: chapter-(\\d+)",
|
||||||
|
" scheduleStart: 2023-01-01",
|
||||||
" access: public",
|
" access: public",
|
||||||
""));
|
""));
|
||||||
List<TestSchedule>? schedules = model.Schedules!;
|
List<TestSchedule>? schedules = model.Schedules!;
|
||||||
|
|
Reference in a new issue