Example #1
0
        void Reply(ChatEventArgs e)
        {
            lock (LockObject)
            {
                switch (e.ChatType)
                {
                case ChatType.Logon:
                    if (!_DictChat.ContainsKey(e.UserName))
                    {
                        this._UserName = e.UserName;
                        foreach (var child in _DictChat)
                        {
                            child.Value.ReplyLogon(e.UserName);
                        }
                        _DictChat.Add(e.UserName, _ReplyClient);
                        _ReplyClient.CurrentUsers(_DictChat.Keys.ToList <String>());
                    }
                    break;

                case ChatType.Leave:
                    foreach (var child in _DictChat)
                    {
                        child.Value.ReplyLeave(e.UserName);
                    }
                    if (_DictChat.ContainsKey(e.UserName))
                    {
                        _DictChat.Remove(e.UserName);
                    }
                    try
                    {
                        _ReplyClient = null;
                        OperationContext.Current.Channel.Abort();
                        OperationContext.Current.Channel.Close();
                    }
                    catch { }
                    break;

                case ChatType.Say:
                    foreach (var child in _DictChat)
                    {
                        child.Value.ReplySay(e.UserName, e.Msg);
                    }
                    break;

                case ChatType.Whisper:
                    if (_DictChat.ContainsKey(e.UserName))
                    {
                        _DictChat[e.UserName].ReplyWhisper(e.Msg, this._UserName);
                    }
                    break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// 登录
 /// </summary>
 /// <param name="user"></param>
 public void Logon(string user)
 {
     if (user.IsNullOrEmpty())
     {
         return;
     }
     if (null == _ReplyClient)
     {
         _ReplyClient = OperationContext.Current.GetCallbackChannel <IClientChatCallback>();
         OperationContext.Current.Channel.Faulted -= Channel_Faulted;
         OperationContext.Current.Channel.Closed  -= Channel_Closed;
         OperationContext.Current.Channel.Faulted += Channel_Faulted;
         OperationContext.Current.Channel.Closed  += Channel_Closed;
         var e = new ChatEventArgs(ChatType.Logon, null, user);
         Reply(e);
     }
 }
Example #3
0
        /// <summary>
        /// 聊天
        /// </summary>
        /// <param name="msg"></param>
        public void Say(string msg)
        {
            var e = new ChatEventArgs(ChatType.Say, msg, this._UserName);

            Reply(e);
        }
Example #4
0
        /// <summary>
        /// 私聊
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="toUser"></param>
        public void Whisper(string msg, string toUser)
        {
            var e = new ChatEventArgs(ChatType.Whisper, msg, toUser);

            Reply(e);
        }
Example #5
0
        /// <summary>
        /// 离开
        /// </summary>
        /// <param name="user"></param>
        public void Leave(string user)
        {
            var e = new ChatEventArgs(ChatType.Leave, string.Format("{0}离开聊天", user), user);

            Reply(e);
        }