Exemple #1
0
 private void ChatNotFound(string message)
 {
     LoggingService.GetInstance().LogNote("Chat Not Found!!!");
     if (ChatController.EnableKeepOpenOnDisconnectAndStartNew())
     {
         Clients.Caller.restartChat(message);
     }
     else
     {
         Clients.Caller.addNewSystemMessageToPage(ChatController.GetConnectionLostText());
     }
 }
Exemple #2
0
        public void Disconnect(string connectionId, bool forceDisconnect)
        {
            var chat = ChatServices.WebChats.FirstOrDefault(c => c.ConnectionId == connectionId || (c.PreviousConnectionIds != null && c.PreviousConnectionIds.Contains(connectionId)));

            if (!forceDisconnect)
            {
                if (chat != null && ChatController.ContinueChat() && (chat.State == ChatState.Connected || chat.State == ChatState.Paused))
                {
                    var now       = DateTime.Now;
                    var remaining = ChatController.ContinueChatTimeout();
                    if (chat.DateEnded.HasValue)
                    {
                        var elapsed = now.Subtract(chat.DateEnded.Value);
                        remaining = ChatController.ContinueChatTimeout() - Convert.ToInt32(elapsed.TotalSeconds);
                    }
                    if (remaining > 0)
                    {
                        var isPaused = chat.State == ChatState.Paused;
                        Clients.Client(connectionId).pauseWcbChat(isPaused);
                        return;
                    }
                }

                Clients.Client(connectionId).disconnected(ChatController.EnableKeepOpenOnDisconnectAndStartNew(), true);
            }
            else
            {
                if (chat != null)
                {
                    ChatServices.SendCustomSystemMessage(CustomMessageType.VisitorDisconnect, "", chat.ConnectionId, chat);
                    if (chat.PreviousConnectionIds != null && chat.PreviousConnectionIds.Any())
                    {
                        foreach (var cid in chat.PreviousConnectionIds.Where(p => p != chat.ConnectionId))
                        {
                            ChatServices.SendCustomSystemMessage(CustomMessageType.VisitorDisconnect, "", cid, chat);
                        }
                    }
                    ChatServices.ProcessDisconnect(chat.ConnectionId, false, true);
                }
            }
        }
Exemple #3
0
 public void Disconnect(WebChat webChat, ChatServices.DisconnectReason reason)
 {
     try
     {
         var chatId                = webChat.ChatId;
         var connectionId          = webChat.ConnectionId;
         var participantId         = webChat.ParticipantId;
         var previousConnectionIds = webChat.PreviousConnectionIds;
         if (ChatController.EnableKeepOpenOnDisconnectAndStartNew() && webChat.DateAnswered.HasValue)
         {
             if (webChat.Messages.Any() && !ChatServices.DisconnectedWebChats.Any(
                     d =>
                     d.ConnectionId == webChat.ConnectionId &&
                     (d.PreviousConnectionIds != null &&
                      d.PreviousConnectionIds.Contains(webChat.ConnectionId))))
             {
                 ChatServices.DisconnectedWebChats.Add(webChat);
             }
         }
         ChatServices.WebChats.Remove(webChat);
         ChatServices.Disconnect(connectionId, reason);
         if (previousConnectionIds != null)
         {
             foreach (var previousConnectionId in previousConnectionIds)
             {
                 ChatServices.Disconnect(previousConnectionId, reason, "", true, true);
             }
         }
         ChatServices.EndChat(participantId);
         var repository = new Repository();
         var chat       = repository.Chats.Find(chatId);
         if (chat != null)
         {
             chat.DateEnded = DateTime.Now;
             repository.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }