Skip to content

Commit 5319298

Browse files
committed
🚧 pass eventName to callback
1 parent 52dab38 commit 5319298

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Console/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
var api = new EliteDangerousApi();
55
api.OnJournalEvent(e =>
66
{
7-
var eventName = JsonUtils.GetEventName(e);
8-
var paths = JsonUtils.FlattenJson(e).Select(p => p.WithPath($"EliteAPI.{eventName}.{p.Path}")).ToList();
7+
var paths = JsonUtils.FlattenJson(e.json).Select(p => p.WithPath($"EliteAPI.{e.eventName}.{p.Path}")).ToList();
8+
99
foreach (var path in paths)
10-
{
1110
Console.WriteLine($"{path.Path}: {path.Value} ({path.Type})");
12-
}
11+
12+
Console.WriteLine($"((EliteAPI.{e.eventName}))");
1313
});
1414

1515
Thread.Sleep(-1);

EliteAPI/EliteDangerousApi.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ public EliteDangerousApi()
1515
_journalWatcher = LineByLineFileWatcher.Create(journalDirectory, "Journal.*.log").watcher;
1616
}
1717

18-
public void OnJournalEvent(Action<string> onEvent) => _journalWatcher.OnChange(onEvent);
18+
public void OnJournalEvent(Action<(string eventName, string json)> onEvent)
19+
{
20+
_journalWatcher.OnChange(json =>
21+
{
22+
var eventName = JsonUtils.GetEventName(json);
23+
onEvent((eventName, json));
24+
});
25+
}
1926
}

0 commit comments

Comments
 (0)