public override bool Process(DataNode dataNode, ConsoleOptions options) { TagListDataNode listNode = dataNode as TagListDataNode; listNode.Clear(); foreach (string value in options.Values) { TagNode tag = TagDataNode.DefaultTag(listNode.Tag.ValueType); TagDataNode tagData = TagDataNode.CreateFromTag(tag); if (!tagData.Parse(value)) { return(false); } if (!listNode.AppendTag(tagData.Tag)) { return(false); } } return(true); }
private DataNode IterativeSearch(DataNode rootNode, int countThreshold) { List <RegionFileDataNode> regions = new List <RegionFileDataNode>(); GatherAllRegions(rootNode, regions); // Gather all the regions under the selected directory IEnumerator <DataNode>[] nodeEnumeratorStack = new IEnumerator <DataNode> [256]; // Enumerator Stack used when exploring chunk sub nodes (fixed size for improved performance) // Explore every region foreach (RegionFileDataNode region in regions) { if (!region.IsExpanded) { region.Expand(); } // Explore every chunk foreach (RegionChunkDataNode chunk in region.Nodes) { if (!chunk.IsExpanded) { chunk.Expand(); } int currentDepth = 0; nodeEnumeratorStack[0] = chunk.Nodes.GetEnumerator(); nodeEnumeratorStack[0].MoveNext(); // Explore chunk's sub nodes while (currentDepth >= 0) { DataNode currentNode = nodeEnumeratorStack[currentDepth].Current; if (!currentNode.IsExpanded) { currentNode.Expand(); } // Check if node is a tag list matching the search TagListDataNode listNode = currentNode as TagListDataNode; if (listNode != null && listNode.TagCount > countThreshold && listNode.NodeName != null) { int nodeNameHash = listNode.NodeName.GetHashCode(); if (nodeNameHash == targetNameHash) { return(listNode); } } if (!nodeEnumeratorStack[currentDepth].MoveNext()) { // Reached end of sibling nodes currentDepth--; currentNode.Collapse(); } else if (currentNode.Nodes.Count > 0) { // Node has children to explore currentDepth++; nodeEnumeratorStack[currentDepth] = currentNode.Nodes.GetEnumerator(); nodeEnumeratorStack[currentDepth].MoveNext(); } } chunk.Collapse(); } // Collapse the region to free some memory region.Collapse(); } return(null); }