Exemplo n.º 1
0
        public void TestFilterTree()
        {
            IFilterTree tree = new RelationshipFilterTree(baseRole);

            tree.AddFilter(new RelationalFilter(MediaAspect.ATTR_TITLE, RelationalOperator.EQ, "Item2"),
                           new FilterTreePath(item1Role, item2Role));
            tree.AddFilter(new RelationalFilter(MediaAspect.ATTR_TITLE, RelationalOperator.EQ, "Item3"),
                           new FilterTreePath(item1Role, item3Role));
            tree.AddFilter(new RelationalFilter(MediaAspect.ATTR_TITLE, RelationalOperator.EQ, "Item1"),
                           new FilterTreePath(item1Role));
            tree.AddFilter(new RelationalFilter(MediaAspect.ATTR_TITLE, RelationalOperator.EQ, "Item0"));

            //No linked ids, should build full filter in both directions
            TestFilterTreeNoLinkedIds(tree);
            //Test copy
            IFilterTree copy = tree.DeepCopy();

            TestFilterTreeNoLinkedIds(copy);

            //Add a linked id in the middle, should optimise by ignoring any filters on the linked media item
            tree.AddLinkedId(item1Id, new FilterTreePath(item1Role));
            TestFilterTreeWithLinkedIds(tree);
            //Test copy
            copy = tree.DeepCopy();
            TestFilterTreeWithLinkedIds(copy);
        }
        protected virtual async Task PrepareFilterTree()
        {
            if (!_rootRole.HasValue)
            {
                return;
            }

            _customFilterTree = new RelationshipFilterTree(_rootRole.Value);

            //Update filter by adding the user filter to the already loaded filters
            IFilter userFilter = UserHelper.GetUserRestrictionFilter(_necessaryMias);

            if (userFilter != null)
            {
                _customFilterTree.AddFilter(userFilter);
            }

            userFilter = UserHelper.GetUserRestrictionFilter(new[] { SeriesAspect.ASPECT_ID });
            if (userFilter != null)
            {
                _customFilterTree.AddFilter(userFilter, new FilterTreePath(SeriesAspect.ROLE_SERIES));
            }
        }