Exemplo n.º 1
0
        /// <summary>
        /// Find tagged OneNote pages in a scope.
        /// </summary>
        /// <param name="scopeID">
        /// OneNote id of the scope to search for pages. This is the element ID of a
        /// notebook, section group, or section. If given as null or empty string scope is
        /// the entire set of notebooks open in OneNote.
        /// </param>
        internal void FindTaggedPages(string scopeID)
        {
            // collect all page tags on pages which have page tags. Tag search appears to
            // be broken using work around
            if (Properties.Settings.Default.UseWindowsSearch)
            {
                ExtractTags(_onenote.FindPagesByMetadata(scopeID, OneNotePageProxy.META_NAME), selectedPagesOnly: false);
            }
            else
            {
                ExtractTags(_onenote.GetHierarchy(scopeID, HierarchyScope.hsPages), selectedPagesOnly: false, omitUntaggedPages: true);
            }

            // attempt to automatically update the tag list, if we have collected all used tags
            HashSet <string> knownTags = new HashSet <String>(OneNotePageProxy.ParseTags(Properties.Settings.Default.KnownTags));
            int countBefore            = knownTags.Count;

            // update the list of known tags by adding tags from search result
            foreach (KeyValuePair <string, TagPageSet> t in _tags)
            {
                knownTags.Add(t.Key);
            }

            if (countBefore != knownTags.Count)
            { // updated tag suggestions
                string[] sortedTags = knownTags.ToArray();
                Array.Sort(sortedTags);
                Properties.Settings.Default.KnownTags = string.Join(",", sortedTags);
            }
        }
 private T[] LoadSuggestedTagsAction()
 {
     return((from string t in OneNotePageProxy.ParseTags(Properties.Settings.Default.KnownTags) select new T()
     {
         TagName = t
     }).ToArray());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create an internal representation of a page returned from FindMeta
        /// </summary>
        /// <param name="page">&lt;one:Page&gt; element</param>
        internal TaggedPage(XElement page)
        {
            XNamespace one = page.GetNamespaceOfPrefix("one");

            ID    = page.Attribute("ID").Value;
            Title = page.Attribute("name").Value;
            var rbin = page.Attribute("isInRecycleBin");

            IsInRecycleBin = "true".Equals(rbin != null ? rbin.Value : String.Empty);
            XAttribute selected = page.Attribute("selected");

            if (selected != null && "all".Equals(selected.Value))
            {
                _isSelected = true;
            }
            XElement meta = page.Elements(one.GetName("Meta")).FirstOrDefault(m => OneNotePageProxy.META_NAME.Equals(m.Attribute("name").Value));

            if (meta != null)
            {
                _tagnames = OneNotePageProxy.ParseTags(meta.Attribute("content").Value);
            }
            else
            {
                _tagnames = new string[0];
            }

            // build the items path
            LinkedList <HierarchyElement> path = new LinkedList <HierarchyElement>();
            XElement e = page;

            while (e.Parent != null)
            {
                e = e.Parent;
                XAttribute id   = e.Attribute("ID");
                XAttribute name = e.Attribute("name");
                if (id == null || name == null)
                {
                    break;
                }
                path.AddFirst(new HierarchyElement(e.Attribute("ID").Value, e.Attribute("name").Value));
            }
            _path = path;
        }