Пример #1
0
        public override bool  Equals(object obj)
        {
            CommunicationUser user = obj as CommunicationUser;

            if (user != null)
            {
                return(this.ToString().Equals(user.ToString()));
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="userFrom"></param>
        /// <param name="userTo"></param>
        public void SendMessage(string message, CommunicationUser userFrom, CommunicationUser userTo)
        {
            //给指定的用户发送消息
            ChatEventArgs e = new ChatEventArgs();

            e.MessageType = MessageType.UserLeave;
            e.User        = userTo;
            e.Message     = userFrom.UserName + ": " + message;

            //循环将在线的用户广播信息
            var users = (m_CurrentOnLineUsers.Where((pair) => { return(pair.ToString() == userTo.ToString()); })).ToList();

            users.ForEach((pair) =>
            {
                pair.Value.GetInvocationList().ToList().ForEach((handler) =>
                {
                    ((CommunicationEventHandler)handler).BeginInvoke(this, e, null, null);
                });
            });
        }