-
Notifications
You must be signed in to change notification settings - Fork 1
/
SchemaPropertyMap.cs
100 lines (83 loc) · 3.08 KB
/
SchemaPropertyMap.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
namespace Circles.Index.Common;
public class CompositeDatabaseSchema : IDatabaseSchema
{
public ISchemaPropertyMap SchemaPropertyMap { get; }
public IEventDtoTableMap EventDtoTableMap { get; }
public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; }
public CompositeDatabaseSchema(IDatabaseSchema[] components)
{
Tables = components
.SelectMany(c => c.Tables)
.ToDictionary(
kvp => kvp.Key
, kvp => kvp.Value
);
SchemaPropertyMap = new CompositeSchemaPropertyMap(components.Select(o => o.SchemaPropertyMap).ToArray());
EventDtoTableMap = new CompositeEventDtoTableMap(components.Select(o => o.EventDtoTableMap).ToArray());
}
}
public interface ISchemaPropertyMap
{
Dictionary<(string Namespace, string Table), Dictionary<string, Func<object, object?>>> Map { get; }
public void Add<TEvent>((string Namespace, string Table) table, Dictionary<string, Func<TEvent, object?>> map);
}
public class SchemaPropertyMap : ISchemaPropertyMap
{
public Dictionary<(string Namespace, string Table), Dictionary<string, Func<object, object?>>> Map { get; } = new();
public void Add<TEvent>((string Namespace, string Table) table, Dictionary<string, Func<TEvent, object?>> map)
{
Map[table] = map.ToDictionary(
pair => pair.Key,
pair => new Func<object, object?>(eventArg => pair.Value((TEvent)eventArg))
);
}
}
public class CompositeSchemaPropertyMap : ISchemaPropertyMap
{
public Dictionary<(string Namespace, string Table), Dictionary<string, Func<object, object?>>> Map { get; }
public void Add<TEvent>((string Namespace, string Table) table, Dictionary<string, Func<TEvent, object?>> map)
{
throw new NotImplementedException();
}
public CompositeSchemaPropertyMap(ISchemaPropertyMap[] components)
{
Map = components
.SelectMany(c => c.Map)
.ToDictionary(
kvp => kvp.Key
, kvp => kvp.Value
);
}
}
public interface IEventDtoTableMap
{
Dictionary<Type, (string Namespace, string Table)> Map { get; }
public void Add<TEvent>((string Namespace, string Table) table)
where TEvent : IIndexEvent;
}
public class EventDtoTableMap : IEventDtoTableMap
{
public Dictionary<Type, (string Namespace, string Table)> Map { get; } = new();
public void Add<TEvent>((string Namespace, string Table) table)
where TEvent : IIndexEvent
{
Map[typeof(TEvent)] = table;
}
}
public class CompositeEventDtoTableMap : IEventDtoTableMap
{
public Dictionary<Type, (string Namespace, string Table)> Map { get; }
public void Add<TEvent>((string Namespace, string Table) table) where TEvent : IIndexEvent
{
throw new NotImplementedException();
}
public CompositeEventDtoTableMap(IEventDtoTableMap[] components)
{
Map = components
.SelectMany(c => c.Map)
.ToDictionary(
kvp => kvp.Key
, kvp => kvp.Value
);
}
}