Ejemplo n.º 1
0
        public QueryResult <BaseItem> QueryRecursive(InternalItemsQuery query)
        {
            var user = query.User;

            if (!query.ForceDirect && RequiresPostFiltering(query))
            {
                IEnumerable <BaseItem> items;
                Func <BaseItem, bool>  filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);

                if (query.User == null)
                {
                    items = GetRecursiveChildren(filter);
                }
                else
                {
                    items = GetRecursiveChildren(user, query);
                }

                return(PostFilterAndSort(items, query, true, true));
            }

            if (!(this is UserRootFolder) && !(this is AggregateFolder))
            {
                query.ParentId = query.ParentId ?? Id;
            }

            return(LibraryManager.GetItemsResult(query));
        }
Ejemplo n.º 2
0
        public virtual Task <QueryResult <BaseItem> > GetItems(InternalItemsQuery query)
        {
            var user = query.User;

            Func <BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);

            IEnumerable <BaseItem> items;

            if (query.User == null)
            {
                items = query.Recursive
                   ? GetRecursiveChildren(filter)
                   : Children.Where(filter);
            }
            else
            {
                items = query.Recursive
                   ? GetRecursiveChildren(user, filter)
                   : GetChildren(user, true).Where(filter);
            }

            var result = PostFilterAndSort(items, query);

            return(Task.FromResult(result));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the children to list.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private void AddChildren(User user, bool includeLinkedChildren, Dictionary <Guid, BaseItem> result, bool recursive, InternalItemsQuery query)
        {
            foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
            {
                if (child.IsVisible(user))
                {
                    if (query == null || UserViewBuilder.FilterItem(child, query))
                    {
                        result[child.Id] = child;
                    }

                    if (recursive && child.IsFolder)
                    {
                        var folder = (Folder)child;

                        folder.AddChildren(user, includeLinkedChildren, result, true, query);
                    }
                }
            }

            if (includeLinkedChildren)
            {
                foreach (var child in GetLinkedChildren(user))
                {
                    if (child.IsVisible(user))
                    {
                        if (query == null || UserViewBuilder.FilterItem(child, query))
                        {
                            result[child.Id] = child;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override IEnumerable <BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
        {
            var result = GetItems(new InternalItemsQuery
            {
                User      = user,
                Recursive = true,
                EnableTotalRecordCount = false,

                ForceDirect = true
            }).Result;

            return(result.Items.Where(i => UserViewBuilder.FilterItem(i, query)));
        }
Ejemplo n.º 5
0
        protected virtual async Task <QueryResult <BaseItem> > GetItemsInternal(InternalItemsQuery query)
        {
            if (SourceType == SourceType.Channel)
            {
                try
                {
                    // Don't blow up here because it could cause parent screens with other content to fail
                    return(await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
                    {
                        ChannelId = ChannelId,
                        FolderId = Id.ToString("N"),
                        Limit = query.Limit,
                        StartIndex = query.StartIndex,
                        UserId = query.User.Id.ToString("N"),
                        SortBy = query.SortBy,
                        SortOrder = query.SortOrder
                    }, new Progress <double>(), CancellationToken.None));
                }
                catch
                {
                    // Already logged at lower levels
                    return(new QueryResult <BaseItem>());
                }
            }

            if (query.Recursive)
            {
                return(QueryRecursive(query));
            }

            var user = query.User;

            Func <BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);

            IEnumerable <BaseItem> items;

            if (query.User == null)
            {
                items = query.Recursive
                   ? GetRecursiveChildren(filter)
                   : Children.Where(filter);
            }
            else
            {
                items = query.Recursive
                   ? GetRecursiveChildren(user, query)
                   : GetChildren(user, true).Where(filter);
            }

            return(PostFilterAndSort(items, query, true, true));
        }
Ejemplo n.º 6
0
        protected override QueryResult <BaseItem> GetItemsInternal(InternalItemsQuery query)
        {
            if (query.Recursive)
            {
                return(QueryRecursive(query));
            }

            var result = UserViewManager.GetUserViews(new UserViewQuery
            {
                UserId      = query.User.Id,
                PresetViews = query.PresetViews
            });

            return(UserViewBuilder.SortAndPage(result, null, query, LibraryManager, true));
        }
Ejemplo n.º 7
0
        public override async Task <QueryResult <BaseItem> > GetItems(InternalItemsQuery query)
        {
            var user = query.User;
            Func <BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);

            if (query.Recursive)
            {
                var items = query.User.RootFolder.GetRecursiveChildren(query.User, filter);
                return(PostFilterAndSort(items, query));
            }

            var result = await UserViewManager.GetUserViews(new UserViewQuery
            {
                UserId = query.User.Id.ToString("N")
            }, CancellationToken.None).ConfigureAwait(false);

            return(PostFilterAndSort(result.Where(filter), query));
        }
Ejemplo n.º 8
0
        protected override async Task <QueryResult <BaseItem> > GetItemsInternal(InternalItemsQuery query)
        {
            if (query.Recursive)
            {
                return(QueryRecursive(query));
            }

            var result = await UserViewManager.GetUserViews(new UserViewQuery
            {
                UserId      = query.User.Id.ToString("N"),
                PresetViews = query.PresetViews
            }, CancellationToken.None).ConfigureAwait(false);

            var user = query.User;
            Func <BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);

            return(PostFilterAndSort(result.Where(filter), query));
        }
Ejemplo n.º 9
0
 protected QueryResult <BaseItem> PostFilterAndSort(IEnumerable <BaseItem> items, InternalItemsQuery query)
 {
     return(UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager));
 }
