@@ -11,14 +11,6 @@ namespace SciSharp.MySQL.Replication
11
11
*/
12
12
class LogEventPackageDecoder : IPackageDecoder < LogEvent >
13
13
{
14
- class DefaultLogEventFactory < TLogEvent > : ILogEventFactory
15
- where TLogEvent : LogEvent , new ( )
16
- {
17
- public LogEvent Create ( )
18
- {
19
- return new TLogEvent ( ) ;
20
- }
21
- }
22
14
23
15
private static readonly DateTime _unixEpoch = new DateTime ( 1970 , 1 , 1 ) ;
24
16
@@ -28,11 +20,11 @@ internal static DateTime GetTimestapmFromUnixEpoch(int seconds)
28
20
}
29
21
30
22
private static Dictionary < LogEventType , ILogEventFactory > _logEventFactories = new Dictionary < LogEventType , ILogEventFactory > ( ) ;
31
-
23
+ private static ILogEventFactory _notImplementedEventFactory = new DefaultEventFactory < NotImplementedEvent > ( ) ;
32
24
internal static void RegisterLogEventType < TLogEvent > ( LogEventType eventType )
33
25
where TLogEvent : LogEvent , new ( )
34
26
{
35
- RegisterLogEventType ( eventType , new DefaultLogEventFactory < TLogEvent > ( ) ) ;
27
+ RegisterLogEventType ( eventType , new DefaultEventFactory < TLogEvent > ( ) ) ;
36
28
}
37
29
38
30
internal static void RegisterLogEventType ( LogEventType eventType , ILogEventFactory factory )
@@ -44,16 +36,18 @@ internal static void RegisterEmptyPayloadEventTypes(params LogEventType[] eventT
44
36
{
45
37
foreach ( var eventType in eventTypes )
46
38
{
47
- _logEventFactories . Add ( eventType , new EmptyPayloadEventFactory ( eventType ) ) ;
39
+ _logEventFactories . Add ( eventType , new DefaultEventFactory < EmptyPayloadEvent > ( ) ) ;
48
40
}
49
41
}
50
42
51
43
protected virtual LogEvent CreateLogEvent ( LogEventType eventType )
52
44
{
53
45
if ( ! _logEventFactories . TryGetValue ( eventType , out var factory ) )
54
- throw new Exception ( "Unexpected eventType: " + eventType ) ;
46
+ factory = _notImplementedEventFactory ;
55
47
56
- return factory . Create ( ) ;
48
+ var log = factory . Create ( ) ;
49
+ log . EventType = eventType ;
50
+ return log ;
57
51
}
58
52
59
53
public LogEvent Decode ( ReadOnlySequence < byte > buffer )
0 commit comments