Esempio n. 1
0
 public void AddOrUpdate(SessionUnit session)
 {
     if (sessions.ContainsKey(session.Identifier))
     {
         SessionUnit temporary;
         bool        isSuccess = sessions.TryRemove(session.Identifier, out temporary);
         if (!isSuccess)
         {
             throw new SessionCloseException("Error occured during updating the session.");
         }
         isSuccess = sessions.TryAdd(session.Identifier, session);
         if (!isSuccess)
         {
             throw new SessionCloseException("Error occured during updating the session.");
         }
     }
     else
     {
         bool isSuccess = sessions.TryAdd(session.Identifier, session);
         if (!isSuccess)
         {
             throw new SessionCloseException("Error occured during adding the session.");
         }
     }
 }
Esempio n. 2
0
        //ticka ustawia tick (http request od klienta) jeżeli lastTisk jest większy niż 20 minut to usuwam
        private void CheckSessions()
        {
            DateTime now = DateTime.Now;

            foreach (var session in sessions.ToArray())
            {
                SessionUnit current = session.Value;
                TimeSpan    delta   = now.Subtract(current.LastTick);
                if (delta.Minutes > 20)
                {
                    Close(session.Key);
                }
            }
            Task.Delay(5000);
        }