Exemplo n.º 1
0
        private void UnSubscribeInternal <TEventArgs>(ContractInfo contract, ChannelConnectionEventType eventType, EventHandler <TEventArgs> callback)
            where TEventArgs : EventArgs
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            switch (eventType)
            {
            case ChannelConnectionEventType.Connected:
                List <EventHandler <ChannelConnectedEventArgs> > connectedListeners;
                if (_channelConnectedEventSubscribers.TryGetValue(contract.Key, out connectedListeners))
                {
                    connectedListeners.Remove(callback as EventHandler <ChannelConnectedEventArgs>);
                }
                break;

            case ChannelConnectionEventType.Reconnected:
                List <EventHandler <ChannelConnectedEventArgs> > reconnectedListeners;
                if (_channelReconnectedEventSubscribers.TryGetValue(contract.Key, out reconnectedListeners))
                {
                    reconnectedListeners.Remove(callback as EventHandler <ChannelConnectedEventArgs>);
                }
                break;

            case ChannelConnectionEventType.Disconnected:
                List <EventHandler <ChannelDisconnectedEventArgs> > disconnectedListeners;
                if (_channelDisconnectedEventSubscribers.TryGetValue(contract.Key, out disconnectedListeners))
                {
                    disconnectedListeners.Remove(callback as EventHandler <ChannelDisconnectedEventArgs>);
                }
                break;

            case ChannelConnectionEventType.ExceptionRaised:
                List <EventHandler <ChannelExceptionRaisedEventArgs> > exceptionRaisedListeners;
                if (_channelExceptionRaisedEventSubscribers.TryGetValue(contract.Key, out exceptionRaisedListeners))
                {
                    exceptionRaisedListeners.Remove(callback as EventHandler <ChannelExceptionRaisedEventArgs>);
                }
                break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 取消订阅通道连接状态事件
 /// </summary>
 /// <typeparam name="TContract">需要订阅的服务契约</typeparam>
 /// <typeparam name="TEventArgs">订阅通道状态参数类型</typeparam>
 /// <param name="eventType">通道状态类型</param>
 /// <param name="callback">通道状态变化回调函数</param>
 public void Unsubscribe <TContract, TEventArgs>(ChannelConnectionEventType eventType, EventHandler <TEventArgs> callback)
     where TContract : class
     where TEventArgs : EventArgs
 {
     UnSubscribeInternal <TEventArgs>(new ContractInfo(typeof(TContract)), eventType, callback);
 }