-
Notifications
You must be signed in to change notification settings - Fork 1
/
ActionEventHandler.cs
81 lines (73 loc) · 2.09 KB
/
ActionEventHandler.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
using ServiceAnt.Subscription.Handler;
using System;
using System.Threading.Tasks;
namespace ServiceAnt.Handler.Subscription.Handler
{
/// <summary>
/// Handle event by action
/// </summary>
/// <typeparam name="TEvent"></typeparam>
public class ActionEventHandler<TEvent> : IEventHandler<TEvent> where TEvent : ITrigger
{
private Func<TEvent, Task> _action;
/// <summary>
/// ctor
/// </summary>
/// <param name="action"></param>
public ActionEventHandler(Func<TEvent, Task> action)
{
_action = action;
}
/// <summary>
/// handle event
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public async Task HandleAsync(TEvent param)
{
await _action(param);
}
/// <summary>
/// check if input action is same with self
/// </summary>
/// <param name="compareAction"></param>
/// <returns></returns>
public bool IsSame(Func<TEvent, Task> compareAction)
{
return compareAction == _action;
}
}
/// <summary>
/// Handle event by dynamic action
/// </summary>
public class ActionEventHandler : IDynamicEventHandler
{
private Func<dynamic, Task> _action;
/// <summary>
/// ctor
/// </summary>
/// <param name="action"></param>
public ActionEventHandler(Func<dynamic, Task> action)
{
_action = action;
}
/// <summary>
/// handle event
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public async Task HandleAsync(dynamic param)
{
await _action(param);
}
/// <summary>
/// check if input action is same with self
/// </summary>
/// <param name="compareAction"></param>
/// <returns></returns>
public bool IsSame(Func<dynamic, Task> compareAction)
{
return compareAction == _action;
}
}
}