diff --git a/MediaBrowser.Api/DisplayPreferencesService.cs b/MediaBrowser.Api/DisplayPreferencesService.cs
index 1ea71c545e..8372ecd36b 100644
--- a/MediaBrowser.Api/DisplayPreferencesService.cs
+++ b/MediaBrowser.Api/DisplayPreferencesService.cs
@@ -12,7 +12,7 @@ namespace MediaBrowser.Api
///
/// Class UpdateDisplayPreferences
///
- [Route("/Users/{UserId}/DisplayPreferences/{Id}", "POST")]
+ [Route("/DisplayPreferences/{DisplayPreferencesId}", "POST")]
[Api(("Updates a user's display preferences for an item"))]
public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid
{
@@ -20,22 +20,19 @@ namespace MediaBrowser.Api
/// Gets or sets the id.
///
/// The id.
- [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
- public Guid Id { get; set; }
+ [ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public Guid DisplayPreferencesId { get; set; }
}
- [Route("/Users/{UserId}/DisplayPreferences/{Id}", "GET")]
+ [Route("/DisplayPreferences/{Id}", "GET")]
[Api(("Gets a user's display preferences for an item"))]
public class GetDisplayPreferences : IReturn
{
- [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
- public Guid UserId { get; set; }
-
///
/// Gets or sets the id.
///
/// The id.
- [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
}
@@ -45,23 +42,23 @@ namespace MediaBrowser.Api
public class DisplayPreferencesService : BaseApiService
{
///
- /// The _user manager
+ /// The _display preferences manager
///
- private readonly IUserManager _userManager;
+ private readonly IDisplayPreferencesManager _displayPreferencesManager;
///
/// The _json serializer
///
private readonly IJsonSerializer _jsonSerializer;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- /// The user manager.
/// The json serializer.
- public DisplayPreferencesService(IUserManager userManager, IJsonSerializer jsonSerializer)
+ /// The display preferences manager.
+ public DisplayPreferencesService(IJsonSerializer jsonSerializer, IDisplayPreferencesManager displayPreferencesManager)
{
- _userManager = userManager;
_jsonSerializer = jsonSerializer;
+ _displayPreferencesManager = displayPreferencesManager;
}
///
@@ -70,7 +67,7 @@ namespace MediaBrowser.Api
/// The request.
public object Get(GetDisplayPreferences request)
{
- var task = _userManager.GetDisplayPreferences(request.UserId, request.Id);
+ var task = _displayPreferencesManager.GetDisplayPreferences(request.Id);
return ToOptimizedResult(task.Result);
}
@@ -84,15 +81,12 @@ namespace MediaBrowser.Api
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
- var userId = new Guid(pathInfo.GetArgumentValue(1));
- var displayPreferencesId = new Guid(pathInfo.GetArgumentValue(3));
-
- var user = _userManager.GetUserById(userId);
+ var displayPreferencesId = new Guid(pathInfo.GetArgumentValue(1));
// Serialize to json and then back so that the core doesn't see the request dto type
var displayPreferences = _jsonSerializer.DeserializeFromString(_jsonSerializer.SerializeToString(request));
- var task = _userManager.SaveDisplayPreferences(user.Id, displayPreferencesId, displayPreferences, CancellationToken.None);
+ var task = _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, CancellationToken.None);
Task.WaitAll(task);
}
diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs
index c64f001c11..42c112752e 100644
--- a/MediaBrowser.Controller/Entities/CollectionFolder.cs
+++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs
@@ -1,6 +1,5 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Tasks;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -35,7 +34,7 @@ namespace MediaBrowser.Controller.Entities
/// Allow different display preferences for each collection folder
///
/// The display prefs id.
- public override Guid DisplayPreferencesId
+ protected override Guid DisplayPreferencesId
{
get
{
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 05ee87defa..ce8bf679ea 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -65,7 +65,7 @@ namespace MediaBrowser.Controller.Entities
///
/// The display prefs id.
[IgnoreDataMember]
- public virtual Guid DisplayPreferencesId
+ protected virtual Guid DisplayPreferencesId
{
get
{
@@ -74,6 +74,16 @@ namespace MediaBrowser.Controller.Entities
}
}
+ ///
+ /// Gets the display preferences id.
+ ///
+ /// The user id.
+ /// Guid.
+ public Guid GetDisplayPreferencesId(Guid userId)
+ {
+ return (userId + DisplayPreferencesId.ToString()).GetMD5();
+ }
+
#region Indexing
///
diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs
index 51d347cafc..36ebcd802e 100644
--- a/MediaBrowser.Controller/Kernel.cs
+++ b/MediaBrowser.Controller/Kernel.cs
@@ -88,12 +88,6 @@ namespace MediaBrowser.Controller
/// The user repository.
public IUserRepository UserRepository { get; set; }
- ///
- /// Gets the active user repository
- ///
- /// The display preferences repository.
- public IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
-
///
/// Gets the list of available item repositories
///
@@ -106,12 +100,6 @@ namespace MediaBrowser.Controller
/// The item repository.
public IItemRepository ItemRepository { get; set; }
- ///
- /// Gets the list of available DisplayPreferencesRepositories
- ///
- /// The display preferences repositories.
- public IEnumerable DisplayPreferencesRepositories { get; set; }
-
///
/// Gets the list of available item repositories
///
@@ -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);
}
///
diff --git a/MediaBrowser.Controller/Library/DtoBuilder.cs b/MediaBrowser.Controller/Library/DtoBuilder.cs
index fbaa59f34f..d54563e41b 100644
--- a/MediaBrowser.Controller/Library/DtoBuilder.cs
+++ b/MediaBrowser.Controller/Library/DtoBuilder.cs
@@ -174,7 +174,7 @@ namespace MediaBrowser.Controller.Library
if (item.IsFolder && fields.Contains(ItemFields.DisplayPreferencesId))
{
- dto.DisplayPreferencesId = ((Folder)item).DisplayPreferencesId.ToString();
+ dto.DisplayPreferencesId = ((Folder) item).GetDisplayPreferencesId(user.Id).ToString();
}
if (item.IsFolder)
diff --git a/MediaBrowser.Controller/Library/IDisplayPreferencesManager.cs b/MediaBrowser.Controller/Library/IDisplayPreferencesManager.cs
new file mode 100644
index 0000000000..f1d782b1d0
--- /dev/null
+++ b/MediaBrowser.Controller/Library/IDisplayPreferencesManager.cs
@@ -0,0 +1,28 @@
+using MediaBrowser.Model.Entities;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Controller.Library
+{
+ ///
+ /// Interface IDisplayPreferencesManager
+ ///
+ public interface IDisplayPreferencesManager
+ {
+ ///
+ /// Gets the display preferences.
+ ///
+ /// The display preferences id.
+ /// DisplayPreferences.
+ Task GetDisplayPreferences(Guid displayPreferencesId);
+
+ ///
+ /// Saves display preferences for an item
+ ///
+ /// The display preferences.
+ /// The cancellation token.
+ /// Task.
+ Task SaveDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken);
+ }
+}
diff --git a/MediaBrowser.Controller/Library/IUserManager.cs b/MediaBrowser.Controller/Library/IUserManager.cs
index 8eee8e447c..ad46cf7c33 100644
--- a/MediaBrowser.Controller/Library/IUserManager.cs
+++ b/MediaBrowser.Controller/Library/IUserManager.cs
@@ -1,7 +1,6 @@
using MediaBrowser.Common.Events;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Connectivity;
-using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -9,6 +8,9 @@ using System.Threading.Tasks;
namespace MediaBrowser.Controller.Library
{
+ ///
+ /// Interface IUserManager
+ ///
public interface IUserManager
{
///
@@ -173,7 +175,7 @@ namespace MediaBrowser.Controller.Library
Task ChangePassword(User user, string newPassword);
///
- /// Saves display preferences for an item
+ /// Saves the user data.
///
/// The user id.
/// The user data id.
@@ -184,29 +186,11 @@ namespace MediaBrowser.Controller.Library
CancellationToken cancellationToken);
///
- /// Gets the display preferences.
+ /// Gets the user data.
///
/// The user id.
/// The user data id.
- /// Task{DisplayPreferences}.
+ /// Task{UserItemData}.
Task GetUserData(Guid userId, Guid userDataId);
-
- ///
- /// Gets the display preferences.
- ///
- /// The user id.
- /// The display preferences id.
- /// DisplayPreferences.
- Task GetDisplayPreferences(Guid userId, Guid displayPreferencesId);
-
- ///
- /// Saves display preferences for an item
- ///
- /// The user id.
- /// The display preferences id.
- /// The display preferences.
- /// The cancellation token.
- /// Task.
- Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences, CancellationToken cancellationToken);
}
}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index 2e7a8a994f..48662fe220 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -88,6 +88,7 @@
+
diff --git a/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs b/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs
index eb43c8ca5b..9774bb68e6 100644
--- a/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs
+++ b/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs
@@ -13,20 +13,17 @@ namespace MediaBrowser.Controller.Persistence
///
/// Saves display preferences for an item
///
- /// The user id.
- /// The display preferences id.
/// The display preferences.
/// The cancellation token.
/// Task.
- Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences,
+ Task SaveDisplayPreferences(DisplayPreferences displayPreferences,
CancellationToken cancellationToken);
///
/// Gets the display preferences.
///
- /// The user id.
/// The display preferences id.
/// Task{DisplayPreferences}.
- Task GetDisplayPreferences(Guid userId, Guid displayPreferencesId);
+ Task GetDisplayPreferences(Guid displayPreferencesId);
}
}
diff --git a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs
index bc8052f0eb..7c977d02f7 100644
--- a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs
+++ b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs
@@ -93,7 +93,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
cancellationToken.ThrowIfCancellationRequested();
- await Fetch(myItem, cancellationToken, result, isoMount).ConfigureAwait(false);
+ Fetch(myItem, cancellationToken, result, isoMount);
cancellationToken.ThrowIfCancellationRequested();
@@ -180,7 +180,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// The result.
/// The iso mount.
/// Task.
- protected abstract Task Fetch(T item, CancellationToken cancellationToken, FFProbeResult result, IIsoMount isoMount);
+ protected abstract void Fetch(T item, CancellationToken cancellationToken, FFProbeResult result, IIsoMount isoMount);
///
/// Converts ffprobe stream info to our MediaStream class
diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFMpegVideoImageProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFMpegVideoImageProvider.cs
index 9dec93a8c8..bc851a0cba 100644
--- a/MediaBrowser.Controller/Providers/MediaInfo/FFMpegVideoImageProvider.cs
+++ b/MediaBrowser.Controller/Providers/MediaInfo/FFMpegVideoImageProvider.cs
@@ -57,12 +57,6 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
if (video != null)
{
- // Can't extract images if there are no video streams
- if (video.MediaStreams == null || video.MediaStreams.All(m => m.Type != MediaStreamType.Video))
- {
- return false;
- }
-
if (video.VideoType == VideoType.Iso && video.IsoType.HasValue && _isoManager.CanMount(item.Path))
{
return true;
@@ -93,17 +87,21 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
{
var video = (Video)item;
- var filename = item.Id + "_" + item.DateModified.Ticks + "_primary";
-
- var path = Kernel.Instance.FFMpegManager.VideoImageCache.GetResourcePath(filename, ".jpg");
-
- if (!Kernel.Instance.FFMpegManager.VideoImageCache.ContainsFilePath(path))
+ // We can only extract images from videos if we know there's an embedded video stream
+ if (video.MediaStreams != null && video.MediaStreams.Any(m => m.Type == MediaStreamType.Video))
{
- return ExtractImage(video, path, cancellationToken);
- }
+ var filename = item.Id + "_" + item.DateModified.Ticks + "_primary";
- // Image is already in the cache
- item.PrimaryImagePath = path;
+ var path = Kernel.Instance.FFMpegManager.VideoImageCache.GetResourcePath(filename, ".jpg");
+
+ if (!Kernel.Instance.FFMpegManager.VideoImageCache.ContainsFilePath(path))
+ {
+ return ExtractImage(video, path, cancellationToken);
+ }
+
+ // Image is already in the cache
+ item.PrimaryImagePath = path;
+ }
}
SetLastRefreshed(item, DateTime.UtcNow);
diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs
index a7cc4985b0..8390a0ceeb 100644
--- a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs
+++ b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs
@@ -42,41 +42,38 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// The data.
/// The iso mount.
/// Task.
- protected override Task Fetch(Audio audio, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
+ protected override void Fetch(Audio audio, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
- return Task.Run(() =>
+ if (data.streams == null)
{
- if (data.streams == null)
- {
- Logger.Error("Audio item has no streams: " + audio.Path);
- return;
- }
+ Logger.Error("Audio item has no streams: " + audio.Path);
+ return;
+ }
- audio.MediaStreams = data.streams.Select(s => GetMediaStream(s, data.format)).ToList();
+ audio.MediaStreams = data.streams.Select(s => GetMediaStream(s, data.format)).ToList();
- // Get the first audio stream
- var stream = data.streams.First(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));
+ // Get the first audio stream
+ var stream = data.streams.First(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));
- // Get duration from stream properties
- var duration = stream.duration;
+ // Get duration from stream properties
+ var duration = stream.duration;
- // If it's not there go into format properties
- if (string.IsNullOrEmpty(duration))
- {
- duration = data.format.duration;
- }
+ // If it's not there go into format properties
+ if (string.IsNullOrEmpty(duration))
+ {
+ duration = data.format.duration;
+ }
- // If we got something, parse it
- if (!string.IsNullOrEmpty(duration))
- {
- audio.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(duration, UsCulture)).Ticks;
- }
+ // If we got something, parse it
+ if (!string.IsNullOrEmpty(duration))
+ {
+ audio.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(duration, UsCulture)).Ticks;
+ }
- if (data.format.tags != null)
- {
- FetchDataFromTags(audio, data.format.tags);
- }
- });
+ if (data.format.tags != null)
+ {
+ FetchDataFromTags(audio, data.format.tags);
+ }
}
///
diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs
index cae74a910b..a2a9fa0d14 100644
--- a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs
+++ b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs
@@ -187,44 +187,41 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// The data.
/// The iso mount.
/// Task.
- protected override Task Fetch(Video video, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
+ protected override void Fetch(Video video, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
- return Task.Run(() =>
+ if (data.format != null)
{
- if (data.format != null)
+ // For dvd's this may not always be accurate, so don't set the runtime if the item already has one
+ var needToSetRuntime = video.VideoType != VideoType.Dvd || video.RunTimeTicks == null || video.RunTimeTicks.Value == 0;
+
+ if (needToSetRuntime && !string.IsNullOrEmpty(data.format.duration))
{
- // For dvd's this may not always be accurate, so don't set the runtime if the item already has one
- var needToSetRuntime = video.VideoType != VideoType.Dvd || video.RunTimeTicks == null || video.RunTimeTicks.Value == 0;
-
- if (needToSetRuntime && !string.IsNullOrEmpty(data.format.duration))
- {
- video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, UsCulture)).Ticks;
- }
+ video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, UsCulture)).Ticks;
}
+ }
- if (data.streams != null)
- {
- video.MediaStreams = data.streams.Select(s => GetMediaStream(s, data.format)).ToList();
- }
+ if (data.streams != null)
+ {
+ video.MediaStreams = data.streams.Select(s => GetMediaStream(s, data.format)).ToList();
+ }
- if (data.Chapters != null)
- {
- video.Chapters = data.Chapters;
- }
+ if (data.Chapters != null)
+ {
+ video.Chapters = data.Chapters;
+ }
- if (video.Chapters == null || video.Chapters.Count == 0)
- {
- AddDummyChapters(video);
- }
+ if (video.Chapters == null || video.Chapters.Count == 0)
+ {
+ AddDummyChapters(video);
+ }
- if (video.VideoType == VideoType.BluRay || (video.IsoType.HasValue && video.IsoType.Value == IsoType.BluRay))
- {
- var inputPath = isoMount != null ? isoMount.MountedPath : video.Path;
- FetchBdInfo(video, inputPath, BdInfoCache, cancellationToken);
- }
+ if (video.VideoType == VideoType.BluRay || (video.IsoType.HasValue && video.IsoType.Value == IsoType.BluRay))
+ {
+ var inputPath = isoMount != null ? isoMount.MountedPath : video.Path;
+ FetchBdInfo(video, inputPath, BdInfoCache, cancellationToken);
+ }
- AddExternalSubtitles(video);
- });
+ AddExternalSubtitles(video);
}
///
diff --git a/MediaBrowser.Model/Entities/DisplayPreferences.cs b/MediaBrowser.Model/Entities/DisplayPreferences.cs
index 7331da86d7..31edab621b 100644
--- a/MediaBrowser.Model/Entities/DisplayPreferences.cs
+++ b/MediaBrowser.Model/Entities/DisplayPreferences.cs
@@ -32,7 +32,7 @@ namespace MediaBrowser.Model.Entities
///
/// The user id.
[ProtoMember(1)]
- public Guid UserId { get; set; }
+ public Guid Id { get; set; }
///
/// Gets or sets the type of the view.
///
diff --git a/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs b/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs
new file mode 100644
index 0000000000..57a9c9d785
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs
@@ -0,0 +1,99 @@
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Logging;
+using System;
+using System.Collections.Concurrent;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Server.Implementations.Library
+{
+ ///
+ /// Class DisplayPreferencesManager
+ ///
+ public class DisplayPreferencesManager : IDisplayPreferencesManager
+ {
+ ///
+ /// The _logger
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// The _display preferences
+ ///
+ private readonly ConcurrentDictionary> _displayPreferences = new ConcurrentDictionary>();
+
+ ///
+ /// Gets the active user repository
+ ///
+ /// The display preferences repository.
+ public IDisplayPreferencesRepository Repository { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The logger.
+ public DisplayPreferencesManager(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ ///
+ /// Gets the display preferences.
+ ///
+ /// The display preferences id.
+ /// DisplayPreferences.
+ public Task GetDisplayPreferences(Guid displayPreferencesId)
+ {
+ return _displayPreferences.GetOrAdd(displayPreferencesId, keyName => RetrieveDisplayPreferences(displayPreferencesId));
+ }
+
+ ///
+ /// Retrieves the display preferences.
+ ///
+ /// The display preferences id.
+ /// DisplayPreferences.
+ private async Task RetrieveDisplayPreferences(Guid displayPreferencesId)
+ {
+ var displayPreferences = await Repository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false);
+
+ return displayPreferences ?? new DisplayPreferences { Id = displayPreferencesId };
+ }
+
+ ///
+ /// Saves display preferences for an item
+ ///
+ /// The display preferences.
+ /// The cancellation token.
+ /// Task.
+ public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken)
+ {
+ if (displayPreferences == null)
+ {
+ throw new ArgumentNullException("displayPreferences");
+ }
+ if (displayPreferences.Id == Guid.Empty)
+ {
+ throw new ArgumentNullException("displayPreferences.Id");
+ }
+
+ try
+ {
+ await Repository.SaveDisplayPreferences(displayPreferences,
+ cancellationToken).ConfigureAwait(false);
+
+ var newValue = Task.FromResult(displayPreferences);
+
+ // Once it succeeds, put it into the dictionary to make it available to everyone else
+ _displayPreferences.AddOrUpdate(displayPreferences.Id, newValue, delegate { return newValue; });
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error saving display preferences", ex);
+
+ throw;
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index c5e4de2bc1..9293d81998 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Connectivity;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Concurrent;
@@ -26,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library
///
/// The _active connections
///
- private readonly List _activeConnections =
- new List();
+ private readonly ConcurrentDictionary _activeConnections =
+ new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase);
///
/// The _users
@@ -70,7 +69,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// All connections.
public IEnumerable AllConnections
{
- get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); }
+ get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate); }
}
///
@@ -99,11 +98,6 @@ namespace MediaBrowser.Server.Implementations.Library
/// The configuration manager.
private IServerConfigurationManager ConfigurationManager { get; set; }
- ///
- /// The _user data
- ///
- private readonly ConcurrentDictionary> _displayPreferences = new ConcurrentDictionary>();
-
private readonly ConcurrentDictionary> _userData = new ConcurrentDictionary>();
///
@@ -165,63 +159,6 @@ namespace MediaBrowser.Server.Implementations.Library
}
#endregion
- ///
- /// Gets the display preferences.
- ///
- /// The user id.
- /// The display preferences id.
- /// DisplayPreferences.
- public Task GetDisplayPreferences(Guid userId, Guid displayPreferencesId)
- {
- var key = userId + displayPreferencesId.ToString();
-
- return _displayPreferences.GetOrAdd(key, keyName => RetrieveDisplayPreferences(userId, displayPreferencesId));
- }
-
- ///
- /// Retrieves the display preferences.
- ///
- /// The user id.
- /// The display preferences id.
- /// DisplayPreferences.
- private async Task RetrieveDisplayPreferences(Guid userId, Guid displayPreferencesId)
- {
- var displayPreferences = await Kernel.Instance.DisplayPreferencesRepository.GetDisplayPreferences(userId, displayPreferencesId).ConfigureAwait(false);
-
- return displayPreferences ?? new DisplayPreferences();
- }
-
- ///
- /// Saves display preferences for an item
- ///
- /// The user id.
- /// The display preferences id.
- /// The display preferences.
- /// The cancellation token.
- /// Task.
- public async Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences, CancellationToken cancellationToken)
- {
- var key = userId + displayPreferencesId.ToString();
-
- try
- {
- await Kernel.Instance.DisplayPreferencesRepository.SaveDisplayPreferences(userId, displayPreferencesId,
- displayPreferences,
- cancellationToken).ConfigureAwait(false);
-
- var newValue = Task.FromResult(displayPreferences);
-
- // Once it succeeds, put it into the dictionary to make it available to everyone else
- _displayPreferences.AddOrUpdate(key, newValue, delegate { return newValue; });
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error saving display preferences", ex);
-
- throw;
- }
- }
-
///
/// Gets a User by Id
///
@@ -232,7 +169,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
if (id == Guid.Empty)
{
- throw new ArgumentNullException();
+ throw new ArgumentNullException("id");
}
return Users.FirstOrDefault(u => u.Id == id);
@@ -376,29 +313,19 @@ namespace MediaBrowser.Server.Implementations.Library
/// ClientConnectionInfo.
private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName)
{
- lock (_activeConnections)
+ var key = clientType + deviceId;
+
+ var connection = _activeConnections.GetOrAdd(key, keyName => new ClientConnectionInfo
{
- var conn = _activeConnections.FirstOrDefault(c => string.Equals(c.Client, clientType, StringComparison.OrdinalIgnoreCase) && string.Equals(deviceId, c.DeviceId));
+ UserId = userId,
+ Client = clientType,
+ DeviceName = deviceName,
+ DeviceId = deviceId
+ });
- if (conn == null)
- {
- conn = new ClientConnectionInfo
- {
- UserId = userId,
- Client = clientType,
- DeviceName = deviceName,
- DeviceId = deviceId
- };
-
- _activeConnections.Add(conn);
- }
- else
- {
- conn.UserId = userId;
- }
-
- return conn;
- }
+ connection.UserId = userId;
+
+ return connection;
}
///
@@ -802,11 +729,11 @@ namespace MediaBrowser.Server.Implementations.Library
}
///
- /// Gets the display preferences.
+ /// Gets the user data.
///
/// The user id.
/// The user data id.
- /// Task{DisplayPreferences}.
+ /// Task{UserItemData}.
public Task GetUserData(Guid userId, Guid userDataId)
{
var key = userId + userDataId.ToString();
@@ -815,11 +742,11 @@ namespace MediaBrowser.Server.Implementations.Library
}
///
- /// Retrieves the display preferences.
+ /// Retrieves the user data.
///
/// The user id.
/// The user data id.
- /// DisplayPreferences.
+ /// Task{UserItemData}.
private async Task RetrieveUserData(Guid userId, Guid userDataId)
{
var userdata = await Kernel.Instance.UserDataRepository.GetUserData(userId, userDataId).ConfigureAwait(false);
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index 043ef08450..f2593f1c5a 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -130,6 +130,7 @@
+
diff --git a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs
index dced1ce28d..c34f8a1baf 100644
--- a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs
+++ b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs
@@ -104,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.Providers
/// The providers.
public void AddMetadataProviders(IEnumerable providers)
{
- MetadataProviders = providers.ToArray();
+ MetadataProviders = providers.OrderBy(e => e.Priority).ToArray();
}
///
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
index 8a15d4028e..f471365ce2 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
@@ -33,6 +33,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
}
}
+ ///
+ /// Gets a value indicating whether [enable delayed commands].
+ ///
+ /// true if [enable delayed commands]; otherwise, false.
+ protected override bool EnableDelayedCommands
+ {
+ get
+ {
+ return false;
+ }
+ }
+
///
/// The _protobuf serializer
///
@@ -78,8 +90,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite
string[] queries = {
- "create table if not exists displaypreferences (id GUID, userId GUID, data BLOB)",
- "create unique index if not exists displaypreferencesindex on displaypreferences (id, userId)",
+ "create table if not exists displaypreferences (id GUID, data BLOB)",
+ "create unique index if not exists displaypreferencesindex on displaypreferences (id)",
"create table if not exists schema_version (table_name primary key, version)",
//pragmas
"pragma temp_store = memory"
@@ -91,75 +103,77 @@ namespace MediaBrowser.Server.Implementations.Sqlite
///
/// Save the display preferences associated with an item in the repo
///
- /// The user id.
- /// The display preferences id.
/// The display preferences.
/// The cancellation token.
/// Task.
/// item
- public Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences, CancellationToken cancellationToken)
+ public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken)
{
if (displayPreferences == null)
{
throw new ArgumentNullException("displayPreferences");
}
+ if (displayPreferences.Id == Guid.Empty)
+ {
+ throw new ArgumentNullException("displayPreferences.Id");
+ }
if (cancellationToken == null)
{
throw new ArgumentNullException("cancellationToken");
}
- if (userId == Guid.Empty)
- {
- throw new ArgumentNullException("userId");
- }
- if (displayPreferencesId == Guid.Empty)
- {
- throw new ArgumentNullException("displayPreferencesId");
- }
cancellationToken.ThrowIfCancellationRequested();
-
- return Task.Run(() =>
+
+ var serialized = _protobufSerializer.SerializeToBytes(displayPreferences);
+
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var cmd = connection.CreateCommand();
+ cmd.CommandText = "replace into displaypreferences (id, data) values (@1, @2)";
+ cmd.AddParam("@1", displayPreferences.Id);
+ cmd.AddParam("@2", serialized);
+
+ using (var tran = connection.BeginTransaction())
{
- var serialized = _protobufSerializer.SerializeToBytes(displayPreferences);
+ try
+ {
+ cmd.Transaction = tran;
- cancellationToken.ThrowIfCancellationRequested();
+ await cmd.ExecuteNonQueryAsync(cancellationToken);
- var cmd = connection.CreateCommand();
- cmd.CommandText = "replace into displaypreferences (id, userId, data) values (@1, @2, @3)";
- cmd.AddParam("@1", displayPreferencesId);
- cmd.AddParam("@2", userId);
- cmd.AddParam("@3", serialized);
- QueueCommand(cmd);
- });
+ tran.Commit();
+ }
+ catch (OperationCanceledException)
+ {
+ tran.Rollback();
+ }
+ catch (Exception e)
+ {
+ Logger.ErrorException("Failed to commit transaction.", e);
+ tran.Rollback();
+ }
+ }
}
///
/// Gets the display preferences.
///
- /// The user id.
/// The display preferences id.
/// Task{DisplayPreferences}.
/// item
- public async Task GetDisplayPreferences(Guid userId, Guid displayPreferencesId)
+ public async Task GetDisplayPreferences(Guid displayPreferencesId)
{
- if (userId == Guid.Empty)
- {
- throw new ArgumentNullException("userId");
- }
if (displayPreferencesId == Guid.Empty)
{
throw new ArgumentNullException("displayPreferencesId");
}
var cmd = connection.CreateCommand();
- cmd.CommandText = "select data from displaypreferences where id = @id and userId=@userId";
+ cmd.CommandText = "select data from displaypreferences where id = @id";
var idParam = cmd.Parameters.Add("@id", DbType.Guid);
idParam.Value = displayPreferencesId;
- var userIdParam = cmd.Parameters.Add("@userId", DbType.Guid);
- userIdParam.Value = userId;
-
using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow).ConfigureAwait(false))
{
if (reader.Read())
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
index c5320a1f62..e722ac3dc8 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
@@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
///
/// The flush interval
///
- private const int FlushInterval = 5000;
+ private const int FlushInterval = 2000;
///
/// The flush timer
@@ -43,6 +43,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// The logger.
protected ILogger Logger { get; private set; }
+ ///
+ /// Gets a value indicating whether [enable delayed commands].
+ ///
+ /// true if [enable delayed commands]; otherwise, false.
+ protected virtual bool EnableDelayedCommands
+ {
+ get
+ {
+ return true;
+ }
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -85,8 +97,11 @@ namespace MediaBrowser.Server.Implementations.Sqlite
await connection.OpenAsync().ConfigureAwait(false);
- // Run once
- FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));
+ if (EnableDelayedCommands)
+ {
+ // Run once
+ FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));
+ }
}
///
@@ -147,16 +162,9 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{
if (connection != null)
{
- // If we're not already flushing, do it now
- if (!IsFlushing)
+ if (EnableDelayedCommands)
{
- Flush(null);
- }
-
- // Don't dispose in the middle of a flush
- while (IsFlushing)
- {
- Thread.Sleep(25);
+ FlushOnDispose();
}
if (connection.IsOpen())
@@ -181,6 +189,24 @@ namespace MediaBrowser.Server.Implementations.Sqlite
}
}
+ ///
+ /// Flushes the on dispose.
+ ///
+ private void FlushOnDispose()
+ {
+ // If we're not already flushing, do it now
+ if (!IsFlushing)
+ {
+ Flush(null);
+ }
+
+ // Don't dispose in the middle of a flush
+ while (IsFlushing)
+ {
+ Thread.Sleep(25);
+ }
+ }
+
///
/// Queues the command.
///
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs
index 2c8d7f437f..b2e11d06f3 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs
@@ -34,6 +34,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
}
}
+ ///
+ /// Gets a value indicating whether [enable delayed commands].
+ ///
+ /// true if [enable delayed commands]; otherwise, false.
+ protected override bool EnableDelayedCommands
+ {
+ get
+ {
+ return false;
+ }
+ }
+
///
/// The _protobuf serializer
///
@@ -106,7 +118,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// or
/// userDataId
///
- public Task SaveUserData(Guid userId, Guid userDataId, UserItemData userData, CancellationToken cancellationToken)
+ public async Task SaveUserData(Guid userId, Guid userDataId, UserItemData userData, CancellationToken cancellationToken)
{
if (userData == null)
{
@@ -127,19 +139,36 @@ namespace MediaBrowser.Server.Implementations.Sqlite
cancellationToken.ThrowIfCancellationRequested();
- return Task.Run(() =>
+ var serialized = _protobufSerializer.SerializeToBytes(userData);
+
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var cmd = connection.CreateCommand();
+ cmd.CommandText = "replace into userdata (id, userId, data) values (@1, @2, @3)";
+ cmd.AddParam("@1", userDataId);
+ cmd.AddParam("@2", userId);
+ cmd.AddParam("@3", serialized);
+
+ using (var tran = connection.BeginTransaction())
{
- var serialized = _protobufSerializer.SerializeToBytes(userData);
+ try
+ {
+ cmd.Transaction = tran;
- cancellationToken.ThrowIfCancellationRequested();
+ await cmd.ExecuteNonQueryAsync(cancellationToken);
- var cmd = connection.CreateCommand();
- cmd.CommandText = "replace into userdata (id, userId, data) values (@1, @2, @3)";
- cmd.AddParam("@1", userDataId);
- cmd.AddParam("@2", userId);
- cmd.AddParam("@3", serialized);
- QueueCommand(cmd);
- });
+ tran.Commit();
+ }
+ catch (OperationCanceledException)
+ {
+ tran.Rollback();
+ }
+ catch (Exception e)
+ {
+ Logger.ErrorException("Failed to commit transaction.", e);
+ tran.Rollback();
+ }
+ }
}
///
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs
index 812c98789f..f55b13d196 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs
@@ -45,6 +45,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
///
private readonly IApplicationPaths _appPaths;
+ ///
+ /// Gets a value indicating whether [enable delayed commands].
+ ///
+ /// true if [enable delayed commands]; otherwise, false.
+ protected override bool EnableDelayedCommands
+ {
+ get
+ {
+ return false;
+ }
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -97,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// The cancellation token.
/// Task.
/// user
- public Task SaveUser(User user, CancellationToken cancellationToken)
+ public async Task SaveUser(User user, CancellationToken cancellationToken)
{
if (user == null)
{
@@ -109,20 +121,37 @@ namespace MediaBrowser.Server.Implementations.Sqlite
throw new ArgumentNullException("cancellationToken");
}
- return Task.Run(() =>
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var serialized = _jsonSerializer.SerializeToBytes(user);
+
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var cmd = connection.CreateCommand();
+ cmd.CommandText = "replace into users (guid, data) values (@1, @2)";
+ cmd.AddParam("@1", user.Id);
+ cmd.AddParam("@2", serialized);
+
+ using (var tran = connection.BeginTransaction())
{
- cancellationToken.ThrowIfCancellationRequested();
+ try
+ {
+ cmd.Transaction = tran;
- var serialized = _jsonSerializer.SerializeToBytes(user);
+ await cmd.ExecuteNonQueryAsync(cancellationToken);
- cancellationToken.ThrowIfCancellationRequested();
-
- var cmd = connection.CreateCommand();
- cmd.CommandText = "replace into users (guid, data) values (@1, @2)";
- cmd.AddParam("@1", user.Id);
- cmd.AddParam("@2", serialized);
- QueueCommand(cmd);
- });
+ tran.Commit();
+ }
+ catch (OperationCanceledException)
+ {
+ tran.Rollback();
+ }
+ catch (Exception e)
+ {
+ Logger.ErrorException("Failed to commit transaction.", e);
+ tran.Rollback();
+ }
+ }
}
///
diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs
index 35f203a629..3161048f04 100644
--- a/MediaBrowser.ServerApplication/App.xaml.cs
+++ b/MediaBrowser.ServerApplication/App.xaml.cs
@@ -165,7 +165,7 @@ namespace MediaBrowser.ServerApplication
await CompositionRoot.Init();
- var win = new MainWindow(CompositionRoot.LogManager, CompositionRoot, CompositionRoot.ServerConfigurationManager, CompositionRoot.UserManager, CompositionRoot.LibraryManager, CompositionRoot.JsonSerializer);
+ var win = new MainWindow(CompositionRoot.LogManager, CompositionRoot, CompositionRoot.ServerConfigurationManager, CompositionRoot.UserManager, CompositionRoot.LibraryManager, CompositionRoot.JsonSerializer, CompositionRoot.DisplayPreferencesManager);
win.Show();
}
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index 131d0a7e7f..90de11976c 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -1,8 +1,4 @@
-using System.Diagnostics;
-using System.Net.Cache;
-using System.Net.Http;
-using System.Net.Sockets;
-using MediaBrowser.Api;
+using MediaBrowser.Api;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Constants;
@@ -46,8 +42,10 @@ using MediaBrowser.ServerApplication.Implementations;
using MediaBrowser.WebDashboard.Api;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Net.Sockets;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
@@ -140,6 +138,11 @@ namespace MediaBrowser.ServerApplication
///
/// The UDP server.
private UdpServer UdpServer { get; set; }
+ ///
+ /// Gets or sets the display preferences manager.
+ ///
+ /// The display preferences manager.
+ internal IDisplayPreferencesManager DisplayPreferencesManager { get; set; }
///
/// The full path to our startmenu shortcut
@@ -212,8 +215,12 @@ namespace MediaBrowser.ServerApplication
ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, DirectoryWatchers, LogManager);
RegisterSingleInstance(ProviderManager);
+ DisplayPreferencesManager = new DisplayPreferencesManager(LogManager.GetLogger("DisplayPreferencesManager"));
+ RegisterSingleInstance(DisplayPreferencesManager);
+
RegisterSingleInstance(() => new LuceneSearchEngine());
-
+
+ await ConfigureRepositories().ConfigureAwait(false);
SetKernelProperties();
SetStaticProperties();
}
@@ -229,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(),
@@ -237,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
///
@@ -277,7 +298,7 @@ namespace MediaBrowser.ServerApplication
() => LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports()),
- () => ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray())
+ () => ProviderManager.AddMetadataProviders(GetExports().ToArray())
);
UdpServer = new UdpServer(Logger, NetworkManager, ServerConfigurationManager);
@@ -409,8 +430,8 @@ namespace MediaBrowser.ServerApplication
public override void Shutdown()
{
App.Instance.Dispatcher.Invoke(App.Instance.Shutdown);
- }
-
+ }
+
///
/// Registers the server with administrator access.
///
@@ -450,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();
+ }
}
}
diff --git a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs
index 8811de9db6..84b3d0c5f0 100644
--- a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs
+++ b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs
@@ -33,7 +33,7 @@ namespace MediaBrowser.ServerApplication
private readonly IJsonSerializer _jsonSerializer;
private readonly ILibraryManager _libraryManager;
- private readonly IUserManager _userManager;
+ private readonly IDisplayPreferencesManager _displayPreferencesManager;
///
/// The current user
@@ -42,12 +42,18 @@ namespace MediaBrowser.ServerApplication
///
/// Initializes a new instance of the class.
///
- public LibraryExplorer(IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost, IUserManager userManager, ILibraryManager libraryManager)
+ /// The json serializer.
+ /// The logger.
+ /// The app host.
+ /// The user manager.
+ /// The library manager.
+ /// The display preferences manager.
+ public LibraryExplorer(IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost, IUserManager userManager, ILibraryManager libraryManager, IDisplayPreferencesManager displayPreferencesManager)
{
_logger = logger;
_jsonSerializer = jsonSerializer;
_libraryManager = libraryManager;
- _userManager = userManager;
+ _displayPreferencesManager = displayPreferencesManager;
InitializeComponent();
lblVersion.Content = "Version: " + appHost.ApplicationVersion;
@@ -91,7 +97,7 @@ namespace MediaBrowser.ServerApplication
var currentFolder = folder;
Task.Factory.StartNew(() =>
{
- var prefs = ddlProfile.SelectedItem != null ? _userManager.GetDisplayPreferences((ddlProfile.SelectedItem as User).Id, currentFolder.DisplayPreferencesId).Result ?? new DisplayPreferences { SortBy = ItemSortBy.SortName } : new DisplayPreferences { SortBy = ItemSortBy.SortName };
+ var prefs = ddlProfile.SelectedItem != null ? _displayPreferencesManager.GetDisplayPreferences(currentFolder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id)).Result ?? new DisplayPreferences { SortBy = ItemSortBy.SortName } : new DisplayPreferences { SortBy = ItemSortBy.SortName };
var node = new TreeViewItem { Tag = currentFolder };
var subChildren = currentFolder.GetChildren(CurrentUser, prefs.IndexBy);
@@ -144,7 +150,7 @@ namespace MediaBrowser.ServerApplication
var subFolder = item as Folder;
if (subFolder != null)
{
- var prefs = _userManager.GetDisplayPreferences(user.Id, subFolder.DisplayPreferencesId).Result;
+ var prefs = _displayPreferencesManager.GetDisplayPreferences(subFolder.GetDisplayPreferencesId(user.Id)).Result;
AddChildren(node, OrderBy(subFolder.GetChildren(user), user, prefs.SortBy), user);
node.Header = item.Name + " (" + node.Items.Count + ")";
@@ -201,8 +207,8 @@ namespace MediaBrowser.ServerApplication
var prefs =
await
- _userManager.GetDisplayPreferences((ddlProfile.SelectedItem as User).Id,
- folder.DisplayPreferencesId);
+ _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id));
+
ddlIndexBy.SelectedItem = prefs != null
? prefs.IndexBy ?? LocalizedStrings.Instance.GetString("NoneDispPref")
: LocalizedStrings.Instance.GetString("NoneDispPref");
@@ -360,7 +366,7 @@ namespace MediaBrowser.ServerApplication
var folder = treeItem != null
? treeItem.Tag as Folder
: null;
- var prefs = folder != null ? _userManager.GetDisplayPreferences(CurrentUser.Id, folder.DisplayPreferencesId).Result : new DisplayPreferences {SortBy = ItemSortBy.SortName};
+ var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id)).Result : new DisplayPreferences { SortBy = ItemSortBy.SortName };
if (folder != null && prefs.IndexBy != ddlIndexBy.SelectedItem as string)
{
//grab UI context so we can update within the below task
@@ -401,7 +407,7 @@ namespace MediaBrowser.ServerApplication
var folder = treeItem != null
? treeItem.Tag as Folder
: null;
- var prefs = folder != null ? _userManager.GetDisplayPreferences(CurrentUser.Id, folder.DisplayPreferencesId).Result : new DisplayPreferences();
+ var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id)).Result : new DisplayPreferences();
if (folder != null && prefs.SortBy != ddlSortBy.SelectedItem as string)
{
//grab UI context so we can update within the below task
diff --git a/MediaBrowser.ServerApplication/MainWindow.xaml.cs b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
index f64b7c9d7d..d3ad61a7da 100644
--- a/MediaBrowser.ServerApplication/MainWindow.xaml.cs
+++ b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
@@ -43,6 +43,7 @@ namespace MediaBrowser.ServerApplication
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
private readonly IJsonSerializer _jsonSerializer;
+ private readonly IDisplayPreferencesManager _displayPreferencesManager;
///
/// Initializes a new instance of the class.
@@ -51,7 +52,7 @@ namespace MediaBrowser.ServerApplication
/// The logger.
/// The app host.
/// logger
- public MainWindow(ILogManager logManager, IApplicationHost appHost, IServerConfigurationManager configurationManager, IUserManager userManager, ILibraryManager libraryManager, IJsonSerializer jsonSerializer)
+ public MainWindow(ILogManager logManager, IApplicationHost appHost, IServerConfigurationManager configurationManager, IUserManager userManager, ILibraryManager libraryManager, IJsonSerializer jsonSerializer, IDisplayPreferencesManager displayPreferencesManager)
{
if (logManager == null)
{
@@ -73,6 +74,7 @@ namespace MediaBrowser.ServerApplication
_userManager = userManager;
_libraryManager = libraryManager;
_jsonSerializer = jsonSerializer;
+ _displayPreferencesManager = displayPreferencesManager;
InitializeComponent();
@@ -223,7 +225,7 @@ namespace MediaBrowser.ServerApplication
/// The instance containing the event data.
private void cmOpenExplorer_click(object sender, RoutedEventArgs e)
{
- new LibraryExplorer(_jsonSerializer, _logger, _appHost, _userManager, _libraryManager).Show();
+ new LibraryExplorer(_jsonSerializer, _logger, _appHost, _userManager, _libraryManager, _displayPreferencesManager).Show();
}
///
diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
index 808b8637a3..a0268a7c7f 100644
--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
@@ -436,6 +436,6 @@ del "$(SolutionDir)..\Deploy\MBServer.zip"
-
+
\ No newline at end of file
diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec
index 892848c163..b89c8f9f2f 100644
--- a/Nuget/MediaBrowser.Common.Internal.nuspec
+++ b/Nuget/MediaBrowser.Common.Internal.nuspec
@@ -2,7 +2,7 @@
MediaBrowser.Common.Internal
- 3.0.66
+ 3.0.67
MediaBrowser.Common.Internal
Luke
ebr,Luke,scottisafool
@@ -12,7 +12,7 @@
Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption.
Copyright © Media Browser 2013
-
+
diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec
index 7fae829c10..f628fee30d 100644
--- a/Nuget/MediaBrowser.Common.nuspec
+++ b/Nuget/MediaBrowser.Common.nuspec
@@ -2,7 +2,7 @@
MediaBrowser.Common
- 3.0.66
+ 3.0.67
MediaBrowser.Common
Media Browser Team
ebr,Luke,scottisafool
diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec
index c2c9b33f26..6058d6e04c 100644
--- a/Nuget/MediaBrowser.Server.Core.nuspec
+++ b/Nuget/MediaBrowser.Server.Core.nuspec
@@ -2,7 +2,7 @@
MediaBrowser.Server.Core
- 3.0.66
+ 3.0.67
Media Browser.Server.Core
Media Browser Team
ebr,Luke,scottisafool
@@ -12,7 +12,7 @@
Contains core components required to build plugins for Media Browser Server.
Copyright © Media Browser 2013
-
+