Example #1
0
 protected override void MessageFilter(ChatParty party, ChatMessage msg)
 {
     if (party.UserType == UserType.Client && msg.Message.IndexOf("$$BROWSER$$") != -1)
     {
         msg.Message = string.Empty;
     }
     base.MessageFilter(party, msg);
 }
Example #2
0
        protected override void PartyLeftFilter(ChatMessage msg, ChatParty party)
        {
            // 转队列或转人时,接起的坐席端不提示上一坐席离开
            if (party != null)
            {
                msg.Message = string.Empty;
            }

            base.PartyLeftFilter(msg, party);
        }
Example #3
0
 /// <summary>
 /// 过滤消息
 /// </summary>
 /// <param name="party"></param>
 /// <param name="msg"></param>
 protected override void MessageFilter(ChatParty party, ChatMessage msg)
 {
     if (party.UserType == UserType.Agent && msg.Message.IndexOf("$$RTO$$") != -1)
     {
         msg.Message = string.Empty;
     }
     if (party.UserType == UserType.External)
     {
         msg.Message = string.Empty;
     }
     base.MessageFilter(party, msg);
 }
Example #4
0
        public static ChatParty InitCustomerInfo(string queryString)
        {
            // 初始化用户
            ChatParty customer = new ChatParty();

            if (string.IsNullOrEmpty(queryString))
            {
                return(customer);
            }
            customer.DisplayName           = "联想用户001";
            customer.ChatProtocol          = new BasicChatProtocol(new Endpoint("", "", 2020));
            customer.ChatProtocol.UserData = new KeyValueCollection();
            Dictionary <string, object> userData = JsonConvert.DeserializeObject(queryString, typeof(Dictionary <string, object>)) as Dictionary <string, object>;

            if (userData != null && userData.Keys.Count > 0)
            {
                string[] keys = new[] { "EnterID", "UserID", "UserName", "MachineNo", "TargetSkill", "emailClient"
                                        , "RegisterNumber", "Queue", "strServiceCardNo", "LAStatID", "WSISID", "CustomerIP", "CustomerLocation" };
                foreach (string key in keys)
                {
                    if (!userData.Keys.Contains(key))
                    {
                        continue;
                    }
                    string value = string.Empty;
                    if (userData[key] != null)
                    {
                        value = userData[key].ToString();
                    }
                    if (key.Equals("UserName"))
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            value = "联想用户";
                        }
                        customer.DisplayName = value;
                        value = Convert.ToBase64String(Encoding.UTF8.GetBytes(value));

                        customer.ChatProtocol.UserData["FirstName"] = value;
                        customer.ChatProtocol.UserData["LastName"]  = string.Empty;
                    }
                    customer.ChatProtocol.UserData.Add(key, value);
                }
            }
            return(customer);
        }
