PiwigoDirectorySync/PiwigoDirectorySync/Program.cs
Philipp Häfelfinger d1290f73c1
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
adds updateDb command
2023-09-10 22:57:42 +02:00

65 lines
2.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PiwigoDirectorySync;
using PiwigoDirectorySync.Commands;
using PiwigoDirectorySync.Infrastructure;
using PiwigoDirectorySync.Persistence;
using PiwigoDirectorySync.Services;
using Spectre.Console.Cli;
var registrations = new ServiceCollection();
registrations.AddSingleton(AppSettings.Config);
registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging"))
.AddSimpleConsole(c =>
{
c.SingleLine = true;
c.IncludeScopes = true;
})
.AddDebug());
registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>();
registrations.AddTransient<IFileIndexer, FileIndexer>();
registrations.AddTransient<IFileSystemScanner, FileSystemScanner>();
registrations.AddTransient<IAlbumSynchronizer, AlbumSynchronizer>();
registrations.AddTransient<IImageSynchronizer, ImageSynchronizer>();
registrations.AddDbContext<PersistenceContext>(options =>
{
_ = AppSettings.Settings.DbProvider switch
{
"Sqlite" => options.UseSqlite(AppSettings.ConnectionString),
"InMemory" => options.UseInMemoryDatabase(AppSettings.ConnectionString),
_ => throw new Exception($"Unsupported dbType: {AppSettings.Settings.DbProvider}")
};
});
var registrar = new DependencyInjectionTypeRegistrar(registrations);
var app = new CommandApp(registrar);
app.Configure(config =>
{
#if DEBUG
config.PropagateExceptions();
config.ValidateExamples();
#endif
config.AddCommand<ScanCommand>("scan");
config.AddCommand<DownloadImagesCommand>("download");
config.AddBranch("sync", c =>
{
c.AddCommand<SyncFullCommand>("full");
c.AddCommand<SyncAlbumsCommand>("albums");
c.AddCommand<SyncImagesCommand>("images");
});
config.AddBranch("piwigo", c =>
{
c.AddCommand<PiwigoListCommand>("list");
c.AddCommand<PiwigoAddCommand>("add");
c.AddCommand<PiwigoUpdateCommand>("update");
c.AddCommand<PiwigoRemoveCommand>("remove");
});
config.AddCommand<UpdateDatabaseCommand>("updateDb");
});
return await app.RunAsync(args);