Skip to content

Commit 4e58e14

Browse files
Merge branch 'issue_3145' of https://github.com/SolidProgramming/firewall-orchestrator into issue_2973
2 parents 67fab51 + bb7a116 commit 4e58e14

File tree

8 files changed

+17
-35
lines changed

8 files changed

+17
-35
lines changed

roles/lib/files/FWO.Services/EventMediator/EventMediator.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace FWO.Services.EventMediator;
66
public class EventMediator : IEventMediator
77
{
88
private readonly Dictionary<Type, List<Action<IEvent>>> _handlers = [];
9-
private readonly Dictionary<object, List<Action<IEvent>>> ObjectHandlers = [];
109

1110
public void Subscribe<TEvent>(Action<TEvent> handler) where TEvent : class, IEvent
1211
{
@@ -18,7 +17,7 @@ public void Subscribe<TEvent>(Action<TEvent> handler) where TEvent : class, IEve
1817
_handlers[typeof(TEvent)].Add(e => handler((TEvent)e));
1918
}
2019

21-
public void Publish<TEvent>(TEvent @event) where TEvent : class, IEvent
20+
public void Publish<TEvent>(TEvent @event) where TEvent : class, IEvent
2221
{
2322
if(_handlers.TryGetValue(typeof(TEvent), out List<Action<IEvent>>? handlers))
2423
{
@@ -29,28 +28,6 @@ public void Publish<TEvent>(TEvent @event) where TEvent : class, IEvent
2928
}
3029
}
3130

32-
public void Subscribe<TEvent>(object sender, Action<TEvent> handler) where TEvent : class, IEvent
33-
{
34-
if(!ObjectHandlers.TryGetValue(sender, out List<Action<IEvent>>? value))
35-
{
36-
value = [];
37-
ObjectHandlers[sender] = value;
38-
}
39-
40-
value.Add(e => handler((TEvent)e));
41-
}
42-
43-
public void Publish<TEvent>(object sender, TEvent @event) where TEvent : class, IEvent
44-
{
45-
if(ObjectHandlers.TryGetValue(sender, out List<Action<IEvent>>? handlers))
46-
{
47-
foreach(Action<IEvent> handler in handlers)
48-
{
49-
handler(@event);
50-
}
51-
}
52-
}
53-
5431
public void Unsubscribe<TEvent>(TEvent @event)
5532
{
5633

roles/lib/files/FWO.Services/EventMediator/Events/CollectionChangedEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace FWO.Services.EventMediator.Events;
44

5-
public class CollectionChangedEvent() : IEvent
5+
public class CollectionChangedEvent(CollectionChangedEventArgs? eventArgs = default) : IEvent
66
{
7-
7+
public IEventArgs? EventArgs { get; set; } = eventArgs;
88
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
namespace FWO.Services.EventMediator.Events;
1+
using FWO.Services.EventMediator.Interfaces;
22

3-
public class CollectionChangedEventArgs(object? Sender, IEnumerable<dynamic>? Collection) : EventArgs
4-
{
3+
namespace FWO.Services.EventMediator.Events;
54

5+
public class CollectionChangedEventArgs(IEnumerable<dynamic> collection) : IEventArgs
6+
{
7+
IEnumerable<dynamic> Collection { get; } = collection;
68
}
79

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
namespace FWO.Services.EventMediator.Interfaces;
22

3-
public interface IEvent{ }
3+
public interface IEvent
4+
{
5+
public IEventArgs? EventArgs { get; set; }
6+
}
47

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace FWO.Services.EventMediator.Interfaces;
2+
3+
public interface IEventArgs { }
4+

roles/lib/files/FWO.Services/EventMediator/Interfaces/IEventMediator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ public interface IEventMediator
44
{
55
void Subscribe<TEvent>(Action<TEvent> handler) where TEvent : class, IEvent;
66
void Publish<TEvent>(TEvent @event) where TEvent : class, IEvent;
7-
void Subscribe<TEvent>(object sender, Action<TEvent> handler) where TEvent : class, IEvent;
8-
void Publish<TEvent>(object sender, TEvent @event) where TEvent : class, IEvent;
97
}
108

roles/ui/files/FWO.UI/Pages/NetworkModelling/ManualAppServer.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@
112112
private bool workInProgress = false;
113113
private bool firstTry = true;
114114

115-
private readonly static CollectionChangedEvent OnCollectionChanged = new();
116-
117115
protected override void OnInitialized()
118116
{
119117
try

roles/ui/files/FWO.UI/Shared/OrderByDropdown.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
CssClass = "";
119119
}
120120

121-
EventMediator.Subscribe<CollectionChangedEvent>(this, new Action<CollectionChangedEvent>(_ => ReorderCollection()));
121+
EventMediator.Subscribe<CollectionChangedEvent>(new Action<CollectionChangedEvent>(_ => ReorderCollection()));
122122

123123
initialized = true;
124124
}

0 commit comments

Comments
 (0)