public static void DoJob(object state) { var app = state as IApplicationBuilder; var settings = app.GetService <IOptionsSnapshot <AppSettings> >().Value; var db = app.GetService <IJsonDataStore <JsonDatabase> >(); var expiredSessions = ClientSessions.SessionsList .Where(client => (DateTime.Now - client.LastReceivedData).Minutes > settings.SessionsSendLogIntervalMinutes); if (expiredSessions.Any()) { foreach (var client in ClientSessions.SessionsList) { if ((DateTime.Now - client.LastReceivedData).Minutes >= settings.SessionsSendLogIntervalMinutes) { client.IsRunning = TextResources.Disconnect; client.Status = Constants.PMDLProStatusDisconnected; client.LastReceivedData = DateTime.Now; } } _db = app.GetService <IJsonDataStore <JsonDatabase> >() as AppJsonDataStore; _db.Database.Sessions = ClientSessions.SessionsList; _db.ApplyChanges(); ViewUpdater.Update(); } }
public static void Add(SessionListItem item) { //update the last data receive time : item.LastReceivedData = DateTime.Now; //if request is coming from unknown client (not RANPOD client) if (item == null || (item.IsRunning != TextResources.Stoped && item.IsRunning != TextResources.Running)) { return; } //request is coming from RANPOD client //we will check if there is any item in our list with same ip var oldItem = SessionsList.FirstOrDefault(session => session.ClientIp == item.ClientIp); if (!string.IsNullOrEmpty(item.ClientIp)) { //item is already in list so we remove it if (oldItem != null) { SessionsList.Remove(oldItem); } } //client has not been configured yet if (item.ProtectionStatus == TextResources.NotConfigured) { var newItem = new SessionListItem { ClientIp = item.ClientIp, IsRunning = "", LicenseExpireDate = "", Version = "", OrganizationId = "", ProtectionStatus = item.ProtectionStatus, LicenseWillExpireSoon = false, LastReceivedData = DateTime.Now }; SessionsList.Add(newItem); } //client has been configured and hardware id is not present else if (item.HardwareId != null && item.HardwareId.ToLower().Contains(Constants.PMDLProPacketErrorFlag)) { var newItem = new SessionListItem { ClientIp = item.ClientIp, IsRunning = item.IsRunning, Version = TextResources.NotAvailable, LicenseExpireDate = item.LicenseExpireDate, ServerID = item.ServerID, OrganizationId = item.OrganizationId, ProtectionStatus = item.ProtectionStatus, LicenseWillExpireSoon = item.LicenseWillExpireSoon, LastReceivedData = DateTime.Now }; SessionsList.Add(newItem); } //client is ok else { SessionsList.Add(item); } _db.Database.Sessions = SessionsList; _db.ApplyChanges(); }