Ejemplo n.º 1
0
        private IEnumerable <T> FilterItems <T>(IEnumerable <T> items, GetItemCounts request, Guid userId)
            where T : BaseItem
        {
            if (request.IsFavorite.HasValue)
            {
                var val = request.IsFavorite.Value;

                items = items.Where(i => _userDataManager.GetUserData(userId, i.GetUserDataKey()).IsFavorite == val);
            }

            return(items);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var items = GetItems(request.UserId).ToList();

            var counts = new ItemCounts
            {
                AlbumCount      = items.OfType <MusicAlbum>().Count(),
                EpisodeCount    = items.OfType <Episode>().Count(),
                GameCount       = items.OfType <Game>().Count(),
                MovieCount      = items.OfType <Movie>().Count(),
                SeriesCount     = items.OfType <Series>().Count(),
                SongCount       = items.OfType <Audio>().Count(),
                TrailerCount    = items.OfType <Trailer>().Count(),
                MusicVideoCount = items.OfType <MusicVideo>().Count()
            };

            return(ToOptimizedResult(counts));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetItemCounts request)
        {
            var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager)
                        .Where(i => i.LocationType != LocationType.Virtual)
                        .ToList();

            var filteredItems = request.UserId.HasValue ? FilterItems(items, request, request.UserId.Value).ToList() : items;

            var albums      = filteredItems.OfType <MusicAlbum>().ToList();
            var episodes    = filteredItems.OfType <Episode>().ToList();
            var games       = filteredItems.OfType <Game>().ToList();
            var movies      = filteredItems.OfType <Movie>().ToList();
            var musicVideos = filteredItems.OfType <MusicVideo>().ToList();
            var adultVideos = filteredItems.OfType <AdultVideo>().ToList();
            var boxsets     = filteredItems.OfType <BoxSet>().ToList();
            var books       = filteredItems.OfType <Book>().ToList();
            var songs       = filteredItems.OfType <Audio>().ToList();
            var series      = filteredItems.OfType <Series>().ToList();

            var counts = new ItemCounts
            {
                AlbumCount      = albums.Count,
                EpisodeCount    = episodes.Count,
                GameCount       = games.Count,
                GameSystemCount = filteredItems.OfType <GameSystem>().Count(),
                MovieCount      = movies.Count,
                SeriesCount     = series.Count,
                SongCount       = songs.Count,
                TrailerCount    = filteredItems.OfType <Trailer>().Count(),
                MusicVideoCount = musicVideos.Count,
                AdultVideoCount = adultVideos.Count,
                BoxSetCount     = boxsets.Count,
                BookCount       = books.Count,

                UniqueTypes = items.Select(i => i.GetType().Name).Distinct().ToList()
            };

            var people = items.SelectMany(i => i.People)
                         .Select(i => i.Name)
                         .Distinct(StringComparer.OrdinalIgnoreCase)
                         .Select(i =>
            {
                try
                {
                    return(_libraryManager.GetPerson(i));
                }
                catch
                {
                    return(null);
                }
            })
                         .Where(i => i != null)
                         .ToList();

            people             = request.UserId.HasValue ? FilterItems(people, request, request.UserId.Value).ToList() : people;
            counts.PersonCount = people.Count;

            var artists = items.OfType <Audio>().SelectMany(i =>
            {
                var list = new List <string>();

                if (!string.IsNullOrEmpty(i.AlbumArtist))
                {
                    list.Add(i.AlbumArtist);
                }
                list.AddRange(i.Artists);

                return(list);
            })
                          .Distinct(StringComparer.OrdinalIgnoreCase)
                          .Select(i =>
            {
                try
                {
                    return(_libraryManager.GetArtist(i));
                }
                catch
                {
                    return(null);
                }
            })
                          .Where(i => i != null)
                          .ToList();

            artists            = request.UserId.HasValue ? FilterItems(artists, request, request.UserId.Value).ToList() : artists;
            counts.ArtistCount = artists.Count;

            return(ToOptimizedResult(counts));
        }