Merge pull request #2097 from jose-pr/IsolateRepos

Manage repositories only through their managers
pull/702/head
Luke 8 years ago committed by GitHub
commit 460e3635fd

@ -41,12 +41,7 @@ namespace MediaBrowser.Server.Implementations.Session
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataManager _userDataRepository;
/// <summary>
/// The _user repository
/// </summary>
private readonly IUserRepository _userRepository;
private readonly IUserDataManager _userDataManager;
/// <summary>
/// The _logger
@ -99,11 +94,10 @@ namespace MediaBrowser.Server.Implementations.Session
private readonly SemaphoreSlim _sessionLock = new SemaphoreSlim(1, 1);
public SessionManager(IUserDataManager userDataRepository, ILogger logger, IUserRepository userRepository, ILibraryManager libraryManager, IUserManager userManager, IMusicManager musicManager, IDtoService dtoService, IImageProcessor imageProcessor, IJsonSerializer jsonSerializer, IServerApplicationHost appHost, IHttpClient httpClient, IAuthenticationRepository authRepo, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager)
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)
{
_userDataRepository = userDataRepository;
_userDataManager = userDataManager;
_logger = logger;
_userRepository = userRepository;
_libraryManager = libraryManager;
_userManager = userManager;
_musicManager = musicManager;
@ -253,8 +247,7 @@ namespace MediaBrowser.Server.Implementations.Session
{
try
{
// Save this directly. No need to fire off all the events for this.
await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
await _userManager.UpdateUser(user).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -636,7 +629,7 @@ namespace MediaBrowser.Server.Implementations.Session
/// <returns>Task.</returns>
private async Task OnPlaybackStart(Guid userId, IHasUserData item)
{
var data = _userDataRepository.GetUserData(userId, item);
var data = _userDataManager.GetUserData(userId, item);
data.PlayCount++;
data.LastPlayedDate = DateTime.UtcNow;
@ -646,7 +639,7 @@ namespace MediaBrowser.Server.Implementations.Session
data.Played = true;
}
await _userDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);
await _userDataManager.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);
}
/// <summary>
@ -713,17 +706,17 @@ namespace MediaBrowser.Server.Implementations.Session
private async Task OnPlaybackProgress(User user, BaseItem item, PlaybackProgressInfo info)
{
var data = _userDataRepository.GetUserData(user.Id, item);
var data = _userDataManager.GetUserData(user.Id, item);
var positionTicks = info.PositionTicks;
if (positionTicks.HasValue)
{
_userDataRepository.UpdatePlayState(item, data, positionTicks.Value);
_userDataManager.UpdatePlayState(item, data, positionTicks.Value);
UpdatePlaybackSettings(user, info, data);
await _userDataRepository.SaveUserData(user.Id, item, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
await _userDataManager.SaveUserData(user.Id, item, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
}
}
@ -849,11 +842,11 @@ namespace MediaBrowser.Server.Implementations.Session
if (!playbackFailed)
{
var data = _userDataRepository.GetUserData(userId, item);
var data = _userDataManager.GetUserData(userId, item);
if (positionTicks.HasValue)
{
playedToCompletion = _userDataRepository.UpdatePlayState(item, data, positionTicks.Value);
playedToCompletion = _userDataManager.UpdatePlayState(item, data, positionTicks.Value);
}
else
{
@ -864,7 +857,7 @@ namespace MediaBrowser.Server.Implementations.Session
playedToCompletion = true;
}
await _userDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
await _userDataManager.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
}
return playedToCompletion;

@ -435,7 +435,6 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(UserDataManager);
UserRepository = await GetUserRepository().ConfigureAwait(false);
RegisterSingleInstance(UserRepository);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths, NativeApp.GetDbConnector());
DisplayPreferencesRepository = displayPreferencesRepo;
@ -517,7 +516,7 @@ namespace MediaBrowser.Server.Startup.Common
MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager, UserDataManager);
RegisterSingleInstance(MediaSourceManager);
SessionManager = new SessionManager(UserDataManager, LogManager.GetLogger("SessionManager"), UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager);
SessionManager = new SessionManager(UserDataManager, LogManager.GetLogger("SessionManager"), LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager);
RegisterSingleInstance(SessionManager);
var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LogManager.GetLogger("Dlna"), JsonSerializer, this);

@ -67,9 +67,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Nat", "Mono.Nat\Mono.Nat.csproj", "{D7453B88-2266-4805-B39B-2B5A2A33E1BA}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms

Loading…
Cancel
Save