|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using RimMind.Application.Common.Interfaces.Extension; |
| 4 | +using RimMind.Application.Features.Bridges; |
4 | 5 |
|
5 | 6 | namespace RimMind.Bridge.RimTalk.Bridge |
6 | 7 | { |
7 | 8 | internal sealed class BridgeModuleCoordinator |
8 | 9 | { |
9 | | - private readonly IReadOnlyList<IBridgeModule> _modules; |
10 | | - private readonly Func<bool> _isDependencyActive; |
11 | | - private readonly Action<string> _log; |
12 | | - private readonly Action<string> _warn; |
| 10 | + private readonly ExternalModBridgeCoordinator _inner; |
13 | 11 |
|
14 | 12 | public BridgeModuleCoordinator( |
15 | 13 | IReadOnlyList<IBridgeModule> modules, |
16 | 14 | Func<bool> isDependencyActive, |
17 | 15 | Action<string> log, |
18 | 16 | Action<string> warn) |
19 | 17 | { |
20 | | - _modules = modules ?? throw new ArgumentNullException(nameof(modules)); |
21 | | - _isDependencyActive = isDependencyActive |
22 | | - ?? throw new ArgumentNullException(nameof(isDependencyActive)); |
23 | | - _log = log ?? throw new ArgumentNullException(nameof(log)); |
24 | | - _warn = warn ?? throw new ArgumentNullException(nameof(warn)); |
| 18 | + if (modules == null) throw new ArgumentNullException(nameof(modules)); |
| 19 | + if (isDependencyActive == null) throw new ArgumentNullException(nameof(isDependencyActive)); |
| 20 | + if (log == null) throw new ArgumentNullException(nameof(log)); |
| 21 | + if (warn == null) throw new ArgumentNullException(nameof(warn)); |
| 22 | + |
| 23 | + _inner = new ExternalModBridgeCoordinator( |
| 24 | + isDependencyActive, |
| 25 | + modules, |
| 26 | + gates: null, |
| 27 | + logInfo: log, |
| 28 | + logWarn: warn, |
| 29 | + inactiveMessage: "RimTalk not active, bridge modules skipped."); |
25 | 30 | } |
26 | 31 |
|
27 | | - public void RegisterAll() |
28 | | - { |
29 | | - if (!_isDependencyActive()) |
30 | | - { |
31 | | - _log("RimTalk not active, bridge modules skipped."); |
32 | | - return; |
33 | | - } |
| 32 | + public bool AreAllRegistered => _inner.AreAllRegistered; |
34 | 33 |
|
35 | | - foreach (IBridgeModule module in _modules) |
36 | | - { |
37 | | - try |
38 | | - { |
39 | | - module.Register(); |
40 | | - _log($"{module.Id} registered={module.IsRegistered}."); |
41 | | - } |
42 | | - catch (Exception ex) |
43 | | - { |
44 | | - _warn($"{module.Id} registration failed: {ex.Message}"); |
45 | | - } |
46 | | - } |
47 | | - } |
| 34 | + public void RegisterAll() => _inner.RegisterAll(); |
48 | 35 |
|
49 | | - public void UnregisterAll() |
50 | | - { |
51 | | - foreach (IBridgeModule module in _modules) |
52 | | - { |
53 | | - try |
54 | | - { |
55 | | - module.Unregister(); |
56 | | - } |
57 | | - catch (Exception ex) |
58 | | - { |
59 | | - _warn($"{module.Id} cleanup failed: {ex.Message}"); |
60 | | - } |
61 | | - } |
62 | | - } |
| 36 | + public void UnregisterAll() => _inner.UnregisterAll(); |
| 37 | + |
| 38 | + public void Refresh() => _inner.Refresh(); |
63 | 39 | } |
64 | 40 | } |
0 commit comments