Exemple #1
0
        public void Store(TLeaf leadData, HierarchicalTreeSettingsData customSettings = null)
        {
            GetSettings(ref customSettings);

            var parentBranch  = this;
            var folderMatches = customSettings.FolderRegex.Matches(leadData.Path);

            for (var m = 0; m < folderMatches.Count; m++)
            {
                var folderMatch = folderMatches[m];
                var value       = folderMatch.LastGroup().Value;
                if (m == folderMatches.Count - 1)
                {
                    var name      = value;
                    var extension = string.Empty;
                    var nameMatch = customSettings.ExtensionRegex.Match(value);
                    if (nameMatch.Success)
                    {
                        name      = nameMatch.Groups[1].Value;
                        extension = nameMatch.Groups[2].Value;
                    }

                    var leaf = new TreeLeaf <IHierarchicalTreeLeaf>(name, extension, leadData);
                    if (!parentBranch.Leaves.Contains(leaf))
                    {
                        //Remove the old one because the leaf hashCode is Path dependant
                        parentBranch.Leaves.Remove(leaf);
                    }

                    parentBranch.Leaves.Add(leaf);
                    break;
                }

                if (parentBranch.Branches.TryGetValue(value, out var childBranch))
                {
                    parentBranch = childBranch;
                }
                else
                {
                    childBranch = new HierarchicalTree <TLeaf>(customSettings)
                    {
                        parent     = parentBranch,
                        branchName = value
                    };

                    parentBranch.Branches.Add(value, childBranch);
                    parentBranch = childBranch;
                }
            }
        }
Exemple #2
0
        public void Remove(IHierarchicalTreeLeaf leadData, HierarchicalTreeSettingsData customSettings = null)
        {
            GetSettings(ref customSettings);

            var activeBranch = SearchForBranch(leadData.Path, true, customSettings);

            if (activeBranch == null)
            {
                return;
            }

            var leaf = new TreeLeaf <IHierarchicalTreeLeaf>(string.Empty, string.Empty, leadData);

            activeBranch.Leaves.Remove(leaf);
        }