Exemplo n.º 1
0
 public IFilter BuildFilter(FilterTreePath path)
 {
     if (path != null && path.Segments.Count > 0)
     {
         throw new ArgumentException(string.Format("{0} must be null or empty when building a filter from a {1}", nameof(path), GetType().Name), nameof(path));
     }
     return(BuildFilter());
 }
Exemplo n.º 2
0
 public void AddFilter(IFilter filter, FilterTreePath path)
 {
     if (path != null && path.Segments.Count > 0)
     {
         throw new ArgumentException(string.Format("{0} must be null or empty when adding a filter to a {1}", nameof(path), GetType().Name), nameof(path));
     }
     AddFilter(filter);
 }
        /// <summary>
        /// Builds a filter starting at the node specified in <paramref name="path"/>
        /// including subfilters for parent and child nodes.
        /// </summary>
        /// <param name="path">The absolute path to the node from this node.</param>
        /// <returns></returns>
        public IFilter BuildFilter(FilterTreePath path)
        {
            //We won't add missing nodes to avoid polluting the tree.
            //The filter will still be created correctly because the 'missing' nodes
            //have a reference to the tree via their parent field and can therefore walk up correctly.
            RelationshipFilterTree node = FindNodeForPath(path, false);

            return(node.BuildChildAndParentFilters(null));
        }
        /// <summary>
        /// Finds the node for the role specified in <paramref name="path"/>.
        /// </summary>
        /// <param name="path">The absolute path to the node from this node.</param>
        /// <param name="addMissingNodesToTree">Whether to add any missing nodes to the tree.</param>
        /// <returns></returns>
        protected RelationshipFilterTree FindNodeForPath(FilterTreePath path, bool addMissingNodesToTree)
        {
            RelationshipFilterTree node = this;

            if (path != null)
            {
                foreach (FilterTreePathSegment segment in path.Segments)
                {
                    node = node.FindChild(segment.Role, addMissingNodesToTree);
                }
            }
            return(node);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Combines multiple <see cref="FilterTreePath"/>s into a single path.
        /// </summary>
        /// <param name="parts">The <see cref="FilterTreePath"/>s to combine</param>
        /// <returns></returns>
        public static FilterTreePath Combine(params FilterTreePath[] parts)
        {
            IEnumerable <FilterTreePath> validPaths = parts.Where(p => p != null && p.Segments.Count > 0);
            FilterTreePath combinedPath             = null;

            foreach (FilterTreePath part in validPaths)
            {
                if (combinedPath == null)
                {
                    combinedPath = new FilterTreePath();
                }
                foreach (FilterTreePathSegment segment in part.Segments)
                {
                    combinedPath.Segments.Add(segment);
                }
            }
            return(combinedPath);
        }
        /// <summary>
        /// Adds a linked id for the role specified in <paramref name="path"/>.
        /// The linked id will override any existing filters for the node.
        /// </summary>
        /// <param name="linkedId">The media item id to link to the node.</param>
        /// <param name="path">The absolute path to the node from this node.</param>
        public void AddLinkedId(Guid linkedId, FilterTreePath path)
        {
            RelationshipFilterTree node = FindNodeForPath(path, true);

            node.LinkedIds.Add(linkedId);
        }
        /// <summary>
        /// Adds a filter to the node specified in <paramref name="path"/>.
        /// </summary>
        /// <param name="filter">The filter to add. The filter will be combined with any existing filters for the node.</param>
        /// <param name="path">The absolute path to the node from this node.</param>
        public void AddFilter(IFilter filter, FilterTreePath path)
        {
            RelationshipFilterTree node = FindNodeForPath(path, true);

            node.CombineFilter(filter);
        }
Exemplo n.º 8
0
 public void AddLinkedId(Guid linkedId, FilterTreePath path)
 {
     throw new InvalidOperationException(string.Format("{0} does not support adding a linked id", GetType().Name));
 }