示例#1
0
 // note: we may have multiple connections with a host, so
 // possibly multiple entries per host (each with a different
 // id), so we do not use the host as the hashtable key
 static public void Add(string host, byte[] id)
 {
     lock (locker) {
         string            uid = BitConverter.ToString(id);
         ClientSessionInfo si  = (ClientSessionInfo)cache[uid];
         if (si == null)
         {
             cache.Add(uid, new ClientSessionInfo(host, id));
         }
         else if (si.HostName == host)
         {
             // we already have this and it's still valid
             // on the server, so we'll keep it a little longer
             si.KeepAlive();
         }
         else
         {
             // it's very unlikely but the same session id
             // could be used by more than one host. In this
             // case we replace the older one with the new one
             si.Dispose();
             cache.Remove(uid);
             cache.Add(uid, new ClientSessionInfo(host, id));
         }
     }
 }
        private static ClientSessionInfo FromContext(
            Context context,
            bool checkValidity)
        {
            if (context == null)
            {
                return((ClientSessionInfo)null);
            }
            byte[] sessionId = context.SessionId;
            if (sessionId == null || sessionId.Length == 0)
            {
                return((ClientSessionInfo)null);
            }
            string            str = BitConverter.ToString(sessionId);
            ClientSessionInfo clientSessionInfo = (ClientSessionInfo)ClientSessionCache.cache[(object)str];

            if (clientSessionInfo == null)
            {
                return((ClientSessionInfo)null);
            }
            if (context.ClientSettings.TargetHost != clientSessionInfo.HostName)
            {
                return((ClientSessionInfo)null);
            }
            if (!checkValidity || clientSessionInfo.Valid)
            {
                return(clientSessionInfo);
            }
            clientSessionInfo.Dispose();
            ClientSessionCache.cache.Remove((object)str);
            return((ClientSessionInfo)null);
        }
示例#3
0
        private static ClientSessionInfo FromContext(Context context, bool checkValidity)
        {
            if (context == null)
            {
                return(null);
            }
            byte[] sessionId = context.SessionId;
            if (sessionId == null || sessionId.Length == 0)
            {
                return(null);
            }
            string            key = BitConverter.ToString(sessionId);
            ClientSessionInfo clientSessionInfo = (ClientSessionInfo)cache[key];

            if (clientSessionInfo == null)
            {
                return(null);
            }
            if (context.ClientSettings.TargetHost != clientSessionInfo.HostName)
            {
                return(null);
            }
            if (checkValidity && !clientSessionInfo.Valid)
            {
                clientSessionInfo.Dispose();
                cache.Remove(key);
                return(null);
            }
            return(clientSessionInfo);
        }
示例#4
0
        // only called inside the lock
        static private ClientSessionInfo 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);

            ClientSessionInfo si = (ClientSessionInfo)cache[uid];

            if (si == null)
            {
                return(null);
            }

            // In the unlikely case of multiple hosts using the same
            // session id, we just act like we do not know about it
            if (context.ClientSettings.TargetHost != si.HostName)
            {
                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);
        }
 public static void Add(string host, byte[] id)
 {
     lock (ClientSessionCache.locker)
     {
         string            str = BitConverter.ToString(id);
         ClientSessionInfo clientSessionInfo = (ClientSessionInfo)ClientSessionCache.cache[(object)str];
         if (clientSessionInfo == null)
         {
             ClientSessionCache.cache.Add((object)str, (object)new ClientSessionInfo(host, id));
         }
         else if (clientSessionInfo.HostName == host)
         {
             clientSessionInfo.KeepAlive();
         }
         else
         {
             clientSessionInfo.Dispose();
             ClientSessionCache.cache.Remove((object)str);
             ClientSessionCache.cache.Add((object)str, (object)new ClientSessionInfo(host, id));
         }
     }
 }
示例#6
0
 public static void Add(string host, byte[] id)
 {
     lock (locker)
     {
         string            key = BitConverter.ToString(id);
         ClientSessionInfo clientSessionInfo = (ClientSessionInfo)cache[key];
         if (clientSessionInfo == null)
         {
             cache.Add(key, new ClientSessionInfo(host, id));
         }
         else if (clientSessionInfo.HostName == host)
         {
             clientSessionInfo.KeepAlive();
         }
         else
         {
             clientSessionInfo.Dispose();
             cache.Remove(key);
             cache.Add(key, new ClientSessionInfo(host, id));
         }
     }
 }