-
Notifications
You must be signed in to change notification settings - Fork 4
/
TableGroupPlugin.cs
42 lines (34 loc) · 1.17 KB
/
TableGroupPlugin.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
using KustoSchemaTools.Helpers;
using KustoSchemaTools.Model;
using KustoSchemaTools.Plugins;
namespace KustoSchemaCLI.Plugins
{
public class TableGroupPlugin : IYamlSchemaPlugin
{
public TableGroupPlugin(string subFolder = "table_groups")
{
SubFolder = subFolder;
}
public string SubFolder { get; }
public async Task OnLoad(Database existingDatabase, string basePath)
{
var dict = existingDatabase.Tables;
var path = Path.Combine(basePath, SubFolder);
if (Directory.Exists(path) == false) return;
var files = Directory.GetFiles(path, "*.yml");
foreach (var filePath in files)
{
var tgFile = await File.ReadAllTextAsync(filePath);
var tg = Serialization.YamlPascalCaseDeserializer.Deserialize<TableGroup>(tgFile);
foreach (var entity in tg.AppliesTo)
{
dict.Merge(tg.Table, entity);
}
}
}
public Task OnWrite(Database existingDatabase, string path)
{
return Task.CompletedTask;
}
}
}