Example #1
0
        /// <summary>
        /// 访客请请求 to-all
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ChatService_VisitorChatRequest(object sender, VisitorChatRequestEventArgs e)
        {
            Visitor v = VisitorService.GetVisitorById(e.VisitorId);

            if (v != null)
            {
                List <Socket> sockets = GetOnlineOperatorSockets(v.AccountId);
                foreach (var item in sockets)
                {
                    sh.SendPacket(item, new VisitorChatRequestEventArgs(e.VisitorId, e.Chat));
                }
            }
        }
Example #2
0
    /// <summary>
    /// 页面请求对话
    /// </summary>
    /// <param name="CurrentVisitor"></param>
    /// <returns>ChatId</returns>
    public static string ChatPageRequestChat(Visitor visitor)
    {
        Trace.WriteLine(string.Format("ChatService.ChatPageRequestChat(Visitor = {0})", visitor));
        if (!string.IsNullOrEmpty(visitor.Name))
        {
            Visitor vs = VisitorService.GetVisitorById(visitor.VisitorId);
            vs.Name = visitor.Name;
            VisitorService.UpdateVisitor(vs);
        }
        Chat chatRequest = new Chat();

        chatRequest.AccountId  = visitor.AccountId;
        chatRequest.CreateTime = DateTime.Now;
        chatRequest.Status     = ChatStatus.Requested;
        chatRequest.VisitorId  = visitor.VisitorId;

        chats.Add(chatRequest);
        Provider.AddChat(chatRequest);

        VisitSession s = VisitSessionService.GetSessionById(visitor.CurrentSessionId);

        s.ChatRequestTime = DateTime.Now;
        s.Status          = VisitSessionStatus.ChatRequesting;

        Message m = new Message();

        m.ChatId      = chatRequest.ChatId;
        m.Text        = "正在接入客服,请稍等...";
        m.Type        = MessageType.SystemMessage_ToVisitor;
        m.Source      = "系统";
        m.Destination = "访客";
        SendMessage(m, DateTime.Now.AddMilliseconds(100));

        if (VisitorChatRequest != null)
        {
            VisitorChatRequestEventArgs req = new VisitorChatRequestEventArgs(visitor.VisitorId, chatRequest);
            visitorChatRequests.Add(req);
            VisitorChatRequest(null, req);
        }

        return(chatRequest.ChatId);
    }
Example #3
0
    /// <summary>
    /// 页面请求对话
    /// </summary>
    /// <param name="CurrentVisitor"></param>
    /// <returns>ChatId</returns>
    public static string ChatPageRequestChat(Visitor visitor)
    {
        Trace.WriteLine(string.Format("ChatService.ChatPageRequestChat(Visitor = {0})", visitor));
        if (!string.IsNullOrEmpty(visitor.Name))
        {
            Visitor vs = VisitorService.GetVisitorById(visitor.VisitorId);
            vs.Name = visitor.Name;
            VisitorService.UpdateVisitor(vs);
        }
        Chat chatRequest = new Chat();
        chatRequest.AccountId = visitor.AccountId;
        chatRequest.CreateTime = DateTime.Now;
        chatRequest.Status = ChatStatus.Requested;
        chatRequest.VisitorId = visitor.VisitorId;

        chats.Add(chatRequest);
        Provider.AddChat(chatRequest);

        VisitSession s = VisitSessionService.GetSessionById(visitor.CurrentSessionId);
        s.ChatRequestTime = DateTime.Now;
        s.Status = VisitSessionStatus.ChatRequesting;

        Message m = new Message();
        m.ChatId = chatRequest.ChatId;
        m.Text = "正在接入客服,请稍等...";
        m.Type = MessageType.SystemMessage_ToVisitor;
        m.Source = "系统";
        m.Destination = "访客";
        SendMessage(m, DateTime.Now.AddMilliseconds(100));

        if (VisitorChatRequest != null)
        {
            VisitorChatRequestEventArgs req = new VisitorChatRequestEventArgs(visitor.VisitorId,chatRequest);
            visitorChatRequests.Add(req);
            VisitorChatRequest(null, req);
        }
        
        return chatRequest.ChatId;
    }
Example #4
0
 void ChatService_VisitorChatRequest(object sender, VisitorChatRequestEventArgs e)
 {
     throw new NotImplementedException();
 }
