-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
62 lines (57 loc) · 1.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Mycenae.Models;
using Mycenae.Tasks;
using NLog;
using NLog.Extensions.Logging;
using System;
using Logger = NLog.Logger;
namespace Mycenae
{
public class Program
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static IServiceProvider _serviceProvider;
public static void Main()
{
try
{
Setup();
var migrationTask = GetMigrationTaskInstance();
migrationTask.Execute();
}
catch (Exception ex)
{
Logger.Error(ex);
}
finally
{
Logger.Info("Ending application...");
}
}
private static void Setup()
{
_serviceProvider = new ServiceCollection()
.AddTransient<Extraction>()
.AddTransient<Insertion>()
.AddTransient<EndToEnd>()
.AddLogging(builder =>
{
builder.ClearProviders();
builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
builder.AddNLog("NLog.config");
})
.BuildServiceProvider();
}
private static MigrationTask GetMigrationTaskInstance()
{
return Settings.Values.TaskToExecute switch
{
TaskToExecute.Extraction => _serviceProvider.GetRequiredService<Extraction>(),
TaskToExecute.Insertion => _serviceProvider.GetRequiredService<Insertion>(),
TaskToExecute.EndToEnd => _serviceProvider.GetRequiredService<EndToEnd>(),
_ => throw new ArgumentException($"Config {nameof(Settings.Values.TaskToExecute)} is not properly specified.")
};
}
}
}