diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-03-25 00:59:49 -0400 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-03-25 00:59:49 -0400 |
| commit | aa079120059699f4778d80f55e68883d75d26b3a (patch) | |
| tree | 90ef957908152d11333fde96b95d609309560bb2 /MediaBrowser.Server.Implementations/Session/SessionManager.cs | |
| parent | 9926be0d9de688c04065c916e44ada4177b38a80 (diff) | |
| parent | 29b6ee4b6f336f08807a7ed7bdb22a1ef68269c0 (diff) | |
Merge pull request #1051 from MediaBrowser/dev
3.0.5557.20000 Beta
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/SessionManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Session/SessionManager.cs | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 5ea970426..f88e21aea 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -236,34 +236,44 @@ namespace MediaBrowser.Server.Implementations.Session } var activityDate = DateTime.UtcNow; - var session = await GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndPoint, user).ConfigureAwait(false); - + var lastActivityDate = session.LastActivityDate; session.LastActivityDate = activityDate; - if (user == null) + if (user != null) { - return session; - } - - var lastActivityDate = user.LastActivityDate; + var userLastActivityDate = user.LastActivityDate ?? DateTime.MinValue; + user.LastActivityDate = activityDate; - user.LastActivityDate = activityDate; + // Don't log in the db anymore frequently than 10 seconds + if ((activityDate - userLastActivityDate).TotalSeconds > 10) + { + try + { + // Save this directly. No need to fire off all the events for this. + await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.ErrorException("Error updating user", ex); + } + } + } - // Don't log in the db anymore frequently than 10 seconds - if (lastActivityDate.HasValue && (activityDate - lastActivityDate.Value).TotalSeconds < 10) + if ((activityDate - lastActivityDate).TotalSeconds > 10) { - return session; - } + EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + { + SessionInfo = session - // Save this directly. No need to fire off all the events for this. - await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); + }, _logger); + } - EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + var controller = session.SessionController; + if (controller != null) { - SessionInfo = session - - }, _logger); + controller.OnActivity(); + } return session; } @@ -1680,7 +1690,7 @@ namespace MediaBrowser.Server.Implementations.Session deviceId = info.DeviceId; } - return GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndpoint, user); + return LogSessionActivity(appName, appVersion, deviceId, deviceName, remoteEndpoint, user); } public Task<SessionInfo> GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint) |
