aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Session/SessionManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Session/SessionManager.cs')
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs112
1 files changed, 60 insertions, 52 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index 7321e9f86..b03345e03 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -1,13 +1,22 @@
-using MediaBrowser.Common.Events;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
+using MediaBrowser.Controller.Authentication;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Devices;
@@ -15,21 +24,11 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Library;
-using Microsoft.Extensions.Logging;
+using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Session;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Threading;
-using MediaBrowser.Model.Extensions;
-using MediaBrowser.Controller.Authentication;
+using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Session
{
@@ -91,10 +90,24 @@ namespace Emby.Server.Implementations.Session
public event EventHandler<SessionEventArgs> SessionEnded;
public event EventHandler<SessionEventArgs> SessionActivity;
- public SessionManager(IUserDataManager userDataManager, ILogger logger, ILibraryManager libraryManager, IUserManager userManager, IMusicManager musicManager, IDtoService dtoService, IImageProcessor imageProcessor, IJsonSerializer jsonSerializer, IServerApplicationHost appHost, IHttpClient httpClient, IAuthenticationRepository authRepo, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, ITimerFactory timerFactory)
+ public SessionManager(
+ IUserDataManager userDataManager,
+ ILoggerFactory loggerFactory,
+ ILibraryManager libraryManager,
+ IUserManager userManager,
+ IMusicManager musicManager,
+ IDtoService dtoService,
+ IImageProcessor imageProcessor,
+ IJsonSerializer jsonSerializer,
+ IServerApplicationHost appHost,
+ IHttpClient httpClient,
+ IAuthenticationRepository authRepo,
+ IDeviceManager deviceManager,
+ IMediaSourceManager mediaSourceManager,
+ ITimerFactory timerFactory)
{
_userDataManager = userDataManager;
- _logger = logger;
+ _logger = loggerFactory.CreateLogger(nameof(SessionManager));
_libraryManager = libraryManager;
_userManager = userManager;
_musicManager = musicManager;
@@ -148,10 +161,7 @@ namespace Emby.Server.Implementations.Session
/// Gets all connections.
/// </summary>
/// <value>All connections.</value>
- public IEnumerable<SessionInfo> Sessions
- {
- get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate).ToList(); }
- }
+ public IEnumerable<SessionInfo> Sessions => _activeConnections.Values.OrderByDescending(c => c.LastActivityDate).ToList();
private void OnSessionStarted(SessionInfo info)
{
@@ -205,8 +215,8 @@ namespace Emby.Server.Implementations.Session
/// <param name="remoteEndPoint">The remote end point.</param>
/// <param name="user">The user.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">user</exception>
- /// <exception cref="System.UnauthorizedAccessException"></exception>
+ /// <exception cref="ArgumentNullException">user</exception>
+ /// <exception cref="UnauthorizedAccessException"></exception>
public SessionInfo LogSessionActivity(string appName,
string appVersion,
string deviceId,
@@ -218,15 +228,15 @@ namespace Emby.Server.Implementations.Session
if (string.IsNullOrEmpty(appName))
{
- throw new ArgumentNullException("appName");
+ throw new ArgumentNullException(nameof(appName));
}
if (string.IsNullOrEmpty(appVersion))
{
- throw new ArgumentNullException("appVersion");
+ throw new ArgumentNullException(nameof(appVersion));
}
if (string.IsNullOrEmpty(deviceId))
{
- throw new ArgumentNullException("deviceId");
+ throw new ArgumentNullException(nameof(deviceId));
}
var activityDate = DateTime.UtcNow;
@@ -269,8 +279,7 @@ namespace Emby.Server.Implementations.Session
{
var key = GetSessionKey(session.Client, session.DeviceId);
- SessionInfo removed;
- _activeConnections.TryRemove(key, out removed);
+ _activeConnections.TryRemove(key, out var removed);
OnSessionEnded(session);
}
@@ -285,8 +294,7 @@ namespace Emby.Server.Implementations.Session
{
var key = GetSessionKey(session.Client, session.DeviceId);
- SessionInfo removed;
- _activeConnections.TryRemove(key, out removed);
+ _activeConnections.TryRemove(key, out var removed);
OnSessionEnded(session);
}
@@ -369,7 +377,7 @@ namespace Emby.Server.Implementations.Session
/// Removes the now playing item id.
/// </summary>
/// <param name="session">The session.</param>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
private void RemoveNowPlayingItem(SessionInfo session)
{
session.NowPlayingItem = null;
@@ -381,7 +389,7 @@ namespace Emby.Server.Implementations.Session
}
}
- private string GetSessionKey(string appName, string deviceId)
+ private static string GetSessionKey(string appName, string deviceId)
{
return appName + deviceId;
}
@@ -402,13 +410,13 @@ namespace Emby.Server.Implementations.Session
if (string.IsNullOrEmpty(deviceId))
{
- throw new ArgumentNullException("deviceId");
+ throw new ArgumentNullException(nameof(deviceId));
}
var key = GetSessionKey(appName, deviceId);
CheckDisposed();
- SessionInfo sessionInfo = _activeConnections.GetOrAdd(key, k =>
+ var sessionInfo = _activeConnections.GetOrAdd(key, k =>
{
return CreateSession(k, appName, appVersion, deviceId, deviceName, remoteEndPoint, user);
});
@@ -575,14 +583,14 @@ namespace Emby.Server.Implementations.Session
/// </summary>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">info</exception>
+ /// <exception cref="ArgumentNullException">info</exception>
public async Task OnPlaybackStart(PlaybackStartInfo info)
{
CheckDisposed();
if (info == null)
{
- throw new ArgumentNullException("info");
+ throw new ArgumentNullException(nameof(info));
}
var session = GetSession(info.SessionId);
@@ -631,7 +639,7 @@ namespace Emby.Server.Implementations.Session
/// <summary>
/// Called when [playback start].
/// </summary>
- /// <param name="userId">The user identifier.</param>
+ /// <param name="user">The user object.</param>
/// <param name="item">The item.</param>
private void OnPlaybackStart(User user, BaseItem item)
{
@@ -669,7 +677,7 @@ namespace Emby.Server.Implementations.Session
if (info == null)
{
- throw new ArgumentNullException("info");
+ throw new ArgumentNullException(nameof(info));
}
var session = GetSession(info.SessionId);
@@ -742,7 +750,7 @@ namespace Emby.Server.Implementations.Session
}
- private bool UpdatePlaybackSettings(User user, PlaybackProgressInfo info, UserItemData data)
+ private static bool UpdatePlaybackSettings(User user, PlaybackProgressInfo info, UserItemData data)
{
var changed = false;
@@ -788,20 +796,20 @@ namespace Emby.Server.Implementations.Session
/// </summary>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">info</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
+ /// <exception cref="ArgumentNullException">info</exception>
+ /// <exception cref="ArgumentOutOfRangeException">positionTicks</exception>
public async Task OnPlaybackStopped(PlaybackStopInfo info)
{
CheckDisposed();
if (info == null)
{
- throw new ArgumentNullException("info");
+ throw new ArgumentNullException(nameof(info));
}
if (info.PositionTicks.HasValue && info.PositionTicks.Value < 0)
{
- throw new ArgumentOutOfRangeException("positionTicks");
+ throw new ArgumentOutOfRangeException(nameof(info), "The PlaybackStopInfo's PositionTicks was negative.");
}
var session = GetSession(info.SessionId);
@@ -993,7 +1001,7 @@ namespace Emby.Server.Implementations.Session
return SendMessageToSession(session, "GeneralCommand", command, cancellationToken);
}
- private async Task SendMessageToSession<T>(SessionInfo session, string name, T data, CancellationToken cancellationToken)
+ private static async Task SendMessageToSession<T>(SessionInfo session, string name, T data, CancellationToken cancellationToken)
{
var controllers = session.SessionControllers.ToArray();
var messageId = Guid.NewGuid().ToString("N");
@@ -1192,11 +1200,11 @@ namespace Emby.Server.Implementations.Session
{
if (session == null)
{
- throw new ArgumentNullException("session");
+ throw new ArgumentNullException(nameof(session));
}
if (controllingSession == null)
{
- throw new ArgumentNullException("controllingSession");
+ throw new ArgumentNullException(nameof(controllingSession));
}
}
@@ -1288,8 +1296,8 @@ namespace Emby.Server.Implementations.Session
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <param name="userId">The user identifier.</param>
- /// <exception cref="System.UnauthorizedAccessException">Cannot modify additional users without authenticating first.</exception>
- /// <exception cref="System.ArgumentException">The requested user is already the primary user of the session.</exception>
+ /// <exception cref="UnauthorizedAccessException">Cannot modify additional users without authenticating first.</exception>
+ /// <exception cref="ArgumentException">The requested user is already the primary user of the session.</exception>
public void AddAdditionalUser(string sessionId, Guid userId)
{
CheckDisposed();
@@ -1322,8 +1330,8 @@ namespace Emby.Server.Implementations.Session
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <param name="userId">The user identifier.</param>
- /// <exception cref="System.UnauthorizedAccessException">Cannot modify additional users without authenticating first.</exception>
- /// <exception cref="System.ArgumentException">The requested user is already the primary user of the session.</exception>
+ /// <exception cref="UnauthorizedAccessException">Cannot modify additional users without authenticating first.</exception>
+ /// <exception cref="ArgumentException">The requested user is already the primary user of the session.</exception>
public void RemoveAdditionalUser(string sessionId, Guid userId)
{
CheckDisposed();
@@ -1490,7 +1498,7 @@ namespace Emby.Server.Implementations.Session
if (string.IsNullOrEmpty(accessToken))
{
- throw new ArgumentNullException("accessToken");
+ throw new ArgumentNullException(nameof(accessToken));
}
var existing = _authRepo.Get(new AuthenticationInfoQuery
@@ -1611,7 +1619,7 @@ namespace Emby.Server.Implementations.Session
{
if (item == null)
{
- throw new ArgumentNullException("item");
+ throw new ArgumentNullException(nameof(item));
}
var dtoOptions = _itemInfoDtoOptions;
@@ -1684,7 +1692,7 @@ namespace Emby.Server.Implementations.Session
{
if (string.IsNullOrEmpty(itemId))
{
- throw new ArgumentNullException("itemId");
+ throw new ArgumentNullException(nameof(itemId));
}
//var item = _libraryManager.GetItemById(new Guid(itemId));
@@ -1726,7 +1734,7 @@ namespace Emby.Server.Implementations.Session
{
if (info == null)
{
- throw new ArgumentNullException("info");
+ throw new ArgumentNullException(nameof(info));
}
var user = info.UserId.Equals(Guid.Empty)