57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
|
|
// See https://aka.ms/new-console-template for more information
|
|||
|
|
|
|||
|
|
using System.Text.Json;
|
|||
|
|
using Catalogger.Backend;
|
|||
|
|
using Catalogger.Backend.Database;
|
|||
|
|
using Catalogger.Backend.Extensions;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using NodaTime;
|
|||
|
|
using NodaTime.Serialization.SystemTextJson;
|
|||
|
|
using NodaTime.Text;
|
|||
|
|
using Serilog;
|
|||
|
|
using Serilog.Events;
|
|||
|
|
using Serilog.Sinks.SystemConsole.Themes;
|
|||
|
|
|
|||
|
|
namespace Catalogger.GoImporter;
|
|||
|
|
|
|||
|
|
internal class Program
|
|||
|
|
{
|
|||
|
|
public static JsonSerializerOptions JsonOptions =
|
|||
|
|
new JsonSerializerOptions().ConfigureForNodaTime(
|
|||
|
|
new NodaJsonSettings
|
|||
|
|
{
|
|||
|
|
InstantConverter = new NodaPatternConverter<Instant>(InstantPattern.ExtendedIso),
|
|||
|
|
}
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
public static async Task Main(string[] args)
|
|||
|
|
{
|
|||
|
|
Log.Logger = new LoggerConfiguration()
|
|||
|
|
.Enrich.FromLogContext()
|
|||
|
|
.MinimumLevel.Debug()
|
|||
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|||
|
|
.WriteTo.Console(theme: AnsiConsoleTheme.Sixteen)
|
|||
|
|
.CreateLogger();
|
|||
|
|
|
|||
|
|
var config = new ConfigurationBuilder().AddConfiguration().Build().Get<Config>();
|
|||
|
|
if (config == null)
|
|||
|
|
{
|
|||
|
|
Log.Fatal("No configuration object was created");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var db = new DatabaseContext(config, null);
|
|||
|
|
await db.Database.MigrateAsync();
|
|||
|
|
|
|||
|
|
var type = args[0].ToLowerInvariant();
|
|||
|
|
var file = args[1];
|
|||
|
|
|
|||
|
|
if (type == "guilds")
|
|||
|
|
{
|
|||
|
|
Log.Information("Importing guilds from {File}", file);
|
|||
|
|
await GuildImport.DoImportAsync(db, file);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|