Ejemplo n.º 1
0
        public SessionManagerHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string path)
            : base(fileHandlerFactoryLocator)
        {
            this.persistedSessionDatas = new PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>>(
                path,
                () => new Dictionary<ID<ISession, Guid>, SessionData>(),
                this.Deserialize,
                this.Serialize);

            me = this;

            this.persistedSessionDatas.Read(sessionDatas =>
            {
                this.sessions = new Dictionary<ID<ISession, Guid>, Session>(sessionDatas.Count);

                foreach (var sessionDataKVP in sessionDatas)
                {
                    var sessionId = sessionDataKVP.Key;
                    var sessionData = sessionDataKVP.Value;

                    this.sessions[sessionId] = new Session(
                        this,
                        fileHandlerFactoryLocator,
                        this.persistedSessionDatas,
                        sessionId,
                        sessionData);
                }
            });

            // Clean old sessions every hour or so
            this.cleanOldSessionsTimer = new Timer(CleanOldSessions, null, 0, 6000000);
        }
Ejemplo n.º 2
0
        public Session(
			SessionManagerHandler sessionManagerHandler, 
			FileHandlerFactoryLocator fileHandlerFactoryLocator,
			PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>> persistedSessionDatas,
			ID<ISession, Guid> sessionId,
			SessionData sessionData)
        {
            this.sessionManagerHandler = sessionManagerHandler;
            this.fileHandlerFactoryLocator = fileHandlerFactoryLocator;
            this.persistedSessionDatas = persistedSessionDatas;
            this.sessionId = sessionId;

            this.maxAge = sessionData.maxAge;
            this.lastQuery = sessionData.lastQuery;
            this.keepAlive = sessionData.keepAlive;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// When this object is disposed, it removes the static reference so it can be GCed
        /// </summary>
        public override void Dispose()
        {
            if (this == me)
                me = null;

            this.cleanOldSessionsTimer.Dispose();

            base.Dispose();
        }