// only called inside the lock static private ServerSessionInfo FromContext(Context context, bool checkValidity) { if (context == null) { return(null); } byte[] id = context.SessionId; if ((id == null) || (id.Length == 0)) { return(null); } // do we have a session cached for this host ? string uid = BitConverter.ToString(id); ServerSessionInfo si = (ServerSessionInfo)cache[uid]; if (si == null) { return(null); } // yes, so what's its status ? if (checkValidity && !si.Valid) { si.Dispose(); cache.Remove(uid); return(null); } // ok, it make sense return(si); }
static public bool SetContextFromCache(Context context) { lock (locker) { ServerSessionInfo csi = FromContext(context, true); if (csi == null) { return(false); } csi.SetContext(context); csi.KeepAlive(); return(true); } }
static public bool SetContextInCache(Context context) { lock (locker) { // Don't check the validity because the masterKey of the ClientSessionInfo // can still be null when this is called the first time ServerSessionInfo csi = FromContext(context, false); if (csi == null) { return(false); } csi.GetContext(context); csi.KeepAlive(); return(true); } }
static public void Add(byte[] id) { lock (locker) { string uid = BitConverter.ToString(id); ServerSessionInfo si = (ServerSessionInfo)cache[uid]; if (si == null) { cache.Add(uid, new ServerSessionInfo(id)); } else { // we already have this and it's still valid // on the server, so we'll keep it a little longer si.KeepAlive(); } } }