Compare commits

...

2 commits

Author SHA1 Message Date
b6cf0b6d5c feat: reworking schedules to handle future dates
Some checks failed
deploy / deploy (push) Has been cancelled
2024-06-05 17:56:26 -05:00
443789c391 refactor: code cleanup 2024-06-05 17:54:40 -05:00
33 changed files with 87 additions and 76 deletions

View file

@ -1,4 +1,5 @@
root = true
["*"]
charset = "utf-8"
csharp_new_line_before_members_in_object_initializers = false
@ -104,7 +105,8 @@ tab_width = 4
["*.md"]
max_line_length = "off"
["*.{appxmanifest,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}]"]
["*.{appxmanifest,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}]
"]
indent_size = 2
indent_style = "space"
tab_width = 2

View file

@ -40,8 +40,7 @@ public class ConfigCommand : Command, ICommandHandler, ITopCommand
public Task<int> InvokeAsync(InvocationContext context)
{
// Get the settings and report that it was being created.
ConfigCommandSettings settings =
this.service.ReadDefaultConfigFile<ConfigCommandSettings>();
var settings = this.service.ReadDefaultConfigFile<ConfigCommandSettings>();
if (settings == null)
{

View file

@ -28,7 +28,9 @@ public class SampleToolModule : Module
};
// Add in the top-level commands.
var commandList = c.Resolve<IList<ITopCommand>>().Cast<Command>().ToList();
List<Command> commandList = c.Resolve<IList<ITopCommand>>()
.Cast<Command>()
.ToList();
if (commandList.Count == 0)
{

View file

@ -38,8 +38,7 @@ public class GemtextPipeTableExtension : IMarkdownExtension
pipeline.BlockParsers.Insert(0, new PipeTableBlockParser());
}
LineBreakInlineParser? lineBreakParser =
pipeline.InlineParsers.FindExact<LineBreakInlineParser>();
var lineBreakParser = pipeline.InlineParsers.FindExact<LineBreakInlineParser>();
if (!pipeline.InlineParsers.Contains<PipeTableParser>())
{

View file

@ -24,7 +24,7 @@ public class IncreaseHeaderDepthsAfterFirst : IMarkdownExtension
return;
}
HeadingRenderer? heading = gemtext.ObjectRenderers.Find<HeadingRenderer>();
var heading = gemtext.ObjectRenderers.Find<HeadingRenderer>();
if (heading != null)
{

View file

@ -22,7 +22,7 @@ public class WikiLinkExtension : IMarkdownExtension
/// <inheritdoc />
public void Setup(MarkdownPipelineBuilder pipeline)
{
WikiLinkInlineParser? parser = pipeline.InlineParsers.FindExact<WikiLinkInlineParser>();
var parser = pipeline.InlineParsers.FindExact<WikiLinkInlineParser>();
if (parser != null)
{

View file

@ -68,7 +68,7 @@ public partial class CreateCalender : OperationBase
calendar.TimeZones.Add(new VTimeZone(this.clock.DateTimeZone.Id));
// Go through the events and add all of them.
var input = entities.ToList();
List<Entity>? input = entities.ToList();
IEnumerable<CalendarEvent> events = input.Select(this.CreateCalendarEvent);
calendar.Events.AddRange(events);
@ -89,7 +89,7 @@ public partial class CreateCalender : OperationBase
private CalendarEvent CreateCalendarEvent(Entity entity)
{
Instant instant = entity.Get<Instant>();
var instant = entity.Get<Instant>();
var when = this.clock.ToDateTime(instant);
string summary = this.GetEventSummary!(entity);
Uri? url = this.GetEventUrl?.Invoke(entity);

View file

@ -72,7 +72,7 @@ public abstract class ClassAttributeSyntaxReceiverBase : ISyntaxReceiver
}
// See if the class has our set properties attribute.
var attributes = cds.AttributeLists.AsEnumerable()
List<string>? attributes = cds.AttributeLists.AsEnumerable()
.SelectMany(x => x.Attributes)
.Select(x => x.Name.ToString())
.ToList();

View file

@ -88,7 +88,7 @@ public class SingletonComponentSourceGenerator
);
// Create the source text and write out the file.
var sourceText = SourceText.From(buffer.ToString(), Encoding.UTF8);
SourceText? sourceText = SourceText.From(buffer.ToString(), Encoding.UTF8);
context.AddSource(cls + ".Generated.cs", sourceText);
}
}

View file

@ -111,7 +111,7 @@ public class WithPropertiesSourceGenerator
buffer.AppendLine("}");
// Create the source text and write out the file.
var sourceText = SourceText.From(buffer.ToString(), Encoding.UTF8);
SourceText? sourceText = SourceText.From(buffer.ToString(), Encoding.UTF8);
context.AddSource(cds.Identifier + ".Generated.cs", sourceText);
}
}

