From ee00f8bf726ae5498d64cff0086b9b7e638936ea Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 24 Jan 2015 14:03:55 -0500 Subject: [PATCH] added HasSyncJob --- MediaBrowser.Api/BaseApiService.cs | 36 ++++++- MediaBrowser.Api/GamesService.cs | 4 +- MediaBrowser.Api/IHasDtoOptions.cs | 29 +----- MediaBrowser.Api/ItemLookupService.cs | 3 +- MediaBrowser.Api/Library/LibraryService.cs | 16 +-- MediaBrowser.Api/Movies/CollectionService.cs | 2 +- MediaBrowser.Api/Movies/MoviesService.cs | 14 +-- MediaBrowser.Api/Movies/TrailersService.cs | 8 +- MediaBrowser.Api/Music/AlbumsService.cs | 4 +- MediaBrowser.Api/Music/InstantMixService.cs | 7 +- MediaBrowser.Api/PlaylistService.cs | 7 +- MediaBrowser.Api/SimilarItemsHelper.cs | 5 +- MediaBrowser.Api/Sync/SyncService.cs | 7 +- MediaBrowser.Api/TvShowsService.cs | 22 +++-- .../UserLibrary/ArtistsService.cs | 2 +- .../UserLibrary/BaseItemsByNameService.cs | 2 +- .../UserLibrary/GameGenresService.cs | 2 +- MediaBrowser.Api/UserLibrary/GenresService.cs | 2 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 6 +- .../UserLibrary/MusicGenresService.cs | 2 +- .../UserLibrary/PersonsService.cs | 2 +- .../UserLibrary/StudiosService.cs | 2 +- .../UserLibrary/UserLibraryService.cs | 16 +-- MediaBrowser.Api/UserLibrary/YearsService.cs | 2 +- MediaBrowser.Api/VideosService.cs | 2 +- .../Networking/BaseNetworkManager.cs | 53 ++++++++++ .../ScheduledTasks/ScheduledTaskWorker.cs | 6 ++ MediaBrowser.Common/Net/INetworkManager.cs | 1 - .../Collections/ICollectionManager.cs | 7 ++ MediaBrowser.Controller/Dto/DtoOptions.cs | 1 + MediaBrowser.Controller/Dto/IDtoService.cs | 11 +++ .../IServerApplicationHost.cs | 12 ++- MediaBrowser.Controller/Sync/ISyncManager.cs | 7 ++ .../Sync/ISyncRepository.cs | 7 ++ MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs | 2 +- .../Configuration/ServerConfiguration.cs | 2 + MediaBrowser.Model/Dto/BaseItemDto.cs | 3 +- MediaBrowser.Model/Tasks/TaskResult.cs | 6 ++ .../Channels/ChannelManager.cs | 8 +- .../Collections/CollectionManager.cs | 12 ++- .../Connect/ConnectManager.cs | 4 +- .../Dto/DtoService.cs | 99 +++++++++++++++++-- .../Library/LibraryManager.cs | 2 +- .../Library/UserManager.cs | 3 +- .../Library/UserViewManager.cs | 38 ++++--- .../Localization/Server/server.json | 4 +- .../Sync/SyncManager.cs | 5 + .../Sync/SyncRepository.cs | 27 +++-- .../Udp/UdpServer.cs | 14 ++- .../ApplicationHost.cs | 43 ++++---- MediaBrowser.sln | 5 + 51 files changed, 420 insertions(+), 166 deletions(-) diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index e90969655..2aaec8627 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,8 +1,10 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Dto; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using ServiceStack.Text.Controller; using ServiceStack.Web; @@ -36,6 +38,7 @@ namespace MediaBrowser.Api public IRequest Request { get; set; } public ISessionContext SessionContext { get; set; } + public IAuthorizationContext AuthorizationContext { get; set; } public string GetHeader(string name) { @@ -110,6 +113,37 @@ namespace MediaBrowser.Api private readonly char[] _dashReplaceChars = { '?', '/', '&' }; private const char SlugChar = '-'; + protected DtoOptions GetDtoOptions(object request) + { + var options = new DtoOptions(); + + options.DeviceId = AuthorizationContext.GetAuthorizationInfo(Request).DeviceId; + + var hasFields = request as IHasItemFields; + if (hasFields != null) + { + options.Fields = hasFields.GetItemFields().ToList(); + } + + var hasDtoOptions = request as IHasDtoOptions; + if (hasDtoOptions != null) + { + options.EnableImages = hasDtoOptions.EnableImages ?? true; + + if (hasDtoOptions.ImageTypeLimit.HasValue) + { + options.ImageTypeLimit = hasDtoOptions.ImageTypeLimit.Value; + } + + if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes)) + { + options.ImageTypes = (hasDtoOptions.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList(); + } + } + + return options; + } + protected MusicArtist GetArtist(string name, ILibraryManager libraryManager) { return libraryManager.GetArtist(DeSlugArtistName(name, libraryManager)); diff --git a/MediaBrowser.Api/GamesService.cs b/MediaBrowser.Api/GamesService.cs index 9aba2b065..39e357f49 100644 --- a/MediaBrowser.Api/GamesService.cs +++ b/MediaBrowser.Api/GamesService.cs @@ -172,7 +172,9 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetSimilarGames request) { - var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager, + var dtoOptions = GetDtoOptions(request); + + var result = SimilarItemsHelper.GetSimilarItemsResult(dtoOptions, _userManager, _itemRepo, _libraryManager, _userDataRepository, diff --git a/MediaBrowser.Api/IHasDtoOptions.cs b/MediaBrowser.Api/IHasDtoOptions.cs index 7fe47c4a1..dac366113 100644 --- a/MediaBrowser.Api/IHasDtoOptions.cs +++ b/MediaBrowser.Api/IHasDtoOptions.cs @@ -1,8 +1,4 @@ -using MediaBrowser.Controller.Dto; -using MediaBrowser.Model.Entities; -using System; -using System.Linq; - + namespace MediaBrowser.Api { public interface IHasDtoOptions : IHasItemFields @@ -13,27 +9,4 @@ namespace MediaBrowser.Api string EnableImageTypes { get; set; } } - - public static class HasDtoOptionsExtensions - { - public static DtoOptions GetDtoOptions(this IHasDtoOptions request) - { - var options = new DtoOptions(); - - options.Fields = request.GetItemFields().ToList(); - options.EnableImages = request.EnableImages ?? true; - - if (request.ImageTypeLimit.HasValue) - { - options.ImageTypeLimit = request.ImageTypeLimit.Value; - } - - if (!string.IsNullOrWhiteSpace(request.EnableImageTypes)) - { - options.ImageTypes = (request.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList(); - } - - return options; - } - } } diff --git a/MediaBrowser.Api/ItemLookupService.cs b/MediaBrowser.Api/ItemLookupService.cs index 9a97022b6..d6b4da8be 100644 --- a/MediaBrowser.Api/ItemLookupService.cs +++ b/MediaBrowser.Api/ItemLookupService.cs @@ -205,7 +205,8 @@ namespace MediaBrowser.Api Logger = Logger, Request = Request, ResultFactory = ResultFactory, - SessionContext = SessionContext + SessionContext = SessionContext, + AuthorizationContext = AuthorizationContext }; service.Post(new RefreshItem diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 5e1619672..bac6f6a39 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -272,7 +272,7 @@ namespace MediaBrowser.Api.Library items = items.Where(i => i.IsHidden == val).ToList(); } - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); var result = new ItemsResult { @@ -344,7 +344,7 @@ namespace MediaBrowser.Api.Library var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null; - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); BaseItem parent = item.Parent; @@ -544,7 +544,7 @@ namespace MediaBrowser.Api.Library ThemeSongsResult = themeSongs, ThemeVideosResult = themeVideos, - SoundtrackSongsResult = GetSoundtrackSongs(request.Id, request.UserId, request.InheritFromParent) + SoundtrackSongsResult = GetSoundtrackSongs(request, request.Id, request.UserId, request.InheritFromParent) }); } @@ -597,7 +597,7 @@ namespace MediaBrowser.Api.Library } } - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); var dtos = themeSongIds.Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) @@ -667,7 +667,7 @@ namespace MediaBrowser.Api.Library } } - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); var dtos = themeVideoIds.Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) @@ -732,17 +732,17 @@ namespace MediaBrowser.Api.Library return ToOptimizedSerializedResultUsingCache(lookup); } - public ThemeMediaResult GetSoundtrackSongs(string id, Guid? userId, bool inheritFromParent) + public ThemeMediaResult GetSoundtrackSongs(GetThemeMedia request, string id, Guid? userId, bool inheritFromParent) { var user = userId.HasValue ? _userManager.GetUserById(userId.Value) : null; var item = string.IsNullOrEmpty(id) ? (userId.HasValue ? user.RootFolder - : (Folder)_libraryManager.RootFolder) + : _libraryManager.RootFolder) : _libraryManager.GetItemById(id); - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); var dtos = GetSoundtrackSongIds(item, inheritFromParent) .Select(_libraryManager.GetItemById) diff --git a/MediaBrowser.Api/Movies/CollectionService.cs b/MediaBrowser.Api/Movies/CollectionService.cs index 97c6cd87d..e6277e39a 100644 --- a/MediaBrowser.Api/Movies/CollectionService.cs +++ b/MediaBrowser.Api/Movies/CollectionService.cs @@ -71,7 +71,7 @@ namespace MediaBrowser.Api.Movies }).ConfigureAwait(false); - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); var dto = _dtoService.GetBaseItemDto(item, dtoOptions); diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index ba3c15a90..0b8bb4036 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Api.Movies .DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString(), StringComparer.OrdinalIgnoreCase) .ToList(); - var dtoOptions = new DtoOptions(); + var dtoOptions = GetDtoOptions(request); dtoOptions.Fields = request.GetItemFields().ToList(); @@ -174,8 +174,6 @@ namespace MediaBrowser.Api.Movies (request.UserId.HasValue ? user.RootFolder : _libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id); - var fields = request.GetItemFields().ToList(); - var inputItems = user == null ? _libraryManager.RootFolder.GetRecursiveChildren().Where(i => i.Id != item.Id) : user.RootFolder.GetRecursiveChildren(user).Where(i => i.Id != item.Id); @@ -225,10 +223,12 @@ namespace MediaBrowser.Api.Movies { returnItems = returnItems.Take(request.Limit.Value); } + + var dtoOptions = GetDtoOptions(request); var result = new ItemsResult { - Items = returnItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(), + Items = _dtoService.GetBaseItemDtos(returnItems, dtoOptions, user).ToArray(), TotalRecordCount = items.Count }; @@ -351,7 +351,7 @@ namespace MediaBrowser.Api.Movies BaselineItemName = director, CategoryId = director.GetMD5().ToString("N"), RecommendationType = type, - Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray() + Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).ToArray() }; } } @@ -375,7 +375,7 @@ namespace MediaBrowser.Api.Movies BaselineItemName = name, CategoryId = name.GetMD5().ToString("N"), RecommendationType = type, - Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray() + Items = _dtoService.GetBaseItemDtos(items, dtoOptions, user).ToArray() }; } } @@ -399,7 +399,7 @@ namespace MediaBrowser.Api.Movies BaselineItemName = item.Name, CategoryId = item.Id.ToString("N"), RecommendationType = type, - Items = similar.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray() + Items = _dtoService.GetBaseItemDtos(similar, dtoOptions, user).ToArray() }; } } diff --git a/MediaBrowser.Api/Movies/TrailersService.cs b/MediaBrowser.Api/Movies/TrailersService.cs index 8e1704af7..3bee59a86 100644 --- a/MediaBrowser.Api/Movies/TrailersService.cs +++ b/MediaBrowser.Api/Movies/TrailersService.cs @@ -84,7 +84,9 @@ namespace MediaBrowser.Api.Movies /// System.Object. public object Get(GetSimilarTrailers request) { - var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager, + var dtoOptions = GetDtoOptions(request); + + var result = SimilarItemsHelper.GetSimilarItemsResult(dtoOptions, _userManager, _itemRepo, _libraryManager, _userDataRepository, @@ -119,9 +121,9 @@ namespace MediaBrowser.Api.Movies var pagedItems = ApplyPaging(request, itemsArray); - var fields = request.GetItemFields().ToList(); + var dtoOptions = GetDtoOptions(request); - var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); + var returnItems = _dtoService.GetBaseItemDtos(pagedItems, dtoOptions, user).ToArray(); return new ItemsResult { diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs index 34a933dee..4cfb3c7d4 100644 --- a/MediaBrowser.Api/Music/AlbumsService.cs +++ b/MediaBrowser.Api/Music/AlbumsService.cs @@ -50,7 +50,9 @@ namespace MediaBrowser.Api.Music /// System.Object. public object Get(GetSimilarAlbums request) { - var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager, + var dtoOptions = GetDtoOptions(request); + + var result = SimilarItemsHelper.GetSimilarItemsResult(dtoOptions, _userManager, _itemRepo, _libraryManager, _userDataRepository, diff --git a/MediaBrowser.Api/Music/InstantMixService.cs b/MediaBrowser.Api/Music/InstantMixService.cs index 43fd0894b..cfb826a13 100644 --- a/MediaBrowser.Api/Music/InstantMixService.cs +++ b/MediaBrowser.Api/Music/InstantMixService.cs @@ -146,8 +146,6 @@ namespace MediaBrowser.Api.Music private object GetResult(IEnumerable