使用CAB中EventBroker碰到困难,暂记于此!
近日在使用企业库中的CAB的EventBroker对LightweightCTI进行改造时碰到了一个另人预想不到的问题,我在其中一个Module中发布的事件通过其它的Module中出现无法接受此事件的情况。
事件发布的代码如下:

事件发布代码段
1
Channel Common Events#region Channel Common Events
2
3
[EventPublication(SwitchEventNames.ChannelStatusChangedEvent, PublicationScope.Global)]
4
public event EventHandler<EventArgs<ChannelStatus>> ChannelStatusChanged;
5
protected virtual void OnChannelStatusChanged(object sender, EventArgs<ChannelStatus> e)
6
{
7
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ChannelStatusChanged))
8
{
9
RunScripts(ChannelEventHandlerName.ChannelStatusChanged);
10
}
11
else
12
if (this.ChannelStatusChanged != null)
13
{
14
this.ChannelStatusChanged(sender, e);
15
}
16
}
17
18
[EventPublication(SwitchEventNames.GetDTMFEvent, PublicationScope.Global)]
19
public event EventHandler<EventArgs<string>> GetDTMF;
20
protected virtual void OnGetDTMF(object sender, EventArgs<string> e)
21
{
22
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.GetDTMF))
23
{
24
RunScripts(ChannelEventHandlerName.GetDTMF);
25
}
26
else
27
if (this.GetDTMF != null)
28
{
29
this.GetDTMF(sender, e);
30
}
31
}
32
33
[EventPublication(SwitchEventNames.CallEvent, PublicationScope.Global)]
34
public event EventHandler<CallEventArgs> Call;
35
protected virtual void OnCall(object sender, CallEventArgs e)
36
{
37
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Call))
38
{
39
RunScripts(ChannelEventHandlerName.Call);
40
}
41
else
42
if (this.Call != null)
43
{
44
this.Call(sender, e);
45
}
46
}
47
48
[EventPublication(SwitchEventNames.FaxingEvent, PublicationScope.Global)]
49
public event EventHandler<FaxEventArgs> Faxing;
50
protected virtual void OnFaxing(object sender, FaxEventArgs e)
51
{
52
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Faxing))
53
{
54
RunScripts(ChannelEventHandlerName.Faxing);
55
}
56
else
57
if (this.Faxing != null)
58
this.Faxing(sender, e);
59
}
60
61
[EventPublication(SwitchEventNames.LinkingToChannelEvent, PublicationScope.Global)]
62
public event EventHandler<LinkingToChannelEventArgs> LinkingToChannel;
63
protected virtual void OnLinkingToChannel(object sender, LinkingToChannelEventArgs e)
64
{
65
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkingToChannel))
66
{
67
RunScripts(ChannelEventHandlerName.LinkingToChannel);
68
}
69
else
70
if (this.LinkingToChannel != null)
71
{
72
this.LinkingToChannel(sender, e);
73
}
74
}
75
76
[EventPublication(SwitchEventNames.LinkedToChannelEvent, PublicationScope.Global)]
77
public event EventHandler<EventArgs<IChannel>> LinkedToChannel;
78
protected virtual void OnLinkedToChannel(object sender, EventArgs<IChannel> e)
79
{
80
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkedToChannel))
81
{
82
RunScripts(ChannelEventHandlerName.LinkedToChannel);
83
}
84
else
85
if (this.LinkedToChannel != null)
86
{
87
this.LinkedToChannel(sender, e);
88
}
89
}
90
91
[EventPublication(SwitchEventNames.ResetedChannelEvent, PublicationScope.Global)]
92
public event EventHandler ResetedChannel;
93
protected virtual void OnResetedChannel(object sender, EventArgs e)
94
{
95
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ResetedChannel))
96
{
97
RunScripts(ChannelEventHandlerName.ResetedChannel);
98
}
99
else
100
if (this.ResetedChannel != null)
101
{
102
this.ResetedChannel(sender, e);
103
}
104
}
105
106
[EventPublication(SwitchEventNames.ProcessTimeoutEvent, PublicationScope.Global)]
107
public event EventHandler ProcessTimeout;
108
protected virtual void OnProcessTimeout(object sender, EventArgs e)
109
{
110
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ProcessTimeout))
111
{
112
RunScripts(ChannelEventHandlerName.ProcessTimeout);
113
}
114
else
115
if (this.ProcessTimeout != null)
116
{
117
this.ProcessTimeout(sender, e);
118
}
119
}
120
121
#endregion 在另外一个Module中的一个SmartPart View进行事件订阅的代码段如下:

