public bool TryGetValue(string key, ObservableCollection <KeyValuePair <string, PDFMergeItem> > tree, out PDFMergeItem value) { foreach (KeyValuePair <string, PDFMergeItem> kvp in tree) { if (kvp.Key.Equals(key)) { value = kvp.Value; return(true); } } value = null; return(false); }
private void AddItem(FileItem item, int depth, ObservableCollection <KeyValuePair <string, PDFMergeItem> > mtree) { MainWinManager.mainWin.AddToProgress(1); // does the outline path have sub-outlines if (item.OutlinePath.FolderNamesCount - 1 >= depth) { // item has sub-outline string key = item.OutlinePath.FolderNames[depth]; // does the sub-outline already not exist? if (!ContainsKey(item.OutlinePath.FolderNames[depth], mtree)) { // sub-outline does not exist // create the node - then add go to the next level PDFMergeItem mi = new PDFMergeItem(key, TreeNodeType.BRANCH, 0, depth, item); mi.AddMergeItems(); mtree.Add(new KeyValuePair <string, PDFMergeItem>(key, mi)); } // did exist or now exists - goto next level PDFMergeItem innerItem; if (TryGetValue(key, mtree, out innerItem)) { AddItem(item, depth + 1, innerItem.MergeItems); } else { throw new MissingPrimaryKeyException(); } } else { // do not add twice if (ContainsKey(item.OutlinePath.FileWithoutExtension, mtree)) { return; } PDFMergeItem pmi = new PDFMergeItem( item.OutlinePath.FileWithoutExtension, TreeNodeType.LEAF, 0, depth, item); this.PropertyChanged += pmi.E; // does not have sub-outlines // add the leaf to the tree mtree.Add(new KeyValuePair <string, PDFMergeItem>( item.OutlinePath.FileWithoutExtension, pmi)); // OnPropertyChange("E"); // mtree.Add(new KeyValuePair<string, PDFMergeItem>( // item.OutlinePath.FileWithoutExtension, // new PDFMergeItem( // item.OutlinePath.FileWithoutExtension, // TreeNodeType.LEAF,0, depth,item))); } }