80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System;
|
|
|
|
using Autofac;
|
|
|
|
using MfGames.Nitride.Commands;
|
|
using MfGames.Nitride.Temporal.Cli;
|
|
|
|
using Serilog;
|
|
|
|
namespace MfGames.Nitride.Temporal.Setup;
|
|
|
|
public static class NitrideTemporalBuilderExtensions
|
|
{
|
|
/// <summary>
|
|
/// Extends the builder to allow for configuring the temporal
|
|
/// settings for generation.
|
|
/// </summary>
|
|
public static NitrideBuilder UseTemporal(
|
|
this NitrideBuilder builder,
|
|
Action<NitrideTemporalConfiguration>? configure = null)
|
|
{
|
|
// Get the configuration so we can set the various options.
|
|
var config = new NitrideTemporalConfiguration();
|
|
|
|
configure?.Invoke(config);
|
|
|
|
// Add in the module registration.
|
|
builder.ConfigureContainer(
|
|
x =>
|
|
{
|
|
// Register the module.
|
|
x.RegisterModule<NitrideTemporalModule>();
|
|
|
|
// Add in the CLI options.
|
|
if (config.AddDateOptionToCommandLine)
|
|
{
|
|
x.RegisterType<DatePipelineCommandOption>()
|
|
.As<IPipelineCommandOption>();
|
|
}
|
|
|
|
if (config.AddExpireOptionToCommandLine
|
|
&& config.Expiration != null)
|
|
{
|
|
x.Register(
|
|
context =>
|
|
{
|
|
ILogger logger = context.Resolve<ILogger>();
|
|
TimeService
|
|
clock = context.Resolve<TimeService>();
|
|
|
|
return new ExpiresPipelineCommandOption(
|
|
logger,
|
|
clock,
|
|
config.Expiration);
|
|
})
|
|
.As<IPipelineCommandOption>();
|
|
}
|
|
});
|
|
|
|
if (config.DateTimeZone != null)
|
|
{
|
|
builder.ConfigureSite(
|
|
(
|
|
_,
|
|
scope) =>
|
|
{
|
|
ILogger logger = scope.Resolve<ILogger>();
|
|
TimeService timeService = scope.Resolve<TimeService>();
|
|
|
|
timeService.DateTimeZone = config.DateTimeZone;
|
|
logger.Verbose(
|
|
"Setting time zone to {Zone:l}",
|
|
timeService.DateTimeZone);
|
|
});
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
}
|