/// <summary>
        /// Finds IProjectTree node in the top level children of a given parent IProjectTree node.
        /// Depending on the type of IDependencyNode search method is different:
        ///     - if dependency node has custom ItemSpec, we only can find it by caption.
        ///     - if dependency node has normal ItemSpec, we first try to find it by path and then
        ///       by caption if path was not found (since unresolved and resolved items can have
        ///       different items specs).
        /// </summary>
        private IProjectTree FindProjectTreeNode(IProjectTree parentNode,
                                                 IDependencyNode nodeInfo,
                                                 string projectFolder)
        {
            IProjectTree treeNode = null;

            if (nodeInfo.Flags.Contains(DependencyNode.CustomItemSpec))
            {
                treeNode = parentNode.FindNodeByCaption(nodeInfo.Caption);
            }
            else
            {
                var itemSpec = nodeInfo.Id.ItemSpec;
                if (!ManagedPathHelper.IsRooted(itemSpec))
                {
                    itemSpec = ManagedPathHelper.TryMakeRooted(projectFolder, itemSpec);
                }

                if (!string.IsNullOrEmpty(itemSpec))
                {
                    treeNode = parentNode.FindNodeByPath(itemSpec);
                }

                if (treeNode == null)
                {
                    treeNode = parentNode.FindNodeByCaption(nodeInfo.Caption);
                }
            }

            return(treeNode);
        }
Beispiel #2
0
        private IProjectTree FindByPathInternal(IProjectTree root, string path)
        {
            var node = root.FindNodeByPath(path);

            if (node != null)
            {
                return(node);
            }

            foreach (var child in root.Children)
            {
                node = child.FindNodeByPath(path);
                if (node != null)
                {
                    return(node);
                }

                foreach (var thirdLevelNode in child.Children)
                {
                    node = thirdLevelNode.FindNodeByPath(path);
                    if (node != null)
                    {
                        return(node);
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// Removes given list of elements form IProjectTree
 /// </summary>
 /// <param name="tree"></param>
 /// <param name="itemsToRemove"></param>
 /// <param name="itemFilter"></param>
 /// <returns></returns>
 public static IProjectTree RemoveElementsFromTree(this IProjectTree tree,
                                                   IEnumerable <string> itemsToRemove,
                                                   Func <string, bool> itemFilter)
 {
     foreach (string file in itemsToRemove)
     {
         if (itemFilter(file))
         {
             // See if we already have this one -  we shouldn't
             var existingNode = tree.FindNodeByPath(file);
             System.Diagnostics.Debug.Assert(existingNode != null);
             if (existingNode != null)
             {
                 tree = existingNode.Remove();
             }
         }
     }
     return(tree);
 }
Beispiel #4
0
 /// <summary>
 /// Adds a givel list of elements to IProjectTree
 /// </summary>
 /// <param name="tree"></param>
 /// <param name="itemsToAdd"></param>
 /// <param name="itemFilter"></param>
 /// <param name="nodeCreator"></param>
 /// <returns></returns>
 public static IProjectTree AddElementsToTree(this IProjectTree tree,
                                              IEnumerable <string> itemsToAdd,
                                              Func <string, bool> itemFilter,
                                              Func <string, IProjectTree> nodeCreator)
 {
     foreach (string item in itemsToAdd)
     {
         if (itemFilter(item))
         {
             // Double check we don't already have this one -  we shouldn't
             var existingNode = tree.FindNodeByPath(item);
             System.Diagnostics.Debug.Assert(existingNode == null);
             if (existingNode == null)
             {
                 tree = tree.Add(nodeCreator(item)).Parent;
             }
         }
     }
     return(tree);
 }