예제 #1
0
 void PollChat(WebChat webChat)
 {
     if (webChat.State == ChatState.Disconnected)
     {
         Disconnect(webChat, ChatServices.DisconnectReason.UserDisconnect);
         return;
     }
     if (webChat.State == ChatState.Paused || (ChatController.KeepQueuedChatsAlive && webChat.State == ChatState.Queued && webChat.IsMinimized))
     {
         if (webChat.DatePaused.HasValue)
         {
             var elapsed             = DateTime.Now.Subtract(webChat.DatePaused.Value);
             var elapsedSeconds      = Convert.ToInt32(elapsed.TotalSeconds);
             var continueChatTimeout = ChatController.ContinueChatTimeout();
             if (elapsedSeconds > continueChatTimeout)
             {
                 LoggingService.GetInstance().LogNote(String.Format("Continue Chat timed out for connection: {0}", webChat.ConnectionId));
                 Disconnect(webChat, ChatServices.DisconnectReason.ContinueChatTimeout);
                 return;
             }
         }
     }
     if ((webChat.State == ChatState.Connected || webChat.State == ChatState.Paused) && ChatController.EnableInactivityTimeout() && webChat.DateAnswered.HasValue)
     {
         if (ChatController.InactivityTimeout() > 0)
         {
             var inactiveTimeout = ChatController.InactivityTimeout();
             var lastAgent       = webChat.Messages.OrderBy(m => m.Order).LastOrDefault(m => m.Direction == "in" && !m.Name.Equals("System", StringComparison.OrdinalIgnoreCase));
             var lastUser        = webChat.Messages.OrderBy(m => m.Order).LastOrDefault(m => m.Direction == "out" && !m.Name.Equals("System", StringComparison.OrdinalIgnoreCase));
             var now             = DateTime.Now;
             var last            = now;
             if (lastAgent != null && lastUser != null)
             {
                 if (ChatController.EnableInactivityResetOnAgentMessage())
                 {
                     last = lastAgent.DateSent > lastUser.DateSent ? lastAgent.DateSent : lastUser.DateSent;
                 }
                 else
                 {
                     last = lastUser.DateSent;
                 }
             }
             else if (lastAgent != null)
             {
                 last = lastAgent.DateSent;
             }
             if (last != now)
             {
                 var elapsed        = now.Subtract(last);
                 var elapsedSeconds = Convert.ToInt32(elapsed.TotalSeconds);
                 if (elapsedSeconds > inactiveTimeout)
                 {
                     LoggingService.GetInstance().LogNote(String.Format("Inactivity Time Out Occurred: {0}", webChat.ConnectionId));
                     Disconnect(webChat, ChatServices.DisconnectReason.InactivityTimeout);
                     return;
                 }
             }
         }
     }
     ChatServices.PollEvents(webChat.ParticipantId, webChat.ConnectionId, webChat.SessionId);
 }