From 4986722c7305ebce02c37c80363a909d372ff7a3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Apr 2013 15:02:48 -0400 Subject: made display preferences uniquely identifiable --- .../Library/UserManager.cs | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library') diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index c5e4de2bc..a122e2c6d 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -102,7 +102,7 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The _user data /// - private readonly ConcurrentDictionary> _displayPreferences = new ConcurrentDictionary>(); + private readonly ConcurrentDictionary> _displayPreferences = new ConcurrentDictionary>(); private readonly ConcurrentDictionary> _userData = new ConcurrentDictionary>(); @@ -168,51 +168,51 @@ namespace MediaBrowser.Server.Implementations.Library /// /// Gets the display preferences. /// - /// The user id. /// The display preferences id. /// DisplayPreferences. - public Task GetDisplayPreferences(Guid userId, Guid displayPreferencesId) + public Task GetDisplayPreferences(Guid displayPreferencesId) { - var key = userId + displayPreferencesId.ToString(); - - return _displayPreferences.GetOrAdd(key, keyName => RetrieveDisplayPreferences(userId, displayPreferencesId)); + return _displayPreferences.GetOrAdd(displayPreferencesId, keyName => RetrieveDisplayPreferences(displayPreferencesId)); } /// /// Retrieves the display preferences. /// - /// The user id. /// The display preferences id. /// DisplayPreferences. - private async Task RetrieveDisplayPreferences(Guid userId, Guid displayPreferencesId) + private async Task RetrieveDisplayPreferences(Guid displayPreferencesId) { - var displayPreferences = await Kernel.Instance.DisplayPreferencesRepository.GetDisplayPreferences(userId, displayPreferencesId).ConfigureAwait(false); + var displayPreferences = await Kernel.Instance.DisplayPreferencesRepository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false); - return displayPreferences ?? new DisplayPreferences(); + return displayPreferences ?? new DisplayPreferences { Id = displayPreferencesId }; } /// /// 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) + public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken) { - var key = userId + displayPreferencesId.ToString(); - + if (displayPreferences == null) + { + throw new ArgumentNullException("displayPreferences"); + } + if (displayPreferences.Id == Guid.Empty) + { + throw new ArgumentNullException("displayPreferences.Id"); + } + try { - await Kernel.Instance.DisplayPreferencesRepository.SaveDisplayPreferences(userId, displayPreferencesId, - displayPreferences, + await Kernel.Instance.DisplayPreferencesRepository.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(key, newValue, delegate { return newValue; }); + _displayPreferences.AddOrUpdate(displayPreferences.Id, newValue, delegate { return newValue; }); } catch (Exception ex) { @@ -232,7 +232,7 @@ namespace MediaBrowser.Server.Implementations.Library { if (id == Guid.Empty) { - throw new ArgumentNullException(); + throw new ArgumentNullException("id"); } return Users.FirstOrDefault(u => u.Id == id); -- cgit v1.2.3