Beispiel #1
0
 public static T GetSessionData <T>(string sessionId, string key) where T : class
 {
     lock (_threadLock)
     {
         T       value   = default(T);
         Session session = _sessions.Value.FirstOrDefault(s => s.SessionId == sessionId);
         if (session.IsNotNull())
         {
             KeyValuePair <string, object> kv = session._values.Value.FirstOrDefault(v => v.Key == key);
             if (kv.IsNotNull() && kv.Value.IsTypeOf <T>())
             {
                 value = kv.Value.CastToType <T>();
             }
         }
         return(value);
     }
 }
Beispiel #2
0
        // Traverse the graph
        private ArrayList ShortestPathInternal(IDictionary <string, Node> graph, string toAccount, int asOfTime)
        {
            KeyValuePair <string, Node> head = graph.First();
            ArrayList visited = new ArrayList();

            while (head.IsNotNull() && head.Key != toAccount && head.Value.Timestamp <= asOfTime)
            {
                visited.Add(head.Key);
                var adjacentNodes = graph.Where(x => head.Value.AdjacentNodes.Contains(x.Key));
                head = (from p in adjacentNodes
                        where (p.Value.AdjacentNodes.Contains(toAccount) || p.Value.AdjacentNodes.Any()) &&
                        !visited.Contains(p.Key)
                        orderby p.Value.Timestamp descending
                        select p).FirstOrDefault();
            }

            return(visited);
        }
Beispiel #3
0
 /// <summary>
 /// 根据会话ID获取会话对象
 /// </summary>
 /// <param name="SessionID"></param>
 /// <returns></returns>
 public IUserSession <T> GetUserSession(Guid SessionID)
 {
     if (Options.IsSqlSaveCookie)
     {
         return(null);
     }
     else
     {
         KeyValuePair <string, object> item = UserSessions.First(p => ((IUserSession <T>)(p.Value)).SessionID == SessionID);
         if (item.IsNotNull())
         {
             return(item.Value as IUserSession <T>);
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #4
0
 public static void SetSessionData(string sessionId, string key, object value)
 {
     lock (_threadLock)
     {
         Session session = _sessions.Value.FirstOrDefault(s => s.SessionId == sessionId);
         if (session.IsNotNull())
         {
             KeyValuePair <string, object> kv = session._values.Value.FirstOrDefault(v => v.Key == key);
             if (kv.IsNotNull())
             {
                 session._values.Value.Remove(kv);
             }
             session._values.Value.Add(new KeyValuePair <string, object>(key, value));
         }
         else
         {
             throw new InvalidSessionIdException("Session doesn't exist or was released");
         }
     }
 }