/// <summary> /// Saves display preferences for an item /// </summary> /// <param name="displayPreferences">The display preferences.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> 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; } }
public UserProfileWindow(DefaultThemePageMasterCommandsViewModel masterCommands, ISessionManager session, IPresentationManager presentationManager, IImageManager imageManager, IApiClient apiClient, DisplayPreferences displayPreferences, ListPageConfig options) { _session = session; _options = options; _displayPreferencesViewModel = new DisplayPreferencesViewModel(displayPreferences, presentationManager); _previousFocus = ""; InitializeComponent(); Loaded += UserProfileWindow_Loaded; Unloaded += UserProfileWindow_Unloaded; masterCommands.PageNavigated += masterCommands_PageNavigated; BtnClose.Click += BtnClose_Click; //Display preferences RadioList.Click += radioList_Click; RadioPoster.Click += radioPoster_Click; RadioThumbstrip.Click += radioThumbstrip_Click; RadioPosterStrip.Click += radioPosterStrip_Click; //Sort preferences RadioSortAscending.Click += RadioSortAscending_Click; RadioSortDescending.Click += RadioSortDescending_Click; //Focus tracking BtnClose.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; HomeButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; DisplayPreferencesButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; SortButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; SettingsButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; LogoutButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; ShutdownAppButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; SleepButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RestartButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; ShutdownButton.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioList.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioPosterStrip.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioPoster.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioThumbstrip.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioSortAscending.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; RadioSortDescending.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; CheckBoxSortRemember.IsKeyboardFocusedChanged += Button_IsKeyboardFocusedChanged; ContentGrid.DataContext = new DefaultThemeUserDtoViewModel(masterCommands, apiClient, imageManager, session) { User = session.CurrentUser, ImageHeight = 54 }; MainGrid.DataContext = this; CheckBoxSortRemember.DataContext = _displayPreferencesViewModel; if (displayPreferences != null) { //Always set to false to begin with in case the user is just doing a quick sort and doesn't want it saved. _displayPreferencesViewModel.RememberSorting = false; } }
public FolderPage(BaseItemDto parent, DisplayPreferences displayPreferences, IApiClient apiClient, IImageManager imageManager, IPresentationManager presentation, INavigationService navigationManager, IPlaybackManager playbackManager, ILogger logger, ListPageConfig options) { _logger = logger; _presentationManager = presentation; _imageManager = imageManager; _apiClient = apiClient; _options = options; _parentItem = parent; InitializeComponent(); Loaded += FolderPage_Loaded; SetDefaults(displayPreferences); var playAllFromHere = parent.IsType("playlist") || parent.IsType("musicalbum"); _viewModel = new ItemListViewModel(vm => options.CustomItemQuery(vm, displayPreferences), _presentationManager, _imageManager, _apiClient, navigationManager, playbackManager, _logger) { ImageDisplayHeightGenerator = GetImageDisplayHeight, DisplayNameGenerator = options.DisplayNameGenerator ?? GetDisplayName, PreferredImageTypesGenerator = GetPreferredImageTypes, ShowSidebarGenerator = GetShowSidebar, ScrollDirectionGenerator = GetScrollDirection, AutoSelectFirstItem = true, ShowLoadingAnimation = true, PlayAllFromHereOnPlayCommand = playAllFromHere, PlayAllFromHereOnNavigateCommand = playAllFromHere }; if (options.ShowTitle) { _viewModel.OnItemCreated = v => { v.DisplayNameVisibility = Visibility.Visible; }; } _viewModel.AddIndexOptions(options.IndexOptions); _viewModel.PropertyChanged += _viewModel_PropertyChanged; _viewModel.DisplayPreferences = displayPreferences; if (!string.IsNullOrEmpty(options.IndexValue)) { var index = options.IndexOptions.First(i => string.Equals(i.Name, options.IndexValue)); _viewModel.IndexOptionsCollectionView.MoveCurrentTo(index); } DataContext = _viewModel; }
public DisplayPreferencesViewModel(DisplayPreferences displayPreferences, IPresentationManager presentation) { DisplayPreferences = displayPreferences; _presentation = presentation; SaveCommand = new RelayCommand(obj => Save()); IncreaseImageSizeCommand = new RelayCommand(obj => IncreaseImageSize()); DecreaseImageSizeCommand = new RelayCommand(obj => DecreaseImageSize()); ToggleScrollDirectionCommand = new RelayCommand(obj => ToggleScrollDirection()); }
public FolderPage(BaseItemDto parent, DisplayPreferences displayPreferences, IApiClient apiClient, IImageManager imageManager, ISessionManager sessionManager, IPresentationManager presentation, INavigationService navigationManager, IPlaybackManager playbackManager, ILogger logger, IServerEvents serverEvents, ListPageConfig options) { _navigationManager = navigationManager; _playbackManager = playbackManager; _logger = logger; _serverEvents = serverEvents; _presentationManager = presentation; _sessionManager = sessionManager; _imageManager = imageManager; _apiClient = apiClient; _options = options; _displayPreferences = displayPreferences; _parentItem = parent; InitializeComponent(); Loaded += FolderPage_Loaded; Unloaded += FolderPage_Unloaded; SetDefaults(displayPreferences); _viewModel = new ItemListViewModel(GetItemsAsync, _presentationManager, _imageManager, _apiClient, _navigationManager, _playbackManager, _logger, _serverEvents) { ImageDisplayHeightGenerator = GetImageDisplayHeight, DisplayNameGenerator = GetDisplayName, PreferredImageTypesGenerator = GetPreferredImageTypes, ShowSidebarGenerator = GetShowSidebar, ScrollDirectionGenerator = GetScrollDirection, AutoSelectFirstItem = true, ShowLoadingAnimation = true }; _viewModel.AddIndexOptions(options.IndexOptions); _viewModel.PropertyChanged += _viewModel_PropertyChanged; _viewModel.DisplayPreferences = displayPreferences; DataContext = _viewModel; UpdateSortTitle(); UpdateSortOrder(); BtnSort.Visibility = _options.SortOptions.Count > 0 ? Visibility.Visible : Visibility.Collapsed; BtnSort.Click += BtnSort_Click; }
public DisplayPreferencesViewModel(DisplayPreferences displayPreferences, IPresentationManager presentation, ITheaterConfigurationManager configurationManager, ISessionManager sessionManager) { DisplayPreferences = displayPreferences; _presentation = presentation; _configurationManager = configurationManager; _sessionManager = sessionManager; _userConfig = configurationManager.GetUserTheaterConfiguration(sessionManager.CurrentUser.Id); SaveCommand = new RelayCommand(obj => Save()); IncreaseImageSizeCommand = new RelayCommand(obj => IncreaseImageSize()); DecreaseImageSizeCommand = new RelayCommand(obj => DecreaseImageSize()); ToggleScrollDirectionCommand = new RelayCommand(obj => ToggleScrollDirection()); }
public FolderPage(BaseItemDto parent, DisplayPreferences displayPreferences, IApiClient apiClient, IImageManager imageManager, IPresentationManager presentation, INavigationService navigationManager, IPlaybackManager playbackManager, ILogger logger, IServerEvents serverEvents, ListPageConfig options) { _logger = logger; _presentationManager = presentation; _imageManager = imageManager; _apiClient = apiClient; _options = options; _parentItem = parent; InitializeComponent(); Loaded += FolderPage_Loaded; SetDefaults(displayPreferences); _viewModel = new ItemListViewModel(vm => options.CustomItemQuery(vm, displayPreferences), _presentationManager, _imageManager, _apiClient, navigationManager, playbackManager, _logger, serverEvents) { ImageDisplayHeightGenerator = GetImageDisplayHeight, DisplayNameGenerator = options.DisplayNameGenerator ?? GetDisplayName, PreferredImageTypesGenerator = GetPreferredImageTypes, ShowSidebarGenerator = GetShowSidebar, ScrollDirectionGenerator = GetScrollDirection, AutoSelectFirstItem = true, ShowLoadingAnimation = true }; _viewModel.AddIndexOptions(options.IndexOptions); _viewModel.PropertyChanged += _viewModel_PropertyChanged; _viewModel.DisplayPreferences = displayPreferences; if (!string.IsNullOrEmpty(options.IndexValue)) { var index = options.IndexOptions.First(i => string.Equals(i.Name, options.IndexValue)); _viewModel.IndexOptionsCollectionView.MoveCurrentTo(index); } DataContext = _viewModel; }
private Task<ItemsResult> GetAllActors(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var fields = FolderPage.QueryFields.ToList(); fields.Remove(ItemFields.Overview); fields.Remove(ItemFields.DisplayPreferencesId); fields.Remove(ItemFields.DateCreated); var query = new PersonsQuery { Fields = fields.ToArray(), IncludeItemTypes = new[] { "Movie", "Trailer" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, UserId = _sessionManager.CurrentUser.Id, Recursive = true }; var indexOption = viewModel.CurrentIndexOption; if (indexOption != null) { if (string.Equals(indexOption.Name, "#", StringComparison.OrdinalIgnoreCase)) { query.NameLessThan = "A"; } else { query.NameStartsWithOrGreater = indexOption.Name; query.NameLessThan = indexOption.Name + "zz"; } } return ApiClient.GetPeopleAsync(query); }
private Task<ItemsResult> GetMoviesByYear(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, IncludeItemTypes = new[] { "Movie" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true }; var indexOption = viewModel.CurrentIndexOption; if (indexOption != null) { query.Years = new[] { int.Parse(indexOption.Name) }; } return ApiClient.GetItemsAsync(query); }
private Task<ItemsResult> GetMovies(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, IncludeItemTypes = new[] { "Movie" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true }; var indexOption = viewModel.CurrentIndexOption == null ? string.Empty : viewModel.CurrentIndexOption.Name; if (string.Equals(indexOption, "TopRated")) { query.MinCommunityRating = ApiClientExtensions.TopMovieCommunityRating; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "Unwatched")) { query.Filters = new[] { ItemFilter.IsUnplayed }; } else if (string.Equals(indexOption, "NewReleases")) { query.SortBy = new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate }; query.SortOrder = SortOrder.Descending; query.Limit = 100; } else if (string.Equals(indexOption, "HDMovies")) { query.IsHD = true; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "3DMovies")) { query.Is3D = true; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "Trailers")) { query.IncludeItemTypes = new[] { "Trailer" }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "BoxSets")) { query.IncludeItemTypes = new[] { "BoxSet" }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "FavoriteMovies")) { query.Filters = new[] { ItemFilter.IsFavorite }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "TopCriticRated")) { query.MinCriticRating = 95; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (string.Equals(indexOption, "Family")) { query.Genres = new[] { "Family" }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (indexOption.StartsWith("Genre:")) { query.Genres = new[] { indexOption.Split(':').Last() }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } else if (indexOption.StartsWith("Studio:")) { query.Studios = new[] { indexOption.Split(':').Last() }; query.SortBy = new[] { ItemSortBy.SortName }; query.SortOrder = SortOrder.Ascending; } return ApiClient.GetItemsAsync(query); }
private Task<ItemsResult> GetFavoriteItems(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var indexOption = viewModel.CurrentIndexOption; if (indexOption != null) { if (string.Equals(indexOption.Name, "Artist", StringComparison.OrdinalIgnoreCase)) { return GetFavoriteArtists(viewModel, displayPreferences); } if (string.Equals(indexOption.Name, "Person", StringComparison.OrdinalIgnoreCase)) { return GetFavoritePeople(viewModel, displayPreferences); } } var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true, Filters = new[] { ItemFilter.IsFavorite } }; if (indexOption != null) { query.IncludeItemTypes = new[] { indexOption.Name }; } return ApiClient.GetItemsAsync(query); }
private Task<ItemsResult> GetAllShows(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, IncludeItemTypes = new[] { "Series" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true }; return ApiClient.GetItemsAsync(query, CancellationToken.None); }
public Task UpdateDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken) { return _apiClient.UpdateDisplayPreferencesAsync(displayPreferences, _sessionFactory().CurrentUser.Id, "MBT-" + _themeManager.CurrentTheme.Name, cancellationToken); }
public DisplayPreferences RetrieveDisplayPreferences(DisplayPreferences dp) { throw new NotImplementedException(); }
private Task<ItemsResult> GetMultiPlayerGames(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, IncludeItemTypes = new[] { "Game" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, MinPlayers = 2, Recursive = true }; var indexOption = viewModel.CurrentIndexOption; if (indexOption != null) { query.MinPlayers = query.MaxPlayers = int.Parse(indexOption.Name); } return ApiClient.GetItemsAsync(query, CancellationToken.None); }
/// <summary> /// Save the display preferences associated with an item in the repo /// </summary> /// <param name="displayPreferences">The display preferences.</param> /// <param name="userId">The user id.</param> /// <param name="client">The client.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, 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"); } cancellationToken.ThrowIfCancellationRequested(); var serialized = _jsonSerializer.SerializeToBytes(displayPreferences); await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); SQLiteTransaction transaction = null; try { transaction = _connection.BeginTransaction(); using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "replace into userdisplaypreferences (id, userid, client, data) values (@1, @2, @3, @4)"; cmd.AddParam("@1", displayPreferences.Id); cmd.AddParam("@2", userId); cmd.AddParam("@3", client); cmd.AddParam("@4", serialized); cmd.Transaction = transaction; await cmd.ExecuteNonQueryAsync(cancellationToken); } transaction.Commit(); } catch (OperationCanceledException) { if (transaction != null) { transaction.Rollback(); } throw; } catch (Exception e) { _logger.ErrorException("Failed to save display preferences:", e); if (transaction != null) { transaction.Rollback(); } throw; } finally { if (transaction != null) { transaction.Dispose(); } _writeLock.Release(); } }
private async Task NavigateToItemInternal(BaseItemDto item, ViewType context) { var apiClient = _connectionManager.GetApiClient(item); // Grab it fresh from the server to make sure we have the full record item = await apiClient.GetItemAsync(item.Id, apiClient.CurrentUserId); if (item.IsFolder) { DisplayPreferences displayPreferences; try { displayPreferences = await _presentationManager.GetDisplayPreferences(apiClient, item.DisplayPreferencesId, CancellationToken.None); } catch { // Already logged at lower levels displayPreferences = new DisplayPreferences { Id = item.DisplayPreferencesId }; } await App.Instance.ApplicationWindow.Dispatcher.InvokeAsync(async () => await Navigate(_themeManager.CurrentTheme.GetFolderPage(item, context, displayPreferences))); } else { await App.Instance.ApplicationWindow.Dispatcher.InvokeAsync(async () => await Navigate(_themeManager.CurrentTheme.GetItemPage(item, context))); } }
private void SetDefaults(DisplayPreferences displayPreferences) { if (string.IsNullOrEmpty(displayPreferences.ViewType)) { displayPreferences.ViewType = _options.DefaultViewType; } if (string.Equals(displayPreferences.ViewType, ListViewTypes.Poster, StringComparison.OrdinalIgnoreCase)) { displayPreferences.PrimaryImageWidth = _options.PosterImageWidth; } else if (string.Equals(displayPreferences.ViewType, ListViewTypes.PosterStrip, StringComparison.OrdinalIgnoreCase)) { displayPreferences.PrimaryImageWidth = _options.PosterStripImageWidth; } else if (string.Equals(displayPreferences.ViewType, ListViewTypes.List, StringComparison.OrdinalIgnoreCase)) { displayPreferences.PrimaryImageWidth = _options.ListImageWidth; } else if (string.Equals(displayPreferences.ViewType, ListViewTypes.Thumbstrip, StringComparison.OrdinalIgnoreCase)) { displayPreferences.PrimaryImageWidth = _options.ThumbImageWidth; } }
private Task<ItemsResult> GetComedyMovies(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, IncludeItemTypes = new[] { "Movie" }, Genres = new[] { ApiClientExtensions.ComedyGenre }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true }; return ApiClient.GetItemsAsync(query); }
/// <summary> /// Gets the folder page. /// </summary> /// <param name="item">The item.</param> /// <param name="context">The context.</param> /// <param name="displayPreferences">The display preferences.</param> /// <returns>Page.</returns> public Page GetFolderPage(BaseItemDto item, ViewType context, DisplayPreferences displayPreferences) { var apiClient = _connectionManager.GetApiClient(item); if (item.IsType("channel") || item.IsType("channelfolderitem")) { var options = GetChannelPageConfig(item, context); return new FolderPage(item, displayPreferences, apiClient, _imageManager, _presentationManager, _navService, _playbackManager, _logger, options); } if (context == ViewType.Folders || !_folderTypesWithDetailPages.Contains(item.Type, StringComparer.OrdinalIgnoreCase)) { var options = GetListPageConfig(item, context); options.ShowTitle = true; return new FolderPage(item, displayPreferences, apiClient, _imageManager, _presentationManager, _navService, _playbackManager, _logger, options); } return GetItemPage(item, context); }
public Task SaveDisplayPreferences(DisplayPreferences displayPreferences, string userId, string client, CancellationToken cancellationToken) { return SaveDisplayPreferences(displayPreferences, new Guid(userId), client, cancellationToken); }
public void SaveDisplayPreferences(DisplayPreferences prefs) { throw new NotImplementedException(); }
public Task UpdateDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken) { var apiClient = _sessionFactory().ActiveApiClient; return apiClient.UpdateDisplayPreferencesAsync(displayPreferences, _sessionFactory().LocalUserId, "MBT-" + _themeManager.CurrentTheme.Name, cancellationToken); }
/// <summary> /// Gets the folder page. /// </summary> /// <param name="item">The item.</param> /// <param name="context">The context.</param> /// <param name="displayPreferences">The display preferences.</param> /// <returns>Page.</returns> public Page GetFolderPage(BaseItemDto item, ViewType context, DisplayPreferences displayPreferences) { if (!_folderTypesWithDetailPages.Contains(item.Type, StringComparer.OrdinalIgnoreCase)) { var options = GetListPageConfig(item, context); return new FolderPage(item, displayPreferences, _apiClient, _imageManager, _sessionManager, _presentationManager, _navService, _playbackManager, _logger, _serverEvents, options); } return GetItemPage(item, context); }
/// <summary> /// Save the display preferences associated with an item in the repo /// </summary> /// <param name="displayPreferences">The display preferences.</param> /// <param name="userId">The user id.</param> /// <param name="client">The client.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, CancellationToken cancellationToken) { if (displayPreferences == null) { throw new ArgumentNullException("displayPreferences"); } if (string.IsNullOrWhiteSpace(displayPreferences.Id)) { throw new ArgumentNullException("displayPreferences.Id"); } cancellationToken.ThrowIfCancellationRequested(); var serialized = _jsonSerializer.SerializeToBytes(displayPreferences); await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; try { transaction = _connection.BeginTransaction(); using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "replace into userdisplaypreferences (id, userid, client, data) values (@1, @2, @3, @4)"; cmd.Parameters.Add(cmd, "@1", DbType.Guid).Value = new Guid(displayPreferences.Id); cmd.Parameters.Add(cmd, "@2", DbType.Guid).Value = userId; cmd.Parameters.Add(cmd, "@3", DbType.String).Value = client; cmd.Parameters.Add(cmd, "@4", DbType.Binary).Value = serialized; cmd.Transaction = transaction; cmd.ExecuteNonQuery(); } transaction.Commit(); } catch (OperationCanceledException) { if (transaction != null) { transaction.Rollback(); } throw; } catch (Exception e) { _logger.ErrorException("Failed to save display preferences:", e); if (transaction != null) { transaction.Rollback(); } throw; } finally { if (transaction != null) { transaction.Dispose(); } _writeLock.Release(); } }
private Task<ItemsResult> GetSeriesByGenre(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ItemQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.LocalUserId, IncludeItemTypes = new[] { "Series" }, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true, ParentId = ParentId }; var indexOption = viewModel.CurrentIndexOption; if (indexOption != null) { query.Genres = new[] { indexOption.Name }; } return ApiClient.GetItemsAsync(query, CancellationToken.None); }
private Task<ItemsResult> GetFavoriteArtists(ItemListViewModel viewModel, DisplayPreferences displayPreferences) { var query = new ArtistsQuery { Fields = FolderPage.QueryFields, UserId = _sessionManager.CurrentUser.Id, SortBy = !String.IsNullOrEmpty(displayPreferences.SortBy) ? new[] { displayPreferences.SortBy } : new[] { ItemSortBy.SortName }, SortOrder = displayPreferences.SortOrder, Recursive = true, Filters = new[] { ItemFilter.IsFavorite } }; return ApiClient.GetArtistsAsync(query); }