Ejemplo n.º 10
0
 protected QueryResult <BaseItem> SortAndFilter(IEnumerable <BaseItem> items, InternalItemsQuery query)
 {
     return(UserViewBuilder.SortAndFilter(items, this, null, query, LibraryManager, UserDataManager));
 }
Ejemplo n.º 11
0
 protected QueryResult <BaseItem> PostFilterAndSort(IEnumerable <BaseItem> items, InternalItemsQuery query, bool collapseBoxSetItems, bool enableSorting)
 {
     return(UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager, ConfigurationManager, collapseBoxSetItems, enableSorting));
 }
Ejemplo n.º 12
0
        private bool RequiresPostFiltering(InternalItemsQuery query)
        {
            if (LinkedChildren.Count > 0)
            {
                if (!(this is ICollectionFolder))
                {
                    Logger.Debug("Query requires post-filtering due to LinkedChildren. Type: " + GetType().Name);
                    return(true);
                }
            }

            if (query.SortBy != null && query.SortBy.Length > 0)
            {
                if (query.SortBy.Contains(ItemSortBy.AiredEpisodeOrder, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.AiredEpisodeOrder");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.Budget, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.Budget");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.GameSystem, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.GameSystem");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.Metascore, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.Metascore");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.Players, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.Players");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.Revenue, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.Revenue");
                    return(true);
                }
                if (query.SortBy.Contains(ItemSortBy.VideoBitRate, StringComparer.OrdinalIgnoreCase))
                {
                    Logger.Debug("Query requires post-filtering due to ItemSortBy.VideoBitRate");
                    return(true);
                }
            }

            if (query.ItemIds.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to ItemIds");
                return(true);
            }

            if (query.IsInBoxSet.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to IsInBoxSet");
                return(true);
            }

            // Filter by Video3DFormat
            if (query.Is3D.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to Is3D");
                return(true);
            }

            if (query.HasOfficialRating.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasOfficialRating");
                return(true);
            }

            if (query.IsPlaceHolder.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to IsPlaceHolder");
                return(true);
            }

            if (query.HasSpecialFeature.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasSpecialFeature");
                return(true);
            }

            if (query.HasSubtitles.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasSubtitles");
                return(true);
            }

            if (query.HasTrailer.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasTrailer");
                return(true);
            }

            // Filter by VideoType
            if (query.VideoTypes.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to VideoTypes");
                return(true);
            }

            // Apply person filter
            if (query.ItemIdsFromPersonFilters != null)
            {
                Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters");
                return(true);
            }

            if (query.MinPlayers.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to MinPlayers");
                return(true);
            }

            if (query.MaxPlayers.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to MaxPlayers");
                return(true);
            }

            if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager))
            {
                Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems");
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(query.AdjacentTo))
            {
                Logger.Debug("Query requires post-filtering due to AdjacentTo");
                return(true);
            }

            if (query.AirDays.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to AirDays");
                return(true);
            }

            if (query.SeriesStatuses.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to SeriesStatuses");
                return(true);
            }

            if (query.AiredDuringSeason.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to AiredDuringSeason");
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(query.AlbumArtistStartsWithOrGreater))
            {
                Logger.Debug("Query requires post-filtering due to AlbumArtistStartsWithOrGreater");
                return(true);
            }

            if (query.IsPlayed.HasValue)
            {
                if (query.IncludeItemTypes.Length == 1 && query.IncludeItemTypes.Contains(typeof(Series).Name))
                {
                    Logger.Debug("Query requires post-filtering due to IsPlayed");
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 13
0
        private bool RequiresPostFiltering(InternalItemsQuery query)
        {
            if (LinkedChildren.Count > 0)
            {
                if (!(this is ICollectionFolder))
                {
                    Logger.Debug("Query requires post-filtering due to LinkedChildren. Type: " + GetType().Name);
                    return(true);
                }
            }

            if (query.IsInBoxSet.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to IsInBoxSet");
                return(true);
            }

            // Filter by Video3DFormat
            if (query.Is3D.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to Is3D");
                return(true);
            }

            if (query.HasOfficialRating.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasOfficialRating");
                return(true);
            }

            if (query.IsPlaceHolder.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to IsPlaceHolder");
                return(true);
            }

            if (query.HasSpecialFeature.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasSpecialFeature");
                return(true);
            }

            if (query.HasSubtitles.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasSubtitles");
                return(true);
            }

            if (query.HasTrailer.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to HasTrailer");
                return(true);
            }

            // Filter by VideoType
            if (query.VideoTypes.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to VideoTypes");
                return(true);
            }

            // Apply person filter
            if (query.ItemIdsFromPersonFilters != null)
            {
                Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters");
                return(true);
            }

            if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager))
            {
                Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems");
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(query.AdjacentTo))
            {
                Logger.Debug("Query requires post-filtering due to AdjacentTo");
                return(true);
            }

            if (query.AirDays.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to AirDays");
                return(true);
            }

            if (query.SeriesStatuses.Length > 0)
            {
                Logger.Debug("Query requires post-filtering due to SeriesStatuses");
                return(true);
            }

            if (query.AiredDuringSeason.HasValue)
            {
                Logger.Debug("Query requires post-filtering due to AiredDuringSeason");
                return(true);
            }

            if (query.IsPlayed.HasValue)
            {
                if (query.IncludeItemTypes.Length == 1 && query.IncludeItemTypes.Contains(typeof(Series).Name))
                {
                    Logger.Debug("Query requires post-filtering due to IsPlayed");
                    return(true);
                }
            }

            return(false);
        }