moved display preferences repo off of the kernel

This commit is contained in:
Luke Pulverenti 2013-04-05 15:48:01 -04:00
parent 31c2d98532
commit 23c8a91976
3 changed files with 43 additions and 22 deletions

View File

@ -88,12 +88,6 @@ namespace MediaBrowser.Controller
/// <value>The user repository.</value>
public IUserRepository UserRepository { get; set; }
/// <summary>
/// Gets the active user repository
/// </summary>
/// <value>The display preferences repository.</value>
public IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
/// <summary>
/// Gets the list of available item repositories
/// </summary>
@ -106,12 +100,6 @@ namespace MediaBrowser.Controller
/// <value>The item repository.</value>
public IItemRepository ItemRepository { get; set; }
/// <summary>
/// Gets the list of available DisplayPreferencesRepositories
/// </summary>
/// <value>The display preferences repositories.</value>
public IEnumerable<IDisplayPreferencesRepository> DisplayPreferencesRepositories { get; set; }
/// <summary>
/// Gets the list of available item repositories
/// </summary>
@ -155,11 +143,7 @@ namespace MediaBrowser.Controller
UserDataRepository = GetRepository(UserDataRepositories, configurationManager.Configuration.UserDataRepository);
var userDataRepoTask = UserDataRepository.Initialize();
// Get the current display preferences repository
DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, configurationManager.Configuration.DisplayPreferencesRepository);
var displayPreferencesRepoTask = DisplayPreferencesRepository.Initialize();
return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask);
return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask);
}
/// <summary>

View File

@ -1,5 +1,5 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
@ -24,6 +24,12 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary>
private readonly ConcurrentDictionary<Guid, Task<DisplayPreferences>> _displayPreferences = new ConcurrentDictionary<Guid, Task<DisplayPreferences>>();
/// <summary>
/// Gets the active user repository
/// </summary>
/// <value>The display preferences repository.</value>
public IDisplayPreferencesRepository Repository { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="DisplayPreferencesManager"/> class.
/// </summary>
@ -50,7 +56,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>DisplayPreferences.</returns>
private async Task<DisplayPreferences> RetrieveDisplayPreferences(Guid displayPreferencesId)
{
var displayPreferences = await Kernel.Instance.DisplayPreferencesRepository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false);
var displayPreferences = await Repository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false);
return displayPreferences ?? new DisplayPreferences { Id = displayPreferencesId };
}
@ -74,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library
try
{
await Kernel.Instance.DisplayPreferencesRepository.SaveDisplayPreferences(displayPreferences,
await Repository.SaveDisplayPreferences(displayPreferences,
cancellationToken).ConfigureAwait(false);
var newValue = Task.FromResult(displayPreferences);

View File

@ -220,6 +220,7 @@ namespace MediaBrowser.ServerApplication
RegisterSingleInstance<ILibrarySearchEngine>(() => new LuceneSearchEngine());
await ConfigureRepositories().ConfigureAwait(false);
SetKernelProperties();
SetStaticProperties();
}
@ -235,7 +236,6 @@ namespace MediaBrowser.ServerApplication
Parallel.Invoke(
() => ServerKernel.UserDataRepositories = GetExports<IUserDataRepository>(),
() => ServerKernel.UserRepositories = GetExports<IUserRepository>(),
() => ServerKernel.DisplayPreferencesRepositories = GetExports<IDisplayPreferencesRepository>(),
() => ServerKernel.ItemRepositories = GetExports<IItemRepository>(),
() => ServerKernel.WeatherProviders = GetExports<IWeatherProvider>(),
() => ServerKernel.ImageEnhancers = GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray(),
@ -243,6 +243,21 @@ namespace MediaBrowser.ServerApplication
);
}
/// <summary>
/// Configures the repositories.
/// </summary>
/// <returns>Task.</returns>
private async Task ConfigureRepositories()
{
var displayPreferencesRepositories = GetExports<IDisplayPreferencesRepository>();
var repo = GetRepository(displayPreferencesRepositories, ServerConfigurationManager.Configuration.DisplayPreferencesRepository);
await repo.Initialize().ConfigureAwait(false);
((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repo;
}
/// <summary>
/// Dirty hacks
/// </summary>
@ -456,5 +471,21 @@ namespace MediaBrowser.ServerApplication
process.WaitForExit();
}
}
/// <summary>
/// Gets the repository.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="repositories">The repositories.</param>
/// <param name="name">The name.</param>
/// <returns>``0.</returns>
private T GetRepository<T>(IEnumerable<T> repositories, string name)
where T : class, IRepository
{
var enumerable = repositories as T[] ?? repositories.ToArray();
return enumerable.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) ??
enumerable.FirstOrDefault();
}
}
}