示例#1
0
        /// <summary>
        /// Gets the <see cref="PluginTreeNode"/> representing the specified path.
        /// </summary>
        /// <param name="path">The path of the Plugin tree node</param>
        /// <param name="throwOnNotFound">
        /// If set to <c>true</c>, this method throws a
        /// <see cref="TreePathNotFoundException"/> when the path does not exist.
        /// If set to <c>false</c>, <c>null</c> is returned for non-existing paths.
        /// </param>
        public static PluginTreeNode GetTreeNode(string path, bool throwOnNotFound)
        {
            if (path == null || path.Length == 0)
            {
                return(rootNode);
            }
            string[]       splittedPath = path.Split('/');
            PluginTreeNode curPath      = rootNode;
            int            i            = 0;

            while (i < splittedPath.Length)
            {
                if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath))
                {
                    if (throwOnNotFound)
                    {
                        throw new TreePathNotFoundException(path);
                    }
                    else
                    {
                        return(null);
                    }
                }
                // curPath = curPath.ChildNodes[splittedPath[i]]; already done by TryGetValue
                ++i;
            }
            return(curPath);
        }
示例#2
0
        static void AddExtensionPath(ExtensionPath path)
        {
            PluginTreeNode treePath = CreatePath(rootNode, path.Name);

            foreach (Extension extension in path.Extensions)
            {
                treePath.Extensions.Add(extension);
            }
        }
示例#3
0
        /// <summary>
        /// Builds a single item in the addin tree.
        /// </summary>
        /// <param name="path">A path to the item in the addin tree.</param>
        /// <param name="caller">The owner used to create the objects.</param>
        /// <exception cref="TreePathNotFoundException">The path does not
        /// exist or does not point to an item.</exception>
        public static object BuildItem(string path, object caller)
        {
            int            pos    = path.LastIndexOf('/');
            string         parent = path.Substring(0, pos);
            string         child  = path.Substring(pos + 1);
            PluginTreeNode node   = GetTreeNode(parent);

            return(node.BuildChildItem(child, caller, new ArrayList(BuildItems <object>(parent, caller, false))));
        }
示例#4
0
        /// <summary>
        /// Builds the items in the path. Ensures that all items have the type T.
        /// </summary>
        /// <param name="path">A path in the addin tree.</param>
        /// <param name="caller">The owner used to create the objects.</param>
        /// <param name="throwOnNotFound">If true, throws a <see cref="TreePathNotFoundException"/>
        /// if the path is not found. If false, an empty ArrayList is returned when the
        /// path is not found.</param>
        public static List <T> BuildItems <T>(string path, object caller, bool throwOnNotFound)
        {
            PluginTreeNode node = GetTreeNode(path, throwOnNotFound);

            if (node == null)
            {
                return(new List <T>());
            }
            else
            {
                return(node.BuildChildItems <T>(caller));
            }
        }
示例#5
0
        static PluginTreeNode CreatePath(PluginTreeNode localRoot, string path)
        {
            if (path == null || path.Length == 0)
            {
                return(localRoot);
            }
            string[]       splittedPath = path.Split('/');
            PluginTreeNode curPath      = localRoot;
            int            i            = 0;

            while (i < splittedPath.Length)
            {
                if (!curPath.ChildNodes.ContainsKey(splittedPath[i]))
                {
                    curPath.ChildNodes[splittedPath[i]] = new PluginTreeNode();
                }
                curPath = curPath.ChildNodes[splittedPath[i]];
                ++i;
            }

            return(curPath);
        }
示例#6
0
        /// <summary>
        /// Checks whether the specified path exists in the Plugin tree.
        /// </summary>
        public static bool ExistsTreeNode(string path)
        {
            if (path == null || path.Length == 0)
            {
                return(true);
            }

            string[]       splittedPath = path.Split('/');
            PluginTreeNode curPath      = rootNode;
            int            i            = 0;

            while (i < splittedPath.Length)
            {
                // curPath = curPath.ChildNodes[splittedPath[i]] - check if child path exists
                if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath))
                {
                    return(false);
                }
                ++i;
            }
            return(true);
        }