Ejemplo n.º 1
0
        public override async Task Execute(params object[] args)
        {
            if (args.Length > 0 && args[0] is string refresh && refresh == "refresh")
            {
                synopses   = args.Any(a => a as string == "synopsis");
                unindexed  = args.Any(a => a as string == "unindexed");
                refreshing = Refresh();
            }

            if (!refreshing)
            {
                using (var dialog = new LinkDialog())
                {
                    if (dialog.ShowDialog(owner) != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    scope     = dialog.Scope;
                    synopses  = dialog.Synopsis;
                    unindexed = dialog.Unindexed;
                }
            }

            var progressDialog = new UI.ProgressDialog(Execute);
            await progressDialog.RunModeless();
        }
Ejemplo n.º 2
0
        // async event handlers should be be declared 'async void'
        private async void ChangeScope(object sender, EventArgs e)
        {
            tagsFlow.Controls.Clear();

            OneNote.Scope scope = OneNote.Scope.Notebooks;
            switch (scopeBox.SelectedIndex)
            {
            case 1: scope = OneNote.Scope.Sections; break;

            case 2: scope = OneNote.Scope.Pages; break;
            }

            var tags = await TagHelpers.FetchRecentTags(scope, 30);

            if (tags.Count > 0)
            {
                var sorted = tags.OrderBy(k => k.Key.StartsWith("#") ? k.Key.Substring(1) : k.Key);

                foreach (var s in sorted)
                {
                    var tag = new TagCheckBox(s.Value);
                    tag.CheckedChanged += ChangeTagSelection;
                    tagsFlow.Controls.Add(tag);
                }
            }
        }
Ejemplo n.º 3
0
        public override async Task Execute(params object[] args)
        {
            using (var dialog = new MapDialog())
            {
                if (dialog.ShowDialog(owner) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                scope       = dialog.Scope;
                fullCatalog = dialog.FullCatalog;
            }

            var progressDialog = new UI.ProgressDialog(Execute);
            await progressDialog.RunModeless();
        }
Ejemplo n.º 4
0
        public void SetScope(OneNote.Scope scope)
        {
            switch (scope)
            {
            case OneNote.Scope.Children: scopeBox.SelectedIndex = 0; break;

            case OneNote.Scope.Pages: scopeBox.SelectedIndex = 1; break;

            case OneNote.Scope.Sections: scopeBox.SelectedIndex = 2; break;

            case OneNote.Scope.Notebooks: scopeBox.SelectedIndex = 3; break;

            default: return;
            }

            scopeBox.Enabled = false;
        }
Ejemplo n.º 5
0
        public override async Task Execute(params object[] args)
        {
            using (var dialog = new RefreshPageLinksDialog())
            {
                if (dialog.ShowDialog(owner) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                scope = dialog.Scope;
            }

            using (var one = new OneNote(out var page, out _))
            {
                // cleaned page title
                title = Unstamp(page.Title);

                // page's hyperlink section-id + page-id
                var uri   = one.GetHyperlink(page.PageId, string.Empty);
                var match = Regex.Match(uri, "section-id={[0-9A-F-]+}&page-id={[0-9A-F-]+}&");
                if (match.Success)
                {
                    // ampersands aren't escaped in hyperlinks but they will be in XML
                    keys = match.Groups[0].Value.Replace("&", "&");
                }
                else
                {
                    logger.WriteLine($"error finding section/page IDs in page hyperlink");
                    return;
                }
            }

            var progressDialog = new UI.ProgressDialog(Execute);
            await progressDialog.RunModeless((s, a) =>
            {
                if (updates > 0)
                {
                    UIHelper.ShowInfo(string.Format(Resx.RefreshPageLinksCommand_updated, updates));
                }
                else
                {
                    UIHelper.ShowInfo(Resx.RefreshPageLinksCommand_none);
                }
            });
        }
Ejemplo n.º 6
0
        public async Task BuildHyperlinkMap(
            OneNote.Scope scope, UI.ProgressDialog progress, CancellationToken token)
        {
            logger.WriteLine("building hyperlink map");

            map = await one.BuildHyperlinkMap(
                scope,
                token,
                async (count) =>
            {
                progress.SetMaximum(count);
                progress.SetMessage($"Scanning {count} page references");
                await Task.Yield();
            },
                async() =>
            {
                progress.Increment();
                await Task.Yield();
            });
        }
Ejemplo n.º 7
0
        private bool Refresh()
        {
            using (one = new OneNote(out page, out ns))
            {
                // find linked references content block...

                var meta = page.Root.Descendants(ns + "Meta")
                           .FirstOrDefault(e => e.Attribute("name").Value == LinkRefsMeta);

                if (meta == null)
                {
                    return(false);
                }

                if (!Enum.TryParse(meta.Attribute("content").Value, out scope))
                {
                    scope = OneNote.Scope.Pages;
                }

                // TODO: deprecated; determine options... if not on refresh URI

                if (!synopses && !unindexed)
                {
                    var meta2 = meta.Parent.Elements(ns + "Meta")
                                .FirstOrDefault(e => e.Attribute("name").Value == SynopsisMeta);

                    if (meta2 != null)
                    {
                        bool.TryParse(meta2.Attribute("content").Value, out synopses);
                    }
                }

                // remove the containing OE so it can be regenerated
                meta.Parent.Remove();
                return(true);
            }
        }
Ejemplo n.º 8
0
        public static async Task <Dictionary <string, string> > FetchRecentTags(OneNote.Scope scope, int poolSize)
        {
            using (var one = new OneNote())
            {
                // builds a hierarchy of all notebooks with notebook/section/page nodes
                // and each Page has a Meta of tags

                var scopeId = string.Empty;
                switch (scope)
                {
                case OneNote.Scope.Sections: scopeId = one.CurrentNotebookId; break;

                case OneNote.Scope.Pages: scopeId = one.CurrentSectionId; break;
                }

                var root = await one.SearchMeta(scopeId, Page.TaggingMetaName);

                var ns    = root.GetNamespaceOfPrefix("one");
                var pages = root.Descendants(ns + "Page")
                            .OrderByDescending(e => e.Attribute("lastModifiedTime").Value);

                var tags = new Dictionary <string, string>();

                var count = 0;
                foreach (var page in pages)
                {
                    var meta = page.Elements(ns + "Meta")
                               .FirstOrDefault(e => e.Attribute("name").Value == Page.TaggingMetaName);

                    if (meta != null)
                    {
                        // tags are entered in user's language so split on their separator
                        var parts = meta.Attribute("content").Value.Split(
                            new string[] { AddIn.Culture.TextInfo.ListSeparator },
                            StringSplitOptions.RemoveEmptyEntries);

                        foreach (var part in parts)
                        {
                            var p   = part.Trim();
                            var key = p.ToLower();
                            if (!tags.ContainsKey(key))
                            {
                                tags.Add(key, p);

                                count++;
                                if (count >= poolSize)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (count >= poolSize)
                    {
                        break;
                    }
                }

                return(tags);
            }
        }