-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
100 lines (90 loc) · 3.72 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Cli.Template.Generator.Commands;
using Cli.Template.Generator.ConfigFiles;
using Cli.Template.Generator.Handler;
using Cli.Template.Generator.Model;
using Cli.Template.Generator.SqlStatement;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace Cli.Template.Generator
{
public static class Program
{
private static IConfigurationRoot? _configuration;
private static GenerateSqlStatements? SqlStatementsConfig { get; } = new GenerateSqlStatements();
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(Serilog.Events.LogEventLevel.Debug)
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.CreateLogger();
ServiceCollection serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
ConfigurateSqlStatements();
var generator = new Generator();
var sqlStatement= CreateSqlStatement(0);
var createCommand1 = new CreateSqlStatementsCommand<KompetenzUntergruppe>(sqlStatement)
{
Activate = true
};
sqlStatement = CreateSqlStatement(1);
var createCommand2 = new CreateSqlStatementsCommand<Kompetenz>(sqlStatement)
{
Activate = true
};
generator.SetCommand(createCommand1);
generator.SetCommand(createCommand2);
generator.ExecuteCommands();
}
private static SqlInsertStatement CreateSqlStatement(int sqlStatementConfigIndex)
{
var sqlStatementConfig = SqlStatementsConfig!.SqlStatements[sqlStatementConfigIndex];
var sqlStatement = new SqlInsertStatement
{
TableName = sqlStatementConfig.TableName,
SourceFullFilePath = sqlStatementConfig.SourceFullFilePath,
DatabaseName = SqlStatementsConfig.DatabaseName
};
sqlStatement.SetPlaceHolders(sqlStatementConfig.PlaceHolders);
sqlStatement.SetFileHandler(new SqlFileHandler(sqlStatementConfig.TargetFullFilePath));
return sqlStatement;
}
private static void ConfigurateSqlStatements()
{
if (_configuration == null)
{
return;
}
_configuration.GetSection("GenerateSQLStatements").Bind(SqlStatementsConfig);
SqlStatementsConfig!.SqlStatements = _configuration.GetSection("GenerateSQLStatements:SqlStatements").Get<List<GenerateSqlStatement>>();
}
private static void ConfigureServices(IServiceCollection services)
{
// Add logging
services.AddSingleton(LoggerFactory.Create(builder =>
{
builder
.AddSerilog(dispose: true);
}));
// configure logging
services.AddLogging(builder =>
{
builder.AddConsole();
builder.AddDebug();
});
// Build configuration
_configuration = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location))
.AddJsonFile("appsettings.json", true, true)
.AddEnvironmentVariables()
.Build();
// Add access to generic IConfigurationRoot
services.AddSingleton(_configuration);
}
}
}