コード例 #1
0
ファイル: ChatServer.cs プロジェクト: LYP951018/FunnyThings
 public void AddRecord(int userId, UserRecord record)
 {
     _rwLock.EnterWriteLock();
     if (!_userRecords.ContainsKey(userId))
         _userRecords.Add(userId, record);
     _rwLock.ExitWriteLock();
 }
コード例 #2
0
ファイル: UserRecord.cs プロジェクト: LYP951018/FunnyThings
 public UserRecord(UserRecord record)
 {
     LastHeartBeatTime = record.LastHeartBeatTime;
     Client = record.Client;
     UserId = record.UserId;
     IsOnline = record.IsOnline;
 }
コード例 #3
0
ファイル: ChatServer.cs プロジェクト: LYP951018/FunnyThings
 public UserRecord QueryRecord(int userId)
 {
     UserRecord record;
     _rwLock.EnterReadLock();
     record = new UserRecord(_userRecords[userId]);
     _rwLock.ExitReadLock();
     return record;
 }
コード例 #4
0
ファイル: ChatServer.cs プロジェクト: LYP951018/FunnyThings
        //public void SetOnlineStatus(int userId, bool isOnline)
        //{
        //    var record = GetRecordByRef(userId);
        //    _rwLock.EnterWriteLock();
        //    record.IsOnline = isOnline;
        //    _rwLock.ExitWriteLock();
        //}

        //public void SetOnline(int userId)
        //{
        //    SetOnlineStatus(userId, true);
        //}

        //public void SetOffline(int userId)
        //{
        //    SetOnlineStatus(userId, false);
        //}

        private void AddHeartBeat(int userId)
        {
            _rwLock.EnterWriteLock();
            UserRecord record = null;

            _userRecords.TryGetValue(userId, out record);
            if (record != null)
            {
                record.LastHeartBeatTime += TimeSpan.FromSeconds(5);
            }
            _rwLock.ExitWriteLock();
        }
コード例 #5
0
ファイル: ChatServer.cs プロジェクト: LYP951018/FunnyThings
        private TcpClient GetClient(int userId)
        {
            UserRecord record = null;

            _rwLock.EnterReadLock();
            try
            {
                if (_userRecords.TryGetValue(userId, out record))
                {
                    return(record.Client);
                }
            }
            finally
            {
                _rwLock.ExitReadLock();
            }
            return(null);
        }
コード例 #6
0
ファイル: DbManager.cs プロジェクト: radtek/PDS_Server
        /*
         * method to perform logout operation
         *
         */
        public static void Logout(string clientID)
        {
            if (clientID.Length <= 0)
            {
                throw new Exception("[LOGOUT] invalid input parameters");
            }

            using (var db = new LiteDatabase(DB_PATH))
            {
                using (db.BeginTrans())
                {
                    // Get a collection (or create, if doesn't exist)
                    LiteCollection <UserRecord> userCollection = db.GetCollection <UserRecord>(DB_USERS);

                    // Index document using document userID property
                    userCollection.EnsureIndex(x => x.UserID);

                    // Index document using document userID property
                    userCollection.EnsureIndex(x => x.UserID);
                    clientID = clientID.ToLower();

                    //find record with selected userID(case insensitive)
                    IEnumerable <UserRecord> results = userCollection.Find(x => x.UserID.Equals(clientID));

                    if (results.LongCount <UserRecord>() <= 0)
                    {
                        throw new Exception("[LOGOUT] clientID does not exist");
                    }

                    //LOGOUT PROCEDURE: update user record (sessionID = "empty")
                    UserRecord loggedUser = results.ElementAt <UserRecord>(0);

                    UserRecord updatedUserRecord = new UserRecord(loggedUser.UserID, loggedUser.Password, SESSIONID_NULL);

                    userCollection.Update(loggedUser.Id, updatedUserRecord);
                }
            }
        }