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
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.Commands;
|
|
|
|
using MfGames.Nitride.Temporal.Cli;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2023-01-16 19:45:59 +00:00
|
|
|
namespace MfGames.Nitride.Temporal.Setup;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
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:40:31 +00:00
|
|
|
public static NitrideBuilder UseTemporal(
|
|
|
|
this NitrideBuilder builder,
|
|
|
|
Action<NitrideTemporalConfiguration>? configure = null)
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-07 02:40:31 +00:00
|
|
|
// Get the configuration so we can set the various options.
|
|
|
|
var config = new NitrideTemporalConfiguration();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
configure?.Invoke(config);
|
2022-06-07 02:03:02 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
// Add in the module registration.
|
|
|
|
builder.ConfigureContainer(
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
// Register the module.
|
|
|
|
x.RegisterModule<NitrideTemporalModule>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2022-06-07 02:40:31 +00:00
|
|
|
// Add in the CLI options.
|
|
|
|
if (config.AddDateOptionToCommandLine)
|
2022-06-05 18:44:51 +00:00
|
|
|
{
|
2022-07-09 04:52:10 +00:00
|
|
|
x.RegisterType<DatePipelineCommandOption>()
|
|
|
|
.As<IPipelineCommandOption>();
|
2022-06-07 02:40:31 +00:00
|
|
|
}
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2023-01-15 00:19:42 +00:00
|
|
|
if (config.AddExpireOptionToCommandLine
|
|
|
|
&& config.Expiration != null)
|
2022-06-07 02:40:31 +00:00
|
|
|
{
|
|
|
|
x.Register(
|
|
|
|
context =>
|
|
|
|
{
|
|
|
|
ILogger logger = context.Resolve<ILogger>();
|
2023-01-21 07:52:52 +00:00
|
|
|
TimeService
|
|
|
|
clock = context.Resolve<TimeService>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2023-01-15 00:19:42 +00:00
|
|
|
return new ExpiresPipelineCommandOption(
|
|
|
|
logger,
|
|
|
|
clock,
|
|
|
|
config.Expiration);
|
2022-06-07 02:40:31 +00:00
|
|
|
})
|
|
|
|
.As<IPipelineCommandOption>();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-07 13:55:13 +00:00
|
|
|
if (config.DateTimeZone != null)
|
|
|
|
{
|
|
|
|
builder.ConfigureSite(
|
2022-07-09 04:52:10 +00:00
|
|
|
(
|
|
|
|
_,
|
|
|
|
scope) =>
|
2022-06-07 13:55:13 +00:00
|
|
|
{
|
2022-06-07 14:40:31 +00:00
|
|
|
ILogger logger = scope.Resolve<ILogger>();
|
2023-01-21 07:52:52 +00:00
|
|
|
TimeService timeService = scope.Resolve<TimeService>();
|
2021-09-07 05:15:45 +00:00
|
|
|
|
2023-01-21 07:52:52 +00:00
|
|
|
timeService.DateTimeZone = config.DateTimeZone;
|
2023-01-15 00:19:42 +00:00
|
|
|
logger.Verbose(
|
|
|
|
"Setting time zone to {Zone:l}",
|
2023-01-21 07:52:52 +00:00
|
|
|
timeService.DateTimeZone);
|
2022-06-07 13:55:13 +00:00
|
|
|
});
|
|
|
|
}
|
2022-06-07 02:40:31 +00:00
|
|
|
|
|
|
|
return builder;
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|