/* Retrieves fields connectionId, userId, userName (from users), sessionStartTime and milestone from * the sashaSessions Database and returns it to the monitor that called for it */ public static string GetSashaSessionRecords(string instance) { using (tsc_tools db = new tsc_tools()) { sashaSession sashaSession = new sashaSession(); var sashaSessionRecord = from s in db.sashaSessions select new { s.connectionId, s.userId, s.user.userName, s.sessionStartTime, s.milestone }; return(JsonConvert.SerializeObject(sashaSessionRecord)); } }
/* Removes the SASHA session record from the database */ public static bool RemoveSashaSessionRecord(string connectionId) { using (tsc_tools db = new tsc_tools()) { sashaSession sashaSession = new sashaSession(); var sashaSessionRecord = db.sashaSessions.Where(s => s.connectionId == connectionId).SingleOrDefault(); if (sashaSessionRecord != null) { db.sashaSessions.Remove(sashaSessionRecord); db.SaveChanges(); return(true); } return(false); } }
/* Adds a record to the SashaSessions Database on connection of a SASHA client */ public static bool AddSashaSessionRecord(string connectionId, string userId, string smpSessionId, string sessionStartTime, string milestone, string instance) { using (tsc_tools db = new tsc_tools()) { sashaSession sashaSession = new sashaSession(); if (!db.sashaSessions.Any(s => s.connectionId == connectionId)) { sashaSession.connectionId = connectionId; sashaSession.userId = userId; sashaSession.smpSessionId = smpSessionId; sashaSession.sessionStartTime = sessionStartTime; sashaSession.milestone = milestone; sashaSession.instance = instance; db.sashaSessions.Add(sashaSession); db.SaveChanges(); return(true); } return(false); } }
public static void pushChat(string connectionId, string requesterConnectionId, string requesterName) { using (tsc_tools db = new tsc_tools()) { sashaSession sashaSession = new sashaSession(); var sashaSessionRecord = (from s in db.sashaSessions where s.connectionId == connectionId select s ).FirstOrDefault(); if (sashaSessionRecord != null) { string smpSessionId = sashaSessionRecord.smpSessionId; string userName = sashaSessionRecord.user.userName; var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>(); context.Groups.Add(requesterConnectionId, smpSessionId); context.Clients.Client(requesterConnectionId).addChatTab(smpSessionId, userName, "push"); context.Clients.Client(connectionId).requestChat(requesterName, requesterConnectionId); } } }
/* Sets Database tables to an initialized state on application startup * Empties records from table sashaSessionRecords * chatSessionRecords * set completeDate to 'Auto Closed' for any records that were not closed * ChatHelpers * connectionId "" * currentChats 0 * lastChatTime CurrentTime */ public static void InitializeTables() { using (tsc_tools db = new tsc_tools()) { sashaSession sashaSession = new sashaSession(); var sashaSessionRecords = db.sashaSessions; db.sashaSessions.RemoveRange(sashaSessionRecords); db.SaveChanges(); chatSession chatSession = new chatSession(); foreach (var chatSessionRecord in db.chatSessions.Where(c => c.completeDate == "").ToList()) { chatSessionRecord.completeDate = "Auto Closed"; } db.SaveChanges(); foreach (var chatHelperRecord in db.chatHelpers.ToList()) { chatHelperRecord.connectionId = ""; chatHelperRecord.currentChats = 0; chatHelperRecord.lastChatTime = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ"); } db.SaveChanges(); } }