I18NCommander/I18N Commander/UI WinForms/Program.cs
Thorsten Sommer 0587af18f2
Added Git Export Feature
- Added import algorithm
- Added FromJsonX() methods to data models
- Added possibility to work with temp. database file
- Added export processor to handle export process & triggers
- Added something changed event e.g. as export trigger
- Added possibility to import a JSON export
- Updated Git icon
2023-01-22 19:35:57 +01:00

84 lines
2.6 KiB
C#

using System.Text.Json;
using DataModel;
using DataModel.Database.Common;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Processor;
using static UI_WinForms.Components.LoaderStart.LoaderAction;
namespace UI_WinForms;
internal static class Program
{
internal static IServiceProvider? SERVICE_PROVIDER;
internal static bool RestartMainApp = false;
[STAThread]
private static void Main()
{
ApplicationConfiguration.Initialize();
Application.EnableVisualStyles();
// Start the loader screen:
var loader = new Loader();
Application.Run(loader);
// Check, if the user closes the loader screen:
if (loader.DialogResult != DialogResult.OK)
return;
//
// Create the DI system
//
var builder = new HostBuilder();
//
// Add services
//
builder.ConfigureServices((hostContext, serviceCollection) =>
{
if(loader.Result.Action is LOAD_PROJECT or CREATE_NEW_PROJECT)
serviceCollection.AddDatabase(loader.Result.DataFile, true);
else if(loader.Result.Action is IMPORT_JSON)
{
try
{
serviceCollection.ImportDataAndAddDatabase(loader.Result.DataFile).ConfigureAwait(false);
}
catch (JsonException)
{
MessageBox.Show($"The JSON file '{loader.Result.DataFile}' is invalid and cannot be imported.", "Invalid JSON file", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(100);
}
}
});
// Tear down the setup:
using var setupMaintenance = Setup.Maintenance;
// Get the host out of the DI system:
var host = builder.Build();
// Create a service scope:
using (var scope = host.Services.CreateScope())
{
// Get a service provider:
SERVICE_PROVIDER = scope.ServiceProvider;
// Set the service provider to the processor:
ProcessorMeta.ServiceProvider = SERVICE_PROVIDER;
// Apply database migrations:
using (var database = SERVICE_PROVIDER.GetRequiredService<DataContext>())
Setup.PerformDataMigration(database).Wait();
// Start the app:
do
{
Application.Run(new Main());
} while (Program.RestartMainApp);
}
}
}