From bae89ee8243fea06ba1e17c1f1ed6da890e9f08c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 16 Mar 2013 12:41:49 -0400 Subject: fix duplicate connections on the dashboard --- .../Library/UserManager.cs | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/UserManager.cs') diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 01a745e95..1ebf99b6a 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -25,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The _active connections /// - private readonly ConcurrentBag _activeConnections = - new ConcurrentBag(); + private readonly List _activeConnections = + new List(); /// /// The _users @@ -67,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets all connections. /// /// All connections. - private IEnumerable AllConnections + public IEnumerable AllConnections { get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); } } @@ -76,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Gets the active connections. /// /// The active connections. - public IEnumerable ConnectedUsers + public IEnumerable RecentConnections { get { return AllConnections.Where(c => (DateTime.UtcNow - c.LastActivityDate).TotalMinutes <= 10); } } @@ -303,22 +303,29 @@ namespace MediaBrowser.Server.Implementations.Library /// ClientConnectionInfo. private ClientConnectionInfo GetConnection(Guid userId, ClientType clientType, string deviceId, string deviceName) { - var conn = _activeConnections.FirstOrDefault(c => c.UserId == userId && c.ClientType == clientType && string.Equals(deviceId, c.DeviceId)); - - if (conn == null) + lock (_activeConnections) { - conn = new ClientConnectionInfo + var conn = _activeConnections.FirstOrDefault(c => c.ClientType == clientType && string.Equals(deviceId, c.DeviceId)); + + if (conn == null) { - UserId = userId, - ClientType = clientType, - DeviceName = deviceName, - DeviceId = deviceId - }; + conn = new ClientConnectionInfo + { + UserId = userId, + ClientType = clientType, + DeviceName = deviceName, + DeviceId = deviceId + }; - _activeConnections.Add(conn); - } + _activeConnections.Add(conn); + } + else + { + conn.UserId = userId; + } - return conn; + return conn; + } } /// -- cgit v1.2.3