Logout() public méthode

public Logout ( ) : void
Résultat void
Exemple #1
0
        public void Stop(bool force)
        {
            if (IsStopped)
            {
                return;
            }

            List <Session> enabledSessions = new List <Session>();

            lock (sync_)
            {
                foreach (SessionID sessionID in connected_)
                {
                    Session session = Session.LookupSession(sessionID);
                    if (session.IsEnabled)
                    {
                        enabledSessions.Add(session);
                        session.Logout();
                    }
                }
            }

            if (!force)
            {
                for (int second = 0; (second < 10) && IsLoggedOn(); ++second)
                {
                    Thread.Sleep(1000);
                }
            }

            lock (sync_)
            {
                HashSet <SessionID> connectedSessionIDs = new HashSet <SessionID>(connected_);
                foreach (SessionID sessionID in connectedSessionIDs)
                {
                    SetDisconnected(Session.LookupSession(sessionID).SessionID);
                }
            }

            isStopped_ = true;
            OnStop();
            thread_.Join(5000);
            thread_ = null;

            foreach (Session session in enabledSessions)
            {
                session.Logon();
            }
        }
Exemple #2
0
        /// <summary>
        /// Logout existing session and close connection
        /// </summary>
        /// <param name="force">If true, terminate immediately.  </param>
        public void Stop(bool force)
        {
            if (_disposed)
            {
                throw new System.ObjectDisposedException(this.GetType().Name);
            }

            if (IsStopped)
            {
                return;
            }

            List <Session> enabledSessions = new List <Session>();

            lock (sync_)
            {
                foreach (SessionID sessionID in connected_)
                {
                    Session session = Session.LookupSession(sessionID);
                    if (session.IsEnabled)
                    {
                        enabledSessions.Add(session);
                        session.Logout();
                    }
                }
            }

            if (!force)
            {
                // TODO change this duration to always exceed LogoutTimeout setting
                for (int second = 0; (second < 10) && IsLoggedOn; ++second)
                {
                    Thread.Sleep(1000);
                }
            }

            lock (sync_)
            {
                HashSet <SessionID> connectedSessionIDs = new HashSet <SessionID>(connected_);
                foreach (SessionID sessionID in connectedSessionIDs)
                {
                    SetDisconnected(Session.LookupSession(sessionID).SessionID);
                }
            }

            isStopped_ = true;
            OnStop();

            // Give OnStop() time to finish its business
            thread_.Join(5000);
            thread_ = null;

            // dispose all sessions and clear all session sets
            lock (sync_)
            {
                foreach (Session s in sessions_.Values)
                {
                    s.Dispose();
                }

                sessions_.Clear();
                sessionIDs_.Clear();
                pending_.Clear();
                connected_.Clear();
                disconnected_.Clear();
            }
        }