/// <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 AddInTreeNode GetTreeNode(string path, bool throwOnNotFound = true) { if (path == null || path.Length == 0) { return(rootNode); } string[] splittedPath = path.Split('/'); AddInTreeNode curPath = rootNode; for (int i = 0; i < splittedPath.Length; i++) { if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath)) { if (throwOnNotFound) { throw new TreePathNotFoundException(path); } else { return(null); } } } return(curPath); }
private void AddExtensionPath(ExtensionPath path) { AddInTreeNode treePath = CreatePath(rootNode, path.Name); foreach (IEnumerable <Codon> innerCodons in path.GroupedCodons) { treePath.AddCodons(innerCodons); } }
public object BuildItem(string path, object parameter, IEnumerable <ICondition> additionalConditions) { int pos = path.LastIndexOf('/'); string parent = path.Substring(0, pos); string child = path.Substring(pos + 1); AddInTreeNode node = GetTreeNode(parent); return(node.BuildChildItem(child, parameter, additionalConditions)); }
public BuildItemArgs(object parameter, Codon codon, IReadOnlyCollection <ICondition> conditions, AddInTreeNode subItemNode) { if (codon == null) { throw new ArgumentNullException("codon"); } this.parameter = parameter; this.codon = codon; this.conditions = conditions; this.subItemNode = subItemNode; }
/// <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="parameter">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 IReadOnlyList <T> BuildItems <T>(string path, object parameter, bool throwOnNotFound = true) { AddInTreeNode node = GetTreeNode(path, throwOnNotFound); if (node == null) { return(new List <T>()); } else { return(node.BuildChildItems <T>(parameter)); } }
public object BuildItem(BuildItemArgs args) { Codon codon = args.Codon; string item = codon.Properties["item"]; string path = codon.Properties["path"]; if (item != null && item.Length > 0) { // include item return(args.AddInTree.BuildItem(item, args.Parameter, args.Conditions)); } else if (path != null && path.Length > 0) { // include path (=multiple items) AddInTreeNode node = args.AddInTree.GetTreeNode(path); return(new IncludeReturnItem(node, args.Parameter, args.Conditions)); } else { throw new BaseException("<Include> requires the attribute 'item' (to include one item) or the attribute 'path' (to include multiple items)"); } }
private 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); }
public IncludeReturnItem(AddInTreeNode node, object parameter, IEnumerable <ICondition> additionalConditions) { this.node = node; this.parameter = parameter; this.additionalConditions = additionalConditions; }