/// <summary> /// Determine if two tags a are equal /// </summary> /// <param name="obj">the other tag for equality test</param> /// <returns>true if both tags are equal; false otherwise</returns> public override bool Equals(object obj) { TagPageSet other = obj as TagPageSet; if (other != null) { return(TagName.Equals(other.TagName)); } return(false); }
/// <summary> /// Extract tags from page descriptors. /// </summary> /// <param name="pageDescriptors"> /// XML document describing pages in the OneNote hierarchy or search result. /// </param> /// <param name="selectedPagesOnly">true to process only pages selected by user</param> /// <param name="omitUntaggedPages">drip untagged pages</param> internal void ExtractTags(XDocument pageDescriptors, bool selectedPagesOnly, bool omitUntaggedPages = false) { // parse the search results _tags.Clear(); _pages.Clear(); try { XNamespace one = pageDescriptors.Root.GetNamespaceOfPrefix("one"); Dictionary <string, TagPageSet> tags = new Dictionary <string, TagPageSet>(); foreach (XElement page in pageDescriptors.Descendants(one.GetName("Page"))) { TaggedPage tp = new TaggedPage(page); if (selectedPagesOnly && !tp.IsSelected) { continue; } // assign Tags int tagcount = 0; foreach (string tagname in tp.TagNames) { tagcount++; TagPageSet t; if (!tags.TryGetValue(tagname, out t)) { t = new TagPageSet(tagname); tags.Add(tagname, t); } t.AddPage(tp); tp.Tags.Add(t); } if (!omitUntaggedPages || tagcount > 0) { _pages.Add(tp.Key, tp); } } // bulk update for performance reasons _tags.UnionWith(tags.Values); TraceLogger.Log(TraceCategory.Info(), "Extracted {0} tags from {1} pages.", _tags.Count, _pages.Count); } catch (Exception ex) { TraceLogger.Log(TraceCategory.Error(), "Parsing Hierarchy data failed: {0}", ex); TraceLogger.Flush(); } }