Esempio n. 1
0
 public override Task OnDisconnected(bool stopCalled)
 {
     try
     {
         var connectionId = Context.ConnectionId;
         LoggingService.GetInstance().LogNote(connectionId + " disconnected from WebChatHub");
         var webChat = ChatServices.WebChats.FirstOrDefault(c => c.ConnectionId == connectionId);
         if (webChat != null && !webChat.DateAnswered.HasValue)
         {
             var keepQueuedChatsAlive = ChatController.KeepQueuedChatsAlive;
             if (keepQueuedChatsAlive)
             {
                 ChatServices.ProcessDisconnect(connectionId);
             }
             else
             {
                 if (webChat.Messages.Any() && ChatController.EnableReloadUnansweredChatHistory())
                 {
                     var unanswered = ChatServices.UnansweredChats.FirstOrDefault(u => u.SessionId == webChat.SessionId);
                     if (unanswered == null)
                     {
                         unanswered = new UnansweredChat
                         {
                             LastUpdated = DateTime.Now,
                             SessionId   = webChat.SessionId,
                             Messages    = webChat.Messages
                         };
                         ChatServices.UnansweredChats.Add(unanswered);
                     }
                     else
                     {
                         foreach (var chatMessage in webChat.Messages)
                         {
                             if (!unanswered.Messages.Any(u => u.Id == chatMessage.Id))
                             {
                                 unanswered.Messages.Add(chatMessage);
                             }
                         }
                         unanswered.LastUpdated = DateTime.Now;
                     }
                 }
                 ChatServices.ProcessDisconnect(connectionId, false, true);
             }
         }
         else
         {
             ChatServices.ProcessDisconnect(connectionId);
         }
     }
     catch (Exception e)
     {
         LoggingService.GetInstance().LogException(e);
     }
     return(base.OnDisconnected(stopCalled));
 }