View file

@ -66,7 +66,7 @@ public partial class ReadFiles : FileSystemOperationBase
// Read the files from the file system.
this.validator.ValidateAndThrow(this);
var glob = Glob.Parse(this.Pattern);
Glob? glob = Glob.Parse(this.Pattern);
IEnumerable<FileEntry> files = this.FileSystem.EnumerateFileEntries(
"/",

View file

@ -3,7 +3,6 @@ using MfGames.Gallium;
using MfGames.Nitride.Entities;
using MfGames.Nitride.Generators;
using Microsoft.Extensions.Logging;
using Serilog;
using Zio;
namespace MfGames.Nitride.IO.Paths;

View file

@ -37,7 +37,7 @@ public class StatusPipelineCommandLineOption : IPipelineCommandOption
return;
}
SpectreDisplayMode mode = value.GetEnumFuzzy<SpectreDisplayMode>("status display mode");
var mode = value.GetEnumFuzzy<SpectreDisplayMode>("status display mode");
this.observer.DisplayMode = mode;
}

View file

@ -30,7 +30,7 @@ public partial class IndexedPathRegexSchedule<TSchedule> : PathRegexScheduleBase
protected override Entity Apply(Entity entity, int number, TimeService timeService)
{
// Figure out the entry in the index.
var applicableKeys = this.Indexes.Keys.Where(a => a <= number).ToList();
List<int>? applicableKeys = this.Indexes.Keys.Where(a => a <= number).ToList();
if (applicableKeys.Count == 0)
{

View file

@ -53,16 +53,17 @@ public partial class IndexedSchedule
// If the time hasn't past, then we don't apply it.
Instant now = timeService.Clock.GetCurrentInstant();
bool isFuture = instant > now;
return instant > now ? entity : this.Apply(entity, number, instant);
return this.Apply(entity, number, instant, isFuture);
}
/// <summary>
/// Applies the schedule to the entity based on the number and instant
/// given.
/// </summary>
protected virtual Entity Apply(Entity entity, int number, Instant instant)
protected virtual Entity Apply(Entity entity, int number, Instant instant, bool isFuture)
{
return entity.Set(instant);
return !isFuture ? entity.Set(instant) : entity;
}
}

View file

@ -65,7 +65,7 @@ public partial class CreateDateIndexes : OperationBase, IResolvingOperation
// Go through the inputs and group each one. We also use `ToList` to force the enumeration to completely
// resolve and we can get everything we need. We will append the created indexes to the end of this list.
var output = input
List<Entity>? output = input
.SelectEntity<Instant>(
(entity, instant) => this.GroupOnFormats(instant, entries, entity)
)
@ -87,9 +87,9 @@ public partial class CreateDateIndexes : OperationBase, IResolvingOperation
// Get all the entities at this level and split them into ones we've seen (at a lower level) and which
// ones are new (these always go on the index).
var seenEntities = pair.Value.Where(a => seen.Contains(a)).ToList();
List<Entity>? seenEntities = pair.Value.Where(a => seen.Contains(a)).ToList();
var newEntities = pair.Value.Where(a => !seen.Contains(a)).ToList();
List<Entity>? newEntities = pair.Value.Where(a => !seen.Contains(a)).ToList();
seen.AddRange(newEntities);

View file