事件订阅代码
1
[EventSubscription(SwitchEventNames.ChannelStatusChangedEvent, ThreadOption.UserInterface)]
2
public void ChannelStatusChangedHandler(object sender, EventArgs<ChannelStatus> e)
3
{
4
IChannel chnl = (IChannel)sender;
5
ChannelsView.Items[chnl.ChannelID].SubItems[1].Text = Enum.GetName(typeof(ChannelStatus), e.Data);
6
}
7
其中,事件发布的对象是由类工厂进行创建的,类工厂的事件却可以成功订阅。几经查询终无所获,希望对MS企业库熟悉的朋友帮忙看一下,是否我在进行事件发布与订阅时有什么地方还没有需要注意一下,在此先行谢过各位啦。
事件发布的代码如下:
1

Channel Common Events#region Channel Common Events2

3
[EventPublication(SwitchEventNames.ChannelStatusChangedEvent, PublicationScope.Global)]4
public event EventHandler<EventArgs<ChannelStatus>> ChannelStatusChanged;5
protected virtual void OnChannelStatusChanged(object sender, EventArgs<ChannelStatus> e)6

{7
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ChannelStatusChanged))8

{9
RunScripts(ChannelEventHandlerName.ChannelStatusChanged);10
}11
else12
if (this.ChannelStatusChanged != null)13

{14
this.ChannelStatusChanged(sender, e);15
}16
}17

18
[EventPublication(SwitchEventNames.GetDTMFEvent, PublicationScope.Global)]19
public event EventHandler<EventArgs<string>> GetDTMF;20
protected virtual void OnGetDTMF(object sender, EventArgs<string> e)21

{22
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.GetDTMF))23

{24
RunScripts(ChannelEventHandlerName.GetDTMF);25
}26
else27
if (this.GetDTMF != null)28

{29
this.GetDTMF(sender, e);30
}31
}32

33
[EventPublication(SwitchEventNames.CallEvent, PublicationScope.Global)]34
public event EventHandler<CallEventArgs> Call;35
protected virtual void OnCall(object sender, CallEventArgs e)36

{37
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Call))38

{39
RunScripts(ChannelEventHandlerName.Call); 40
}41
else42
if (this.Call != null)43

{44
this.Call(sender, e);45
}46
}47

48
[EventPublication(SwitchEventNames.FaxingEvent, PublicationScope.Global)]49
public event EventHandler<FaxEventArgs> Faxing;50
protected virtual void OnFaxing(object sender, FaxEventArgs e)51

{52
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Faxing))53

{54
RunScripts(ChannelEventHandlerName.Faxing);55
}56
else57
if (this.Faxing != null)58
this.Faxing(sender, e);59
}60

61
[EventPublication(SwitchEventNames.LinkingToChannelEvent, PublicationScope.Global)]62
public event EventHandler<LinkingToChannelEventArgs> LinkingToChannel;63
protected virtual void OnLinkingToChannel(object sender, LinkingToChannelEventArgs e)64

{65
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkingToChannel))66

{67
RunScripts(ChannelEventHandlerName.LinkingToChannel);68
}69
else70
if (this.LinkingToChannel != null)71

{72
this.LinkingToChannel(sender, e);73
}74
}75

76
[EventPublication(SwitchEventNames.LinkedToChannelEvent, PublicationScope.Global)]77
public event EventHandler<EventArgs<IChannel>> LinkedToChannel;78
protected virtual void OnLinkedToChannel(object sender, EventArgs<IChannel> e)79

{80
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkedToChannel))81

{82
RunScripts(ChannelEventHandlerName.LinkedToChannel);83
}84
else85
if (this.LinkedToChannel != null)86

{87
this.LinkedToChannel(sender, e);88
}89
}90

91
[EventPublication(SwitchEventNames.ResetedChannelEvent, PublicationScope.Global)]92
public event EventHandler ResetedChannel;93
protected virtual void OnResetedChannel(object sender, EventArgs e)94

{95
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ResetedChannel))96

{97
RunScripts(ChannelEventHandlerName.ResetedChannel);98
}99
else100
if (this.ResetedChannel != null)101

{102
this.ResetedChannel(sender, e);103
}104
}105

106
[EventPublication(SwitchEventNames.ProcessTimeoutEvent, PublicationScope.Global)]107
public event EventHandler ProcessTimeout;108
protected virtual void OnProcessTimeout(object sender, EventArgs e)109

{110
if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ProcessTimeout))111

{112
RunScripts(ChannelEventHandlerName.ProcessTimeout);113
}114
else115
if (this.ProcessTimeout != null)116

{117
this.ProcessTimeout(sender, e);118
}119
}120

121
#endregion 1
[EventSubscription(SwitchEventNames.ChannelStatusChangedEvent, ThreadOption.UserInterface)]2
public void ChannelStatusChangedHandler(object sender, EventArgs<ChannelStatus> e)3

{4
IChannel chnl = (IChannel)sender;5
ChannelsView.Items[chnl.ChannelID].SubItems[1].Text = Enum.GetName(typeof(ChannelStatus), e.Data);6
}7

浙公网安备 33010602011771号