2021-09-07 05:15:45 +00:00
|
|
|
using System;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Autofac;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Nitride.Commands;
|
2022-06-05 18:44:51 +00:00
|
|
|
using Nitride.Temporal.Cli;
|
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
using Expires = Nitride.Temporal.Cli.ExpiresPipelineCommandOption;
|
|
|
|
|
|
|
|
namespace Nitride.Temporal;
|
|
|
|
|
|
|
|
public static class NitrideTemporalBuilderExtensions
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Extends the builder to allow for configuring the temporal
|
|
|
|
/// settings for generation.
|
|
|
|
/// </summary>
|
2022-06-07 02:03:02 +00:00
|
|
|
public static NitrideBuilder UseTemporal(this NitrideBuilder builder, Action<Timekeeper>? configure = null)
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-07 02:03:02 +00:00
|
|
|
builder.ConfigureContainer(x => x.RegisterModule<NitrideTemporalModule>());
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:03:02 +00:00
|
|
|
if (configure != null)
|
|
|
|
{
|
|
|
|
builder.ConfigureSite((_, scope) => configure(scope.Resolve<Timekeeper>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder;
|
2022-06-05 18:44:51 +00:00
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds the "--date=XXXX-XX-XX" option into the pipeline commands.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="builder">The host builder being configured.</param>
|
|
|
|
/// <returns>The builder passed in.</returns>
|
|
|
|
public static NitrideBuilder WithClockFromOptions(this NitrideBuilder builder)
|
|
|
|
{
|
|
|
|
return builder.UseTemporal()
|
|
|
|
.ConfigureContainer(
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
x.RegisterType<DatePipelineCommandOption>().As<IPipelineCommandOption>();
|
|
|
|
});
|
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds the "--expire=XXXX" option into the pipeline commands where
|
|
|
|
/// "XXX" is a format like "5y" or "500000:00:00.0". This is parsed by
|
|
|
|
/// TimeSpanParser which gives an easy format.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="builder">The host builder being configured.</param>
|
|
|
|
/// <param name="defaultValue">The default expiration, if one is provided.</param>
|
|
|
|
/// <returns>The builder passed in.</returns>
|
|
|
|
public static NitrideBuilder WithExpiresFromOptions(this NitrideBuilder builder, TimeSpan defaultValue)
|
|
|
|
{
|
|
|
|
return WithExpiresFromOptions(builder, defaultValue.ToString());
|
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds the "--expire=XXXX" option into the pipeline commands where
|
|
|
|
/// "XXX" is a format like "5y" or "500000:00:00.0". This is parsed by
|
|
|
|
/// TimeSpanParser which gives an easy format.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="builder">The host builder being configured.</param>
|
|
|
|
/// <param name="defaultValue">The default expiration, if one is provided.</param>
|
|
|
|
/// <returns>The builder passed in.</returns>
|
|
|
|
public static NitrideBuilder WithExpiresFromOptions(this NitrideBuilder builder, string? defaultValue = null)
|
|
|
|
{
|
|
|
|
return builder.ConfigureContainer(
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
x.Register(
|
|
|
|
context =>
|
|
|
|
{
|
|
|
|
ILogger? logger = context.Resolve<ILogger>();
|
|
|
|
Timekeeper? clock = context.Resolve<Timekeeper>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
return new Expires(logger, clock, defaultValue);
|
|
|
|
})
|
|
|
|
.As<IPipelineCommandOption>();
|
|
|
|
});
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|