Exemplo n.º 1
0
 /* Checks helperConnection for an existing record and connectionStatus.
  * If no record exists return noRecord
  * If a record exists check if connectionStatus is notConnected
  *      True: Update ConnectionStatus and return newConnection
  *      False: return existingConnection */
 public static string GetChatHelper(string userId, string connectionId)
 {
     using (tsc_tools db = new tsc_tools())
     {
         chatHelper chatHelper       = new chatHelper();
         var        chatHelperRecord = db.chatHelpers.Where(c => c.userId == userId).SingleOrDefault();
         if (chatHelperRecord != null)
         {
             if (chatHelperRecord.connectionId != "")
             {
                 return("existingConnection");
             }
             else
             {
                 int maximumChats = chatHelperRecord.maximumChats;
                 chatHelperRecord.connectionId = connectionId;
                 db.Entry(chatHelperRecord).CurrentValues.SetValues(chatHelperRecord);
                 db.SaveChanges();
                 db.Configuration.LazyLoadingEnabled = false;
                 var Record = db.chatHelpers.Where(c => c.userId == userId).SingleOrDefault();
                 return(JsonConvert.SerializeObject(Record));
             }
         }
         else
         {
             return("noRecord");
         }
     }
 }
Exemplo n.º 2
0
 public static void ToggleHelperStatus(string connectionId, string status)
 {
     using (tsc_tools db = new tsc_tools())
     {
         chatHelper chatHelper       = new chatHelper();
         var        chatHelperRecord =
             (from c in db.chatHelpers
              where c.connectionId == connectionId
              select c
             ).FirstOrDefault();
         if (chatHelperRecord != null)
         {
             chatHelperRecord.onlineStatus = status;
         }
         db.Entry(chatHelperRecord).CurrentValues.SetValues(chatHelperRecord);
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
 /* Updates Chat Helper record to mark them offline, no longer connected and closes any changes they have open in chatSessions */
 public static void UpdateChatHelper(string connectionId)
 {
     using (tsc_tools db = new tsc_tools())
     {
         chatHelper chatHelper       = new chatHelper();
         var        chatHelperRecord = db.chatHelpers.Where(c => c.connectionId == connectionId).SingleOrDefault();
         if (chatHelperRecord != null)
         {
             chatHelperRecord.connectionId = "";
             chatHelperRecord.currentChats = 0;
             chatHelperRecord.onlineStatus = "Offline";
         }
         db.Entry(chatHelperRecord).CurrentValues.SetValues(chatHelperRecord);
         db.SaveChanges();
         chatSession chatSession = new chatSession();
         foreach (var chatSessionRecord in db.chatSessions.Where(c => c.helperConnectionId == connectionId && c.completeDate == "").ToList())
         {
             chatSessionRecord.completeDate = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
 /* Updates the sashaSessionrecord with the current time so that it starts getting tracked on monitors */
 public static void UpdateSashaSessionRecord(string userId, string connectionId, string milestone, string lastAgentActivityTime)
 {
     using (tsc_tools db = new tsc_tools())
     {
         chatHelper chatHelper         = new chatHelper();
         var        sashaSessionRecord =
             (from s in db.sashaSessions
              where s.userId == userId &&
              s.connectionId == connectionId
              select s
             ).FirstOrDefault();
         if (sashaSessionRecord != null)
         {
             string userName         = sashaSessionRecord.user.userName;
             string sessionStartTime = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
             sashaSessionRecord.sessionStartTime = sessionStartTime;
             db.Entry(sashaSessionRecord).CurrentValues.SetValues(sashaSessionRecord);
             db.SaveChanges();
             var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>();
             context.Clients.Group(groupNames.Monitor).addSashaSession(connectionId, userId, userName, sessionStartTime, milestone, lastAgentActivityTime);
         }
     }
 }
Exemplo n.º 5
0
        /* Checks for an available helper and connects them if ready */
        public static bool GetAvailableHelper(string smpSessionId, string userId, string userName, string connectionId, string flowName, string stepName)
        {
            Dictionary <string, string> returnInfo = new Dictionary <string, string>();

            using (tsc_tools db = new tsc_tools())
            {
                chatHelper chatHelper       = new chatHelper();
                var        chatHelperRecord =
                    (from c in db.chatHelpers
                     where c.onlineStatus == "Online"
                     select c
                    ).FirstOrDefault();
                if (chatHelperRecord == null)
                {
                    /* No Online Chat Helpers */
                    var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>();
                    var time    = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    context.Clients.Client(connectionId).throwMessage("Notice", "There are currently no chat helpers online.", false);
                    context.Clients.Client(connectionId).broadcastMessage(smpSessionId, time, "SYSTEM", "There are currently no chat helpers online.");
                    chatSession ChatSession = new chatSession();
                    ChatSession.chatGUID          = Guid.NewGuid();
                    ChatSession.sashaSessionId    = smpSessionId;
                    ChatSession.agentConnectionId = connectionId;
                    ChatSession.agentId           = userId;
                    ChatSession.lastActivity      = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.requestDate       = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.flowName          = flowName;
                    ChatSession.stepName          = stepName;
                    db.chatSessions.Add(ChatSession);
                    db.SaveChanges();
                    return(false);
                }
                chatHelperRecord =
                    (from c in db.chatHelpers
                     where c.onlineStatus == "Online" &&
                     c.currentChats < c.maximumChats &&
                     c.userId != userId
                     orderby c.lastChatTime ascending
                     select c
                    ).FirstOrDefault();
                if (chatHelperRecord == null)
                {
                    /* Helpers online but all at maximum sessions */
                    var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>();
                    var time    = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    context.Clients.Client(connectionId).throwMessage("Notice", "All available chat helpers are busy.", false);
                    context.Clients.Client(connectionId).broadcastMessage(smpSessionId, time, "SYSTEM", "All chat helpers are busy.");
                    chatSession ChatSession = new chatSession();
                    ChatSession.chatGUID          = Guid.NewGuid();
                    ChatSession.sashaSessionId    = smpSessionId;
                    ChatSession.agentConnectionId = connectionId;
                    ChatSession.agentId           = userId;
                    ChatSession.lastActivity      = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.requestDate       = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.completeDate      = "";
                    ChatSession.flowName          = flowName;
                    ChatSession.stepName          = stepName;
                    db.chatSessions.Add(ChatSession);
                    db.SaveChanges();
                    return(false);
                }
                if (chatHelperRecord != null)
                {
                    string chatHelperId           = chatHelperRecord.userId;
                    string chatHelperName         = chatHelperRecord.user.userName;
                    string chatHelperConnectionId = chatHelperRecord.connectionId;
                    string lastChatTime           = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    int    currentChats           = chatHelperRecord.currentChats + 1;
                    /* Helper Found */
                    var time    = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>();
                    context.Clients.Client(connectionId).broadcastMessage(smpSessionId, time, chatHelperName, "Hello " + userName + " how may I assist you?");
                    returnInfo.Add("Available", "True");
                    returnInfo.Add("chatHelperId", chatHelperId);
                    returnInfo.Add("chatHelperName", chatHelperName);
                    chatHelperRecord.currentChats = currentChats;
                    db.Entry(chatHelperRecord).CurrentValues.SetValues(chatHelperRecord);
                    db.SaveChanges();
                    chatSession ChatSession = new chatSession();
                    ChatSession.chatGUID           = Guid.NewGuid();
                    ChatSession.sashaSessionId     = smpSessionId;
                    ChatSession.agentConnectionId  = connectionId;
                    ChatSession.helperConnectionId = chatHelperConnectionId;
                    ChatSession.agentId            = userId;
                    ChatSession.helperId           = chatHelperId;
                    ChatSession.lastActivity       = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.requestDate        = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");
                    ChatSession.completeDate       = "";
                    ChatSession.flowName           = flowName;
                    ChatSession.stepName           = stepName;
                    db.chatSessions.Add(ChatSession);
                    db.SaveChanges();
                    context.Groups.Add(chatHelperConnectionId, smpSessionId);
                    context.Clients.Client(chatHelperConnectionId).addChatTab(smpSessionId, userName, "pull");
                }
                return(true);
            }
        }