Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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));
         }
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        static public bool SetContextFromCache(Context context)
        {
            lock (locker) {
                ClientSessionInfo csi = FromContext(context, true);
                if (csi == null)
                {
                    return(false);
                }

                csi.SetContext(context);
                csi.KeepAlive();
                return(true);
            }
        }
Ejemplo n.º 5
0
 public static bool SetContextInCache(Context context)
 {
     lock (ClientSessionCache.locker)
     {
         ClientSessionInfo clientSessionInfo = ClientSessionCache.FromContext(context, false);
         if (clientSessionInfo == null)
         {
             return(false);
         }
         clientSessionInfo.GetContext(context);
         clientSessionInfo.KeepAlive();
         return(true);
     }
 }
Ejemplo n.º 6
0
        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
                ClientSessionInfo csi = FromContext(context, false);
                if (csi == null)
                {
                    return(false);
                }

                csi.GetContext(context);
                csi.KeepAlive();
                return(true);
            }
        }
Ejemplo n.º 7
0
        public static bool SetContextInCache(Context context)
        {
            lock (locker)
            {
                ClientSessionInfo clientSessionInfo = FromContext(context, checkValidity: false);
                if (clientSessionInfo == null)
                {
                    return(false);
                }
                clientSessionInfo.GetContext(context);
                clientSessionInfo.KeepAlive();
                return(true);

IL_0035:
                bool result;
                return(result);
            }
        }
        public static byte[] FromHost(string host)
        {
            object obj = ClientSessionCache.locker;

            byte[] result;
            lock (obj)
            {
                foreach (object obj2 in ClientSessionCache.cache.Values)
                {
                    ClientSessionInfo clientSessionInfo = (ClientSessionInfo)obj2;
                    if (clientSessionInfo.HostName == host && clientSessionInfo.Valid)
                    {
                        clientSessionInfo.KeepAlive();
                        return(clientSessionInfo.Id);
                    }
                }
                result = null;
            }
            return(result);
        }
Ejemplo n.º 9
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 bool SetContextInCache(Context context)
        {
            object obj = ClientSessionCache.locker;
            bool   result;

            lock (obj)
            {
                ClientSessionInfo clientSessionInfo = ClientSessionCache.FromContext(context, false);
                if (clientSessionInfo == null)
                {
                    result = false;
                }
                else
                {
                    clientSessionInfo.GetContext(context);
                    clientSessionInfo.KeepAlive();
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
 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));
         }
     }
 }
Ejemplo n.º 12
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));
         }
     }
 }