private void RemoveSessionFromDatabase(SessionId sessionId) { lock (_lockObj) { try { using (ServerDataContext context = new ServerDataContext()) { context.RemoveSession(sessionId); context.SaveChanges(); } } catch (Exception e) { ApplicationContext.Log.Error(GetType(), e); throw; } } }
public void ReconnectSessions() { using (ServerDataContext context = new ServerDataContext()) { List <SessionId> toRemove = new List <SessionId>(); foreach (ActiveSession session in context.ActiveSessions) { SessionId sessionId = new SessionId(session.SessionId); SessionData data = new SessionData(sessionId, context.CreateFakeTicket(session)); _sessions.TryAdd(sessionId, data); try { using (ClientProxy proxy = CreateClientProxy(data.Ticket)) { proxy.ConnectionRestarted(); Logger.Info("Restarted session to computer {0}.", data.Ticket.ClientComputer); } } catch (Exception e) { toRemove.Add(sessionId); ApplicationContext.Log.Error(GetType(), e); ApplicationContext.Log.Info(GetType(), "Removed session to: {0}", data.Ticket.ClientComputer); } } if (toRemove.Count > 0) { foreach (SessionId sessionId in toRemove) { SessionData tmpData; context.RemoveSession(sessionId); _sessions.TryRemove(sessionId, out tmpData); } context.SaveChanges(); } } }