Jonathan Jenne 3675e83102 push
2023-12-06 11:58:15 +01:00

72 lines
2.5 KiB
C#

using DigitalData.Modules.Logging;
using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using Quartz;
namespace EnvelopeGenerator.Web
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add base services
builder.Services.AddSingleton<LoggingService>();
builder.Services.AddTransient<DatabaseService>();
// Add higher order services
builder.Services.AddSingleton<EnvelopeService>();
// Add services to the container.
builder.Services.AddControllersWithViews().AddJsonOptions(q =>
{
// Prevents serialization error when serializing SvgBitmap in EnvelopeReceiver
q.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
});
// Configure and start scheduler
builder.Services.AddQuartz(q =>
{
Scheduler scheduler = InitScheduler(builder);
scheduler.ScheduleJob<Common.Jobs.CertificateDocumentJob>(q, "CertificateDocument", 5);
});
builder.Services.AddQuartzHostedService();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
private static LogConfig InitLogger(WebApplicationBuilder builder)
{
string logPath = builder.Configuration.GetValue<string>("Config:LogPath");
return new LogConfig(LogConfig.PathType.CustomPath, logPath, "Scheduler", "Digital Data", "ECM.EnvelopeGenerator.Web");
}
private static Scheduler InitScheduler( WebApplicationBuilder builder)
{
LogConfig logConfig = InitLogger(builder);
string connectionString = builder.Configuration.GetValue<string>("Config:ConnectionString");
Scheduler scheduler = new(logConfig, connectionString);
return scheduler;
}
}
}