From 23c8a91976922ca73a62910090881e677dc4f4f8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Apr 2013 15:48:01 -0400 Subject: moved display preferences repo off of the kernel --- MediaBrowser.ServerApplication/ApplicationHost.cs | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.ServerApplication') diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index c782eac188..7fef4935d7 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -220,6 +220,7 @@ namespace MediaBrowser.ServerApplication RegisterSingleInstance(() => new LuceneSearchEngine()); + await ConfigureRepositories().ConfigureAwait(false); SetKernelProperties(); SetStaticProperties(); } @@ -235,7 +236,6 @@ namespace MediaBrowser.ServerApplication Parallel.Invoke( () => ServerKernel.UserDataRepositories = GetExports(), () => ServerKernel.UserRepositories = GetExports(), - () => ServerKernel.DisplayPreferencesRepositories = GetExports(), () => ServerKernel.ItemRepositories = GetExports(), () => ServerKernel.WeatherProviders = GetExports(), () => ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray(), @@ -243,6 +243,21 @@ namespace MediaBrowser.ServerApplication ); } + /// + /// Configures the repositories. + /// + /// Task. + private async Task ConfigureRepositories() + { + var displayPreferencesRepositories = GetExports(); + + var repo = GetRepository(displayPreferencesRepositories, ServerConfigurationManager.Configuration.DisplayPreferencesRepository); + + await repo.Initialize().ConfigureAwait(false); + + ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repo; + } + /// /// Dirty hacks /// @@ -456,5 +471,21 @@ namespace MediaBrowser.ServerApplication process.WaitForExit(); } } + + /// + /// Gets the repository. + /// + /// + /// The repositories. + /// The name. + /// ``0. + private T GetRepository(IEnumerable 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(); + } } } -- cgit v1.2.3