Example #1
0
 /// <summary>
 /// 添加监听器
 /// </summary>
 /// <param name="listener"></param>
 public void AddListener(MessageListener listener)
 {
     lock (_syncLock)
     {
         if (_listeners.Contains(listener))
         {
             throw new InvalidOperationException("Listeners have already registered.");
         }
         else
         {
             _listeners.Add(listener);
         }
     }
 }
 /// <summary>
 /// 添加监听器
 /// </summary>
 /// <param name="listener"></param>
 public void AddListener(MessageListener listener)
 {
     lock (_syncLock)
     {
         if (_listeners.Contains(listener))
         {
             throw new InvalidOperationException("Listeners have already registered.");
         }
         else
         {
             _listeners.Add(listener);
         }
     }
 }
Example #3
0
 /// <summary>
 /// 移除监听器
 /// </summary>
 /// <param name="listener"></param>
 public void RemoveListener(MessageListener listener)
 {
     lock (_syncLock)
     {
         if (_listeners.Contains(listener))
         {
             this._listeners.Remove(listener);
         }
         else
         {
             throw new InvalidOperationException("Listeners don't exist.");
         }
     }
 }
Example #4
0
        public override bool Equals(object obj)
        {
            bool eq = base.Equals(obj);

            if (!eq)
            {
                MessageListener lstn         = obj as MessageListener;
                var             endPoint     = lstn._endPoint as IPEndPoint;
                var             currEndPoint = this._endPoint as IPEndPoint;

                if (endPoint.Address.Equals(currEndPoint.Address) &&
                    endPoint.Port == currEndPoint.Port)
                {
                    eq = true;
                }
            }
            return(eq);
        }
 /// <summary>
 /// 移除监听器
 /// </summary>
 /// <param name="listener"></param>
 public void RemoveListener(MessageListener listener)
 {
     lock (_syncLock)
     {
         if (_listeners.Contains(listener))
         {
             this._listeners.Remove(listener);
         }
         else
         {
             throw new InvalidOperationException("Listeners don't exist.");
         }
     }
 }