使用CAB中EventBroker碰到困难,暂记于此!

  近日在使用企业库中的CAB的EventBroker对 LightweightCTI进行改造时碰到了一个另人预想不到的问题,我在其中一个Module中发布的事件通过其它的Module中出现无法接受此事件的情况。
  事件发布的代码如下:
ContractedBlock.gif ExpandedBlockStart.gif 事件发布代码段
  1ContractedBlock.gifExpandedBlockStart.gif        Channel Common Events#region Channel Common Events
  2InBlock.gif
  3InBlock.gif        [EventPublication(SwitchEventNames.ChannelStatusChangedEvent, PublicationScope.Global)]
  4InBlock.gif        public event EventHandler<EventArgs<ChannelStatus>> ChannelStatusChanged;
  5InBlock.gif        protected virtual void OnChannelStatusChanged(object sender, EventArgs<ChannelStatus> e)
  6ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
  7InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ChannelStatusChanged))
  8ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
  9InBlock.gif                RunScripts(ChannelEventHandlerName.ChannelStatusChanged);
 10ExpandedSubBlockEnd.gif            }

 11InBlock.gif            else
 12InBlock.gif                if (this.ChannelStatusChanged != null)
 13ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 14InBlock.gif                    this.ChannelStatusChanged(sender, e);
 15ExpandedSubBlockEnd.gif                }

 16ExpandedSubBlockEnd.gif        }

 17InBlock.gif
 18InBlock.gif        [EventPublication(SwitchEventNames.GetDTMFEvent, PublicationScope.Global)]
 19InBlock.gif        public event EventHandler<EventArgs<string>> GetDTMF;
 20InBlock.gif        protected virtual void OnGetDTMF(object sender, EventArgs<string> e)
 21ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 22InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.GetDTMF))
 23ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 24InBlock.gif                RunScripts(ChannelEventHandlerName.GetDTMF);
 25ExpandedSubBlockEnd.gif            }

 26InBlock.gif            else
 27InBlock.gif                if (this.GetDTMF != null)
 28ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 29InBlock.gif                    this.GetDTMF(sender, e);
 30ExpandedSubBlockEnd.gif                }

 31ExpandedSubBlockEnd.gif        }

 32InBlock.gif
 33InBlock.gif        [EventPublication(SwitchEventNames.CallEvent, PublicationScope.Global)]
 34InBlock.gif        public event EventHandler<CallEventArgs> Call;
 35InBlock.gif        protected virtual void OnCall(object sender, CallEventArgs e)
 36ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 37InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Call))
 38ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 39InBlock.gif                RunScripts(ChannelEventHandlerName.Call); 
 40ExpandedSubBlockEnd.gif            }

 41InBlock.gif            else
 42InBlock.gif                if (this.Call != null)
 43ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 44InBlock.gif                    this.Call(sender, e);
 45ExpandedSubBlockEnd.gif                }

 46ExpandedSubBlockEnd.gif        }

 47InBlock.gif
 48InBlock.gif        [EventPublication(SwitchEventNames.FaxingEvent, PublicationScope.Global)]
 49InBlock.gif        public event EventHandler<FaxEventArgs> Faxing;
 50InBlock.gif        protected virtual void OnFaxing(object sender, FaxEventArgs e)
 51ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 52InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.Faxing))
 53ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 54InBlock.gif                RunScripts(ChannelEventHandlerName.Faxing);
 55ExpandedSubBlockEnd.gif            }

 56InBlock.gif            else
 57InBlock.gif                if (this.Faxing != null)
 58InBlock.gif                    this.Faxing(sender, e);
 59ExpandedSubBlockEnd.gif        }

 60InBlock.gif
 61InBlock.gif        [EventPublication(SwitchEventNames.LinkingToChannelEvent, PublicationScope.Global)]
 62InBlock.gif        public event EventHandler<LinkingToChannelEventArgs> LinkingToChannel;
 63InBlock.gif        protected virtual void OnLinkingToChannel(object sender, LinkingToChannelEventArgs e)
 64ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 65InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkingToChannel))
 66ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 67InBlock.gif                RunScripts(ChannelEventHandlerName.LinkingToChannel);
 68ExpandedSubBlockEnd.gif            }

 69InBlock.gif            else
 70InBlock.gif                if (this.LinkingToChannel != null)
 71ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 72InBlock.gif                    this.LinkingToChannel(sender, e);
 73ExpandedSubBlockEnd.gif                }

 74ExpandedSubBlockEnd.gif        }

 75InBlock.gif
 76InBlock.gif        [EventPublication(SwitchEventNames.LinkedToChannelEvent, PublicationScope.Global)]
 77InBlock.gif        public event EventHandler<EventArgs<IChannel>> LinkedToChannel;
 78InBlock.gif        protected virtual void OnLinkedToChannel(object sender, EventArgs<IChannel> e)
 79ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 80InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.LinkedToChannel))
 81ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 82InBlock.gif                RunScripts(ChannelEventHandlerName.LinkedToChannel);
 83ExpandedSubBlockEnd.gif            }

 84InBlock.gif            else
 85InBlock.gif                if (this.LinkedToChannel != null)
 86ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 87InBlock.gif                    this.LinkedToChannel(sender, e);
 88ExpandedSubBlockEnd.gif                }

 89ExpandedSubBlockEnd.gif        }

 90InBlock.gif
 91InBlock.gif        [EventPublication(SwitchEventNames.ResetedChannelEvent, PublicationScope.Global)]
 92InBlock.gif        public event EventHandler ResetedChannel;
 93InBlock.gif        protected virtual void OnResetedChannel(object sender, EventArgs e)
 94ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 95InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ResetedChannel))
 96ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 97InBlock.gif                RunScripts(ChannelEventHandlerName.ResetedChannel);
 98ExpandedSubBlockEnd.gif            }

 99InBlock.gif            else
