Пример #1
0
        private static void QueueListen()
        {
            while (true)
            {
                for (int i = 0; i < Queue.Count; i++)
                {
                    try
                    {
                        var customer = Queue[i];

                        SocketP2PMessageEntity message = new SocketP2PMessageEntity();
                        message.Sender   = customer.Sender;
                        message.Identity = customer.Identity;
                        message.Owner    = customer.Owner;
                        message.WeiXinNo = customer.WeiXinNo;
                        message.OpenId   = customer.OpenId;
                        message.Data     = "CHECKIDENTITY";

                        IIdentity id = new CustomerIdentity();
                        id.Comunicate(customer, message, Clients, Queue, SendToClientComplete, OutPutSystemMessage);
                    }
                    catch
                    {
                        break;
                    }
                }

                Thread.Sleep(1000 * 60 * 5);
            }
        }
Пример #2
0
        public static void Execute(SocketP2PEntity client, SocketP2PMessageEntity message,
                                   List <SocketP2PEntity> Clients, List <SocketP2PEntity> Queue,
                                   SendToClientCompleteHandler SendToClientCompleteHandler, OutPutSystemMessageHandler OutPutSystemMessageHandler)
        {
            IIdentity id = null;

            switch (message.Identity.ToUpper())
            {
            case "CUSTOMER":
                id = new CustomerIdentity();
                break;

            case "SERVANT":
                id = new ServantIdentity();
                break;
            }

            id.Comunicate(client, message, Clients, Queue, SendToClientCompleteHandler, OutPutSystemMessageHandler);
        }
Пример #3
0
        private static void AutoCutLine()
        {
            while (true)
            {
                try
                {
                    var clients = from x in Clients
                                  where x.Identity == "CUSTOMER" &&
                                  x.LastTalkTime != null &&
                                  (DateTime.Now - (x.LastTalkTime ?? DateTime.Now)).TotalSeconds > (60 * 3) &&
                                  !(from z in Queue
                                    where z.Sender == x.Sender
                                    select z).Any()
                                  select x;

                    foreach (var client in clients)
                    {
                        // 通知客服
                        var servant = Clients.Where(x => x.Sender == client.Receiver).FirstOrDefault();
                        if (servant != null)
                        {
                            try
                            {
                                SocketP2PMessageEntity message = new SocketP2PMessageEntity();
                                message.Sender   = null;
                                message.Receiver = servant.Sender;
                                message.Identity = "SERVER";
                                message.Data     = string.Format("访客({0})超过3分钟未发言,系统自动断线,请等待其他访客的服务请求", servant.Receiver);
                                message.Owner    = servant.Owner;
                                message.WeiXinNo = servant.WeiXinNo;
                                message.OpenId   = servant.OpenId;

                                servant.Receiver = null;

                                ServantIdentity identity = new ServantIdentity();
                                identity.Comunicate(servant, message, Clients, Queue, SendToClientComplete, OutPutSystemMessage);
                            }
                            catch (SocketException ex)
                            {
                                servant.Socket.Close();
                                Clients.Remove(servant);
                                OutPutSystemMessage(ex.Message);
                            }
                        }

                        Thread.Sleep(500);
                        // 通知访客
                        try
                        {
                            SocketP2PMessageEntity message = new SocketP2PMessageEntity();
                            message.Sender   = null;
                            message.Receiver = client.Sender;
                            message.Identity = "SERVER";
                            message.Data     = "您有3分钟未发言,自动为您退出";
                            message.Owner    = client.Owner;
                            message.WeiXinNo = client.WeiXinNo;
                            message.OpenId   = client.OpenId;
                            CustomerIdentity identity = new CustomerIdentity();
                            identity.Comunicate(client, message, Clients, Queue, SendToClientComplete, OutPutSystemMessage);
                        }
                        catch (SocketException ex)
                        {
                            OutPutSystemMessage(ex.Message);
                        }
                        finally
                        {
                            client.Socket.Close();
                            Clients.Remove(client);
                        }
                    }
                }
                catch
                {
                }

                Thread.Sleep(500);
            }
        }