コード例 #1
0
        /// <summary>
        /// Gets the <see cref="AddInTreeNode"/> representing the specified path.
        /// </summary>
        /// <param name="path">The path of the AddIn 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 AddInTreeNode GetTreeNode(string path, bool throwOnNotFound)
        {
            if (path == null || path.Length == 0)
            {
                return(rootNode);
            }
            string[]      splittedPath = path.Split('/');
            AddInTreeNode 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)
        {
            AddInTreeNode treePath = CreatePath(rootNode, path.Name);

            foreach (Codon codon in path.Codons)
            {
                treePath.Codons.Add(codon);
            }
        }
コード例 #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);
            AddInTreeNode node   = GetTreeNode(parent);

            return(node.BuildChildItem(child, caller, new ArrayList(BuildItems <object>(path, 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)
        {
            AddInTreeNode node = GetTreeNode(path, throwOnNotFound);

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

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

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

            string[]      splittedPath = path.Split('/');
            AddInTreeNode 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);
        }