100InBlock.gif                if (this.ResetedChannel != null)
101ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
102InBlock.gif                    this.ResetedChannel(sender, e);
103ExpandedSubBlockEnd.gif                }

104ExpandedSubBlockEnd.gif        }

105InBlock.gif
106InBlock.gif        [EventPublication(SwitchEventNames.ProcessTimeoutEvent, PublicationScope.Global)]
107InBlock.gif        public event EventHandler ProcessTimeout;
108InBlock.gif        protected virtual void OnProcessTimeout(object sender, EventArgs e)
109ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
110InBlock.gif            if (scriptLoaders.ContainsKey(ChannelEventHandlerName.ProcessTimeout))
111ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
112InBlock.gif                RunScripts(ChannelEventHandlerName.ProcessTimeout);
113ExpandedSubBlockEnd.gif            }

114InBlock.gif            else
115InBlock.gif                if (this.ProcessTimeout != null)
116ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
117InBlock.gif                    this.ProcessTimeout(sender, e);
118ExpandedSubBlockEnd.gif                }

119ExpandedSubBlockEnd.gif        }

120InBlock.gif
121ExpandedBlockEnd.gif        #endregion
 
  在另外一个Module中的一个SmartPart View进行事件订阅的代码段如下:
ContractedBlock.gif ExpandedBlockStart.gif 事件订阅代码
1None.gif        [EventSubscription(SwitchEventNames.ChannelStatusChangedEvent, ThreadOption.UserInterface)]
2None.gif        public void ChannelStatusChangedHandler(object sender, EventArgs<ChannelStatus> e)
3ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
4InBlock.gif            IChannel chnl = (IChannel)sender;
5InBlock.gif            ChannelsView.Items[chnl.ChannelID].SubItems[1].Text = Enum.GetName(typeof(ChannelStatus), e.Data);
6ExpandedBlockEnd.gif        }

7None.gif
  其中,事件发布的对象是由类工厂进行创建的,类工厂的事件却可以成功订阅。几经查询终无所获,希望对MS企业库熟悉的朋友帮忙看一下,是否我在进行事件发布与订阅时有什么地方还没有需要注意一下,在此先行谢过各位啦。

转载于:https://www.cnblogs.com/JackyXu/archive/2007/06/13/781253.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值