@ -44,7 +44,7 @@ public class DatePipelineCommandOption : IPipelineCommandOption
{
// We have a date, so we need to create a fake clock that has this
// date for the entire run.
var local = LocalDateTime.FromDateTime(value.Value);
LocalDateTime local = LocalDateTime.FromDateTime(value.Value);
ZonedDateTime zoned = local.InZoneStrictly(this.timeService.DateTimeZone);
var instant = zoned.ToInstant();

View file

@ -46,8 +46,8 @@ public static class NitrideTemporalBuilderExtensions
{
x.Register(context =>
{
ILogger logger = context.Resolve<ILogger>();
TimeService clock = context.Resolve<TimeService>();
var logger = context.Resolve<ILogger>();
var clock = context.Resolve<TimeService>();
return new ExpiresPipelineCommandOption(logger, clock, config.Expiration);
})
@ -60,8 +60,8 @@ public static class NitrideTemporalBuilderExtensions
builder.ConfigureSite(
(_, scope) =>
{
ILogger logger = scope.Resolve<ILogger>();
TimeService timeService = scope.Resolve<TimeService>();
var logger = scope.Resolve<ILogger>();
var timeService = scope.Resolve<TimeService>();
timeService.DateTimeZone = config.DateTimeZone;
logger.Verbose("Setting time zone to {Zone:l}", timeService.DateTimeZone);

View file

@ -89,7 +89,7 @@ public class TimeService
/// <returns>An instant representing this DateTimeOffset.</returns>
public Instant CreateInstant(DateTimeOffset when)
{
var offset = OffsetDateTime.FromDateTimeOffset(when);
OffsetDateTime offset = OffsetDateTime.FromDateTimeOffset(when);
return offset.ToInstant();
}
@ -103,7 +103,7 @@ public class TimeService
{
if (when.Kind == DateTimeKind.Unspecified)
{
var localDate = LocalDate.FromDateTime(when);
LocalDate localDate = LocalDate.FromDateTime(when);
return this.CreateInstant(localDate);
}

View file

@ -137,7 +137,7 @@ public class ConfigToolService
}
string json = file.ReadAllText();
TType result = JsonConvert.DeserializeObject<TType>(json)!;
var result = JsonConvert.DeserializeObject<TType>(json)!;
return result;
}

View file

@ -14,7 +14,7 @@ public static class ParseResultExtensions
return new List<string>();
}
var values = optionValues
List<string>? values = optionValues
.Split(',')
.Select(x => x.Trim())
.SelectMany(x => x.Split(' '))

View file

@ -42,7 +42,7 @@ public static class StringCliExtensions
public static Result<string> GetFuzzy(this string value, ICollection<string> possible)
{
// Look for a direct match.
var found = possible
List<string>? found = possible
.Where(x => string.Equals(x, value, StringComparison.InvariantCultureIgnoreCase))
.ToList();
@ -107,7 +107,7 @@ public static class StringCliExtensions
}
// Attempt a fuzzy search.
var possible = Enum.GetNames(typeof(TEnum))
List<string>? possible = Enum.GetNames(typeof(TEnum))
.Select(e => e.ToLower())
.Where(e => e.StartsWith(input.ToLower()))
.ToList();

View file

@ -127,7 +127,7 @@ public class LoggingToolService
nameof(LogContextFormat.Class)
);
LogContextFormat format = level.GetEnumFuzzy<LogContextFormat>("log context format");
var format = level.GetEnumFuzzy<LogContextFormat>("log context format");
return format;
}
@ -140,7 +140,7 @@ public class LoggingToolService
"Warning"
);
LogEventLevel logLevel = level.GetEnumFuzzy<LogEventLevel>("log level");
var logLevel = level.GetEnumFuzzy<LogEventLevel>("log level");
return logLevel;
}

View file

