public void GetOnlineUsers() { if (m_Status != "online") { return; } UsersOnline.Clear(); DateTime _utcnow = DateTime.UtcNow; string _currentuser = m_PlacePath + SUtils.currentUserName + ".online"; StreamWriter sw = null; try { if (File.Exists(_currentuser)) { sw = new StreamWriter(_currentuser); } else { sw = new StreamWriter(File.Create(_currentuser)); } sw.Write(_utcnow.ToString(), false); // false = overwrite sw.Close(); } catch { } // TODO string[] files = Directory.GetFiles(m_PlacePath, "*.online"); for (int i = 0; i < files.Count(); i++) { if (files[i] == _currentuser) { continue; } string _user = Path.GetFileNameWithoutExtension(files[i]); try { StreamReader sr = new StreamReader(files[i]); DateTime _time = Convert.ToDateTime(sr.ReadLine()).AddMinutes(10); sr.Close(); if (_time < _utcnow) { File.Delete(files[i]); // user will be removed via Watcher } else { UsersOnline.Add(_user); } } catch { } // TODO } }
public void AddUser(string userName, string ConnectionId) { UsersOnline.Add(userName, ConnectionId); UsersConnections.Add(ConnectionId, userName); }