From 4d083b618dab11f3f2e6f54c149592de2fc16562 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 16 Mar 2013 01:52:33 -0400 Subject: restored request logging --- .../Library/UserManager.cs | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 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 8928ed238..01a745e95 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -62,7 +62,7 @@ namespace MediaBrowser.Server.Implementations.Library } } } - + /// /// Gets all connections. /// @@ -71,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library { get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); } } - + /// /// Gets the active connections. /// @@ -172,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.Library return Users.FirstOrDefault(u => u.Id == id); } - + /// /// Authenticates a User and returns a result indicating whether or not it succeeded /// @@ -222,10 +222,11 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The user. /// Type of the client. + /// The device id. /// Name of the device. /// Task. /// user - public Task LogUserActivity(User user, ClientType clientType, string deviceName) + public Task LogUserActivity(User user, ClientType clientType, string deviceId, string deviceName) { if (user == null) { @@ -236,7 +237,7 @@ namespace MediaBrowser.Server.Implementations.Library user.LastActivityDate = activityDate; - LogConnection(user.Id, clientType, deviceName, activityDate); + LogConnection(user.Id, clientType, deviceId, deviceName, activityDate); // Save this directly. No need to fire off all the events for this. return Kernel.UserRepository.SaveUser(user, CancellationToken.None); @@ -247,15 +248,17 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The user. /// Type of the client. + /// The device id. /// Name of the device. /// The item. /// The current position ticks. - private void UpdateNowPlayingItemId(User user, ClientType clientType, string deviceName, BaseItem item, long? currentPositionTicks = null) + private void UpdateNowPlayingItemId(User user, ClientType clientType, string deviceId, string deviceName, BaseItem item, long? currentPositionTicks = null) { - var conn = GetConnection(user.Id, clientType, deviceName); + var conn = GetConnection(user.Id, clientType, deviceId, deviceName); conn.NowPlayingPositionTicks = currentPositionTicks; conn.NowPlayingItem = DtoBuilder.GetBaseItemInfo(item); + conn.LastActivityDate = DateTime.UtcNow; } /// @@ -263,11 +266,12 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The user. /// Type of the client. + /// The device id. /// Name of the device. /// The item. - private void RemoveNowPlayingItemId(User user, ClientType clientType, string deviceName, BaseItem item) + private void RemoveNowPlayingItemId(User user, ClientType clientType, string deviceId, string deviceName, BaseItem item) { - var conn = GetConnection(user.Id, clientType, deviceName); + var conn = GetConnection(user.Id, clientType, deviceId, deviceName); if (conn.NowPlayingItem != null && conn.NowPlayingItem.Id.Equals(item.Id.ToString())) { @@ -281,11 +285,12 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The user id. /// Type of the client. + /// The device id. /// Name of the device. /// The last activity date. - private void LogConnection(Guid userId, ClientType clientType, string deviceName, DateTime lastActivityDate) + private void LogConnection(Guid userId, ClientType clientType, string deviceId, string deviceName, DateTime lastActivityDate) { - GetConnection(userId, clientType, deviceName).LastActivityDate = lastActivityDate; + GetConnection(userId, clientType, deviceId, deviceName).LastActivityDate = lastActivityDate; } /// @@ -293,11 +298,12 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The user id. /// Type of the client. + /// The device id. /// Name of the device. /// ClientConnectionInfo. - private ClientConnectionInfo GetConnection(Guid userId, ClientType clientType, string deviceName) + private ClientConnectionInfo GetConnection(Guid userId, ClientType clientType, string deviceId, string deviceName) { - var conn = _activeConnections.FirstOrDefault(c => c.UserId == userId && c.ClientType == clientType && string.Equals(deviceName, c.DeviceName, StringComparison.OrdinalIgnoreCase)); + var conn = _activeConnections.FirstOrDefault(c => c.UserId == userId && c.ClientType == clientType && string.Equals(deviceId, c.DeviceId)); if (conn == null) { @@ -305,7 +311,8 @@ namespace MediaBrowser.Server.Implementations.Library { UserId = userId, ClientType = clientType, - DeviceName = deviceName + DeviceName = deviceName, + DeviceId = deviceId }; _activeConnections.Add(conn); @@ -524,9 +531,10 @@ namespace MediaBrowser.Server.Implementations.Library /// The user. /// The item. /// Type of the client. + /// The device id. /// Name of the device. /// - public void OnPlaybackStart(User user, BaseItem item, ClientType clientType, string deviceName) + public void OnPlaybackStart(User user, BaseItem item, ClientType clientType, string deviceId, string deviceName) { if (user == null) { @@ -537,7 +545,7 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException(); } - UpdateNowPlayingItemId(user, clientType, deviceName, item); + UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item); // Nothing to save here // Fire events to inform plugins @@ -555,10 +563,11 @@ namespace MediaBrowser.Server.Implementations.Library /// The item. /// The position ticks. /// Type of the client. + /// The device id. /// Name of the device. /// Task. /// - public async Task OnPlaybackProgress(User user, BaseItem item, long? positionTicks, ClientType clientType, string deviceName) + public async Task OnPlaybackProgress(User user, BaseItem item, long? positionTicks, ClientType clientType, string deviceId, string deviceName) { if (user == null) { @@ -569,7 +578,7 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException(); } - UpdateNowPlayingItemId(user, clientType, deviceName, item, positionTicks); + UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, positionTicks); if (positionTicks.HasValue) { @@ -594,10 +603,11 @@ namespace MediaBrowser.Server.Implementations.Library /// The item. /// The position ticks. /// Type of the client. + /// The device id. /// Name of the device. /// Task. /// - public async Task OnPlaybackStopped(User user, BaseItem item, long? positionTicks, ClientType clientType, string deviceName) + public async Task OnPlaybackStopped(User user, BaseItem item, long? positionTicks, ClientType clientType, string deviceId, string deviceName) { if (user == null) { @@ -608,7 +618,7 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException(); } - RemoveNowPlayingItemId(user, clientType, deviceName, item); + RemoveNowPlayingItemId(user, clientType, deviceId, deviceName, item); var data = item.GetUserData(user, true); -- cgit v1.2.3