Example #5
0
        void processServerEvents(DataArriveEventArgs e)
        {
            // 客服状态改变
            if (e.Data.GetType() == typeof(OperatorForceLogoffEventArgs))
            {
                if (OperatorForceLogoff != null)
                {
                    OperatorForceLogoff(this, null);
                }
            }
            else if (e.Data.GetType() == typeof(OperatorStatusChangeEventArgs))
            {
                OperatorStatusChangeEventArgs os = (OperatorStatusChangeEventArgs)e.Data;
                Operator op = GetOperatorById(os.OperatorId);
                if (op != null)
                {
                    op.Status = os.Status;
                    OperatorStatusChanged(this, os);
                }
            }
            //访客对话请求
            else if (e.Data.GetType() == typeof(VisitorChatRequestEventArgs))
            {
                VisitorChatRequestEventArgs vc = (VisitorChatRequestEventArgs)e.Data;
                Visitor v = GetVisitorById(vc.VisitorId);
                if (v != null)
                {
                    v.CurrentSession.Status = VisitSessionStatus.ChatRequesting;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                    VisitorChatRequest(this, vc);
                    addChat(vc.Chat);
                }
            }
            //客服对话邀请
            else if (e.Data.GetType() == typeof(OperatorChatRequestEventArgs))
            {
                OperatorChatRequestEventArgs ocr = (OperatorChatRequestEventArgs)e.Data;
                Operator op = GetOperatorById(ocr.OperatorId);
                Visitor  v  = GetVisitorById(ocr.VisitorId);
                if (op != null && v != null)
                {
                    op.Status = OperatorStatus.InviteChat;
                    addChat(ocr.Chat);
                    //v.CurrentSession.Status = VisitSessionStatus.
                    //OperatorChatRequest(this, ocr);
                    OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, OperatorStatus.InviteChat));
                }
            }
            // 访客对话请求被接受
            else if (e.Data.GetType() == typeof(VisitorChatRequestAcceptedEventArgs))
            {
                VisitorChatRequestAcceptedEventArgs v = e.Data as VisitorChatRequestAcceptedEventArgs;
                Chat     chat    = GetChatByChatId(v.VisitorChatRequest.Chat.ChatId);
                Operator op      = GetOperatorById(v.VisitorChatRequest.Chat.OperatorId);
                Visitor  visitor = GetVisitorById(v.VisitorChatRequest.VisitorId);
                if (chat != null && op != null && visitor != null)
                {
                    chat.OperatorId = v.VisitorChatRequest.Chat.OperatorId;
                    op.Status       = OperatorStatus.Chatting;
                    visitor.CurrentSession.OperatorId = op.OperatorId;
                    VisitSession vs = visitor.CurrentSession;
                    vs.ChatingTime = v.VisitorChatRequest.Chat.AcceptTime;
                    vs.Status      = VisitSessionStatus.Chatting;

                    //VisitorChatRequestAccepted(this, (VisitorChatRequestAcceptedEventArgs)e.Data);
                    OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(v.VisitorChatRequest.Chat.OperatorId, OperatorStatus.Chatting));
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(vs));
                }
            }
            // 客服对话邀请被接受
            else if (e.Data.GetType() == typeof(OperatorChatRequestAcceptedEventArgs))
            {
                OperatorChatRequestAcceptedEventArgs ocr = (OperatorChatRequestAcceptedEventArgs)e.Data;
                Operator op = GetOperatorById(ocr.ChatRequest.OperatorId);
                Visitor  v  = GetVisitorById(ocr.ChatRequest.VisitorId);
                if (op != null && v != null)
                {
                    op.Status = OperatorStatus.Chatting;
                    v.CurrentSession.Status = VisitSessionStatus.Chatting;
                    if (OperatorChatRequestAccepted != null)
                    {
                        OperatorChatRequestAccepted(this, (OperatorChatRequestAcceptedEventArgs)e.Data);
                    }
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                    OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, op.Status));
                }
            }
            // 客服对话邀请被拒绝
            else if (e.Data.GetType() == typeof(OperatorChatRequestDeclinedEventArgs))
            {
                OperatorChatRequestDeclinedEventArgs ocr = (OperatorChatRequestDeclinedEventArgs)e.Data;
                Operator op = GetOperatorById(ocr.ChatRequest.OperatorId);
                Visitor  v  = GetVisitorById(ocr.ChatRequest.VisitorId);
                Chat     c  = GetChatByChatId(ocr.ChatRequest.Chat.ChatId);
                if (op != null && v != null && c != null)
                {
                    c.Status = ChatStatus.Decline;
                    if (!IsOperatorHasActiveChat(op.OperatorId))
                    {
                        op.Status = OperatorStatus.Idle;
                        OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, OperatorStatus.Idle));
                    }
                    v.CurrentSession.Status = VisitSessionStatus.Visiting;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                    if (OperatorChatRequestDeclined != null)
                    {
                        OperatorChatRequestDeclined(this, (OperatorChatRequestDeclinedEventArgs)e.Data);
                    }
                }
            }
            // 新的对话
            else if (e.Data.GetType() == typeof(NewChatEventArgs))
            {
                NewChat(this, (NewChatEventArgs)e.Data);
            }
            // 对话状态改变
            else if (e.Data.GetType() == typeof(ChatStatusChangedEventArgs))
            {
                ChatStatusChangedEventArgs cs = (ChatStatusChangedEventArgs)e.Data;

                Chat chat = GetChatByChatId(cs.ChatId);
                if (chat == null)
                {
                    return;
                }
                Visitor v = GetVisitorById(chat.VisitorId);
                if (v == null)
                {
                    return;
                }
                chat.Status = cs.Status;
                Operator o = GetOperatorById(chat.OperatorId);

                if (chat.Status == ChatStatus.Accepted)
                {
                    v.CurrentSession.Status = VisitSessionStatus.Chatting;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                    o.Status = OperatorStatus.Chatting;
                    OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(chat.OperatorId, OperatorStatus.Chatting));
                }
                else if (chat.Status == ChatStatus.Closed)
                {
                    v.CurrentSession.Status = VisitSessionStatus.Visiting;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                    if (o != null && !IsOperatorHasActiveChat(chat.OperatorId))
                    {
                        o.Status = OperatorStatus.Idle;
                        OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(chat.OperatorId, OperatorStatus.Idle));
                    }
                }

                if (ChatStatusChanged != null)
                {
                    ChatStatusChanged(this, cs);
                }
            }
            else if (e.Data.GetType() == typeof(OperatorChatJoinInviteEventArgs))
            {
                ChatJoinInvite(this, (OperatorChatJoinInviteEventArgs)e.Data);
            }
            else if (e.Data.GetType() == typeof(OperatorChatJoinInviteAcceptedEventArgs))
            {
                ChatJoinInviteAccepted(this, (OperatorChatJoinInviteAcceptedEventArgs)e.Data);
            }
            else if (e.Data.GetType() == typeof(OperatorChatJoinInviteDeclinedEventArgs))
            {
                ChatJoinInviteDeclined(this, (OperatorChatJoinInviteDeclinedEventArgs)e.Data);
            }
            // 新消息
            else if (e.Data.GetType() == typeof(ChatMessageEventArgs) && NewMessage != null)
            {
                NewMessage(this, (ChatMessageEventArgs)e.Data);
            }
            // 新访问,访客可能已经存在
            else if (e.Data.GetType() == typeof(NewVisitingEventArgs) && NewVisiting != null)
            {
                NewVisitingEventArgs nv = (NewVisitingEventArgs)e.Data;
                nv.Visitor.CurrentSession = nv.Session;
                Visitor v = GetVisitorById(nv.Visitor.VisitorId);
                if (v != null)
                {
                    v.CurrentSession = nv.Session;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                }
                else
                {
                    addVisitor(nv.Visitor);
                    NewVisiting(this, (NewVisitingEventArgs)e.Data);
                }
            }
            // 访客离开
            else if (e.Data.GetType() == typeof(VisitorLeaveEventArgs))
            {
                VisitorLeaveEventArgs vl = e.Data as VisitorLeaveEventArgs;
                Visitor v = GetVisitorById(vl.VisitorId);
                if (v != null)
                {
                    v.CurrentSession.Status = VisitSessionStatus.Leave;
                    VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession));
                }
                //VisitorLeave(this, (VisitorLeaveEventArgs)e.Data);
            }
        }
Example #6
0
 void ChatService_VisitorChatRequest(object sender, VisitorChatRequestEventArgs e)
 {
     throw new NotImplementedException();
 }