@ -25,7 +25,7 @@ public class AddPathPrefixTest : NitrideIOTestBase
fileSystem.CreateFile("/c1.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
AddPathPrefix op = context.Resolve<AddPathPrefix>().WithPathPrefix("/prefix");

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using MfGames.Gallium;
using MfGames.Nitride.IO.Contents;
using MfGames.Nitride.IO.Paths;
using MfGames.Nitride.Tests;
@ -36,11 +37,13 @@ public class DirectChildPathScannerTests : NitrideIOTestBase
fileSystem.CreateFile("/a/d/e/index.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
DirectChildPathScanner op = context.Resolve<DirectChildPathScanner>();
var readFiles = context.Resolve<ReadFiles>();
var op = context.Resolve<DirectChildPathScanner>();
// Read and replace the paths.
var _ = NitrideOperationExtensions.Run(readFiles.WithPattern("/**").Run(), op).ToList();
List<Entity>? _ = NitrideOperationExtensions
.Run(readFiles.WithPattern("/**").Run(), op)
.ToList();
KeyValuePair<string, string[]>[] actual = op.GetScannedResults()
.ToDictionary(x => x.Key, x => x.Value.Select(y => y.Get<UPath>().ToString()).ToArray())

View file

@ -27,7 +27,7 @@ public class GetEntityByPathTests : NitrideIOTestBase
fileSystem.CreateFile("/c1.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
// Read and replace the paths.
IOrderedEnumerable<string> output = NitrideIOEnumerableEntityExtensions
@ -55,7 +55,7 @@ public class GetEntityByPathTests : NitrideIOTestBase
fileSystem.CreateFile("/c1.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
// Read and replace the paths.
IOrderedEnumerable<string> output = NitrideIOEnumerableEntityExtensions
@ -88,7 +88,7 @@ public class GetEntityByPathTests : NitrideIOTestBase
fileSystem.CreateFile("/c1.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
// Read and replace the paths.
IOrderedEnumerable<string> output = NitrideIOEnumerableEntityExtensions

View file

@ -37,8 +37,8 @@ public class LinkDirectChildrenTests : NitrideIOTestBase
fileSystem.CreateFile("/a/d/e/index.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
DirectChildPathScanner scanner = context.Resolve<DirectChildPathScanner>();
var readFiles = context.Resolve<ReadFiles>();
var scanner = context.Resolve<DirectChildPathScanner>();
CreateOrUpdateIndex op = context.Resolve<LinkDirectChildren>().WithScanner(scanner);

View file

@ -21,8 +21,8 @@ public class MoveToIndexPathsTest : NitrideIOTestBase
CreateFileSystem(context);
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
MoveToIndexPath op = context.Resolve<MoveToIndexPath>();
var readFiles = context.Resolve<ReadFiles>();
var op = context.Resolve<MoveToIndexPath>();
// Read and replace the paths.
IOrderedEnumerable<string> output = NitrideOperationExtensions
@ -43,7 +43,7 @@ public class MoveToIndexPathsTest : NitrideIOTestBase
CreateFileSystem(context);
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
MoveToIndexPath op = context
.Resolve<MoveToIndexPath>()

View file

@ -27,7 +27,7 @@ public class RemovePathPrefixTest : NitrideIOTestBase
fileSystem.CreateFile("/a/a/c1.md");
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
RemovePathPrefix op = context.Resolve<RemovePathPrefix>().WithPathPrefix("/a");

View file

@ -33,7 +33,7 @@ public class WhereNotIgnoredTests : NitrideIOTestBase
var ignore = new IgnoreList(new[] { "*.txt" });
// Set up the operation.
ReadFiles readFiles = context.Resolve<ReadFiles>();
var readFiles = context.Resolve<ReadFiles>();
// Read and replace the paths.
IOrderedEnumerable<string> output = NitrideIOEnumerableEntityExtensions

View file

@ -23,7 +23,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
List<Entity> input =
new() { new Entity().Set(IsMarkdown.Instance).SetTextContent("- [Empty](link)"), };
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
@ -40,30 +40,13 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("- [Empty](link) space"),
};
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty space](link)", content);
}
[Fact]
public void ExtendSingleMarkdownLinkStar()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("* [Empty](link) space"),
};
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("* [Empty space](link)", content);
}
[Fact]
public void ExtendSingleMarkdownLinkSpaces()
{
@ -75,13 +58,30 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("- [Empty](link) space"),
};
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("- [Empty space](link)", content);
}
[Fact]
public void ExtendSingleMarkdownLinkStar()
{
using MarkdownTestContext context = this.CreateContext();
List<Entity> input =
new()
{
new Entity().Set(IsMarkdown.Instance).SetTextContent("* [Empty](link) space"),
};
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
Assert.Equal("* [Empty space](link)", content);
}
[Fact]
public void NoLinksNoChange()
{
@ -89,7 +89,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
List<Entity> input =
new() { new Entity().Set(IsMarkdown.Instance).SetTextContent("- Empty"), };
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();
@ -108,7 +108,7 @@ public class MakeSingleLinkListItemsTests : TestBase<MarkdownTestContext>
.Set(IsMarkdown.Instance)
.SetTextContent("- [Empty](link) [space](link2)"),
};
MakeSingleLinkListItems? op = context.Resolve<MakeSingleLinkListItems>();
var op = context.Resolve<MakeSingleLinkListItems>();
IEnumerable<Entity> output = op.Run(input);
string content = output.First().GetTextContentString()!.Trim();

View file

@ -237,10 +237,16 @@ public class IndexedPathRegexScheduleTest : TemporalSchedulesTestBase
public string? Access { get; set; }
/// <inheritdoc />
protected override Entity Apply(Entity entity, int number, Instant instant)
protected override Entity Apply(Entity entity, int number, Instant instant, bool isFuture)
{
if (isFuture)
{
return entity;
}
TestModel model = entity.Get<TestModel>();
model.Access = this.Access;
return entity.SetAll(instant, model);
}
}

View file

@ -14,7 +14,7 @@ public class TextContentYamlTests : NitrideTestBase
public void NoTextContent()
{
Entity entity = new();
TestContent? output = entity.GetTextContentYaml<TestContent>();
var output = entity.GetTextContentYaml<TestContent>();
Assert.Null(output);
}
@ -23,7 +23,7 @@ public class TextContentYamlTests : NitrideTestBase
public void SetAndGetContent()
{
Entity entity = new Entity().SetTextContentYaml(new TestContent { Value = "t1" });
TestContent? output = entity.GetTextContentYaml<TestContent>();
var output = entity.GetTextContentYaml<TestContent>();
Assert.NotNull(output);
Assert.Equal("t1", output.Value);
@ -35,7 +35,7 @@ public class TextContentYamlTests : NitrideTestBase
Entity entity = new Entity()
.SetTextContentYaml(new TestContent { Value = "t1" })
.SetTextContentYaml<TestContent>(null);
TestContent? output = entity.GetTextContentYaml<TestContent>();
var output = entity.GetTextContentYaml<TestContent>();
Assert.Null(output);
}