Example #5
0
        /// <summary>
        /// 实现基类方法
        /// </summary>
        public override void InitConnecton()
        {
            try
            {
                this.ChatServiceInfo = BalanceCache.GetInstance().GetServiceInfo();
                if (this.ChatServiceInfo == null)
                {
                    return;
                }

                ChatLog.GetInstance().FormatMessage("已分配到服务器。(别名:{0}   地址:{1}:{2})"
                                                    , this.ChatServiceInfo.Alias, this.ChatServiceInfo.Host, this.ChatServiceInfo.Port);

                Uri       chatRoomURI  = new Uri(string.Format("tcp://{0}:{1}", this.ChatServiceInfo.Host, this.ChatServiceInfo.Port));
                Endpoint  chatEndPoint = new Endpoint(chatRoomURI);
                ChatParty user         = new ChatParty();
                user.DisplayName  = this.Customer.DisplayName;
                user.ChatProtocol = new BasicChatProtocol(chatEndPoint);
                user.ChatProtocol.AutoRegister = true;
                user.ChatProtocol.UserType     = UserType.Client;
                user.ChatProtocol.UserNickname = this.Customer.DisplayName;
                if (this.Customer.ChatProtocol != null)
                {
                    user.ChatProtocol.UserData = this.Customer.ChatProtocol.UserData;
                }
                user.ChatProtocol.Error  += ChatProtocol_Error;
                user.ChatProtocol.Opened += ChatProtocol_Opened;
                user.ChatProtocol.Closed += ChatProtocol_Closed;
                // 打开聊天服务
                try
                {
                    string        logName = "testLog";
                    Log4NetLogger logger  = new Log4NetLogger(log, logName);
                    user.ThreadInvoker = new SingleThreadInvoker("EventReceivingBrokerService-1");
                    user.ThreadInvoker.EnableLogging(logger);
                    user.EventBroker = new EventReceivingBrokerService(user.ThreadInvoker);
                    user.EventBroker.EnableLogging(logger);
                    user.EventBroker.Register(this.ChatEventsHandler, new MessageFilter(user.ChatProtocol.ProtocolId));
                    user.ChatProtocol.SetReceiver(user.EventBroker);
                    user.ChatProtocol.EnableLogging(logger);
                    this.customer = user;
                    var isOpend = false;
                    lock (ChatLock.LOCK_OPEN)
                    {
                        try
                        {
                            user.ChatProtocol.Open(new TimeSpan(0, 0, 5));
                            isOpend = true;
                        }
                        catch (Exception ex)
                        {
                            ChatLog.GetInstance().LogException(ex);
                        }
                    }
                    if (!isOpend)
                    {
                        ChatLog.GetInstance().FormatMessage("Error03:无法连接消息服务器,方法:CustomerChatContext:InitConnecton,chatRoomURI:{0},用户昵称{1},用户UserID:{2}", chatRoomURI.ToString(), this.Customer.DisplayName, this.Customer.UserID);
                        throw new Exception("无法连接消息服务器,请稍候再试。");
                    }
                }
                catch
                {
                    if (user.EventBroker != null)
                    {
                        user.EventBroker.Unregister(this.ChatEventsHandler);
                    }
                    this.PartyDispose(user);
                }
            }
            catch (Exception ex)
            {
                ChatLog.GetInstance().LogException(ex);
            }
        }
 public CustomerChatContext(string sessionID, ChatParty customerInfo)
     : this(sessionID)
 {
     this.customer = customerInfo;
 }
        /// <summary>
        /// 实现基类方法
        /// </summary>
        public override void InitConnecton()
        {
            int ii = 0;

            while (!this.IsAvailableConnection && ii <= 3)
            {
                Trace.WriteLine(string.Format("正在尝试第{0}次连接……", ii + 1));
                try
                {
                    //this.ChatServiceInfo = LoadBalancer.GetServiceInfo(CfgAppType.CFGChatServer, "Resources");
                    //if (this.ChatServiceInfo == null) continue;

                    //Trace.WriteLine(string.Format("已分配到服务器。(别名:{0}   地址:{1}:{2})"
                    //    , this.ChatServiceInfo.Alias, this.ChatServiceInfo.Host, this.ChatServiceInfo.Port));

                    //Uri chatRoomURI = new Uri(string.Format("tcp://{0}:{1}", this.ChatServiceInfo.Host, this.ChatServiceInfo.Port));
                    Uri       chatRoomURI  = new Uri("tcp://10.99.36.115:4801");
                    Endpoint  chatEndPoint = new Endpoint(chatRoomURI);
                    ChatParty user         = new ChatParty();
                    user.DisplayName  = this.Customer.DisplayName;
                    user.ChatProtocol = new BasicChatProtocol(chatEndPoint);
                    user.ChatProtocol.AutoRegister = true;
                    user.ChatProtocol.UserType     = UserType.Client;
                    user.ChatProtocol.UserNickname = this.Customer.DisplayName;
                    if (this.Customer.ChatProtocol != null)
                    {
                        user.ChatProtocol.UserData = this.Customer.ChatProtocol.UserData;
                    }
                    // 打开聊天服务
                    try
                    {
                        string        logName = "testLog";
                        Log4NetLogger logger  = new Log4NetLogger(log, logName);
                        user.ThreadInvoker = new SingleThreadInvoker("EventReceivingBrokerService-1", logger);
                        user.ThreadInvoker.EnableLogging(logger);
                        user.EventBroker = new EventReceivingBrokerService(user.ThreadInvoker);
                        user.EventBroker.EnableLogging(logger);
                        user.EventBroker.Register(this.ChatEventsHandler, new MessageFilter(user.ChatProtocol.ProtocolId));
                        user.ChatProtocol.SetReceiver(user.EventBroker);

                        var isOpend = false;
                        lock (ChatLock.LOCK_OPEN)
                        {
                            try
                            {
                                user.ChatProtocol.Open();
                                isOpend = true;
                                System.Threading.Thread.Sleep(50);
                            }
                            catch { }
                        }
                        if (!isOpend)
                        {
                            throw new Exception("连接ChatServer异常,稍候重试。");
                        }

                        this.customer = user;

                        this.InitRoom();
                        this.Room.Partys.Add(this.customer);

                        // 日志
                        ChatLog.GetInstance().LogEvent(ChatEvent.NewClient, this.customer.DisplayName);

                        // 若使用TLS协议
                        if (this.ChatServiceInfo != null &&
                            this.ChatServiceInfo.IsWebApiPortSecured)
                        {
                            KeyValueCollection kvs = new KeyValueCollection();
                            kvs[CommonConnection.TlsKey]          = 1;
                            kvs[CommonConnection.BlockingModeKey] = "true";
                            KeyValueConfiguration cfg = new KeyValueConfiguration(kvs);
                            this.customer.ChatProtocol.Configure(cfg);
                        }
                    }
                    catch (Exception)
                    {
                        if (user.EventBroker != null)
                        {
                            user.EventBroker.Unregister(this.ChatEventsHandler);
                        }
                        this.PartyDispose(user);
                    }
                }
                catch (LoadBalancerException ex)
                {
                    Trace.WriteLine("负载异常:" + ex.Message);
                    ii++;
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    ChatLog.GetInstance().LogException(ex);
                    ii++;
                }
            }
        }
Example #8
0
 internal void AddChatParty(ChatParty chatParty)
 {
     db.ChatParties.Add(chatParty);
     db.SaveChanges();
 }