private async Task <Dictionary <string, OneNote.HyperlinkInfo> > GetHyperlinks( UI.ProgressDialog progress, CancellationToken token) { var catalog = fullCatalog ? OneNote.Scope.Notebooks : scope; return(await one.BuildHyperlinkMap(catalog, token, async (count) => { progress.SetMaximum(count); progress.SetMessage($"Scanning {count} page references"); await Task.Yield(); }, async() => { progress.Increment(); await Task.Yield(); })); }
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(); }); }
private async Task <SourceInfo> GetSource(string sourceId, string linkId) { var source = one.GetPage(sourceId, OneNote.PageDetail.BinaryData); if (source == null) { if (linkId == null) { // linkId should only be null from EmbedContent because it's using the local // reference to the page, but GetPage still couldn't find it so give up! return(null); } logger.WriteLine("recoverying from GetPage by mapping to hyperlink"); var token = new CancellationTokenSource(); var map = await one.BuildHyperlinkMap(OneNote.Scope.Sections, token.Token, async (count) => { await Task.Yield(); }, async() => { await Task.Yield(); }); if (map.ContainsKey(linkId)) { sourceId = map[linkId].PageID; source = one.GetPage(sourceId, OneNote.PageDetail.BinaryData); } if (source == null) { UIHelper.ShowInfo(one.Window, Resx.EmbedSubpageCommand_NoSource); return(null); } } var outRoot = source.Root.Elements(source.Namespace + "Outline") .FirstOrDefault(e => !e.Elements(ns + "Meta") .Any(m => m.Attribute("name").Value == MetaNames.TaggingBank)); if (outRoot == null) { UIHelper.ShowInfo(one.Window, Resx.EmbedSubpageCommand_NoContent); return(null); } PageNamespace.Set(ns); var outline = new Outline(outRoot); var snippets = outline.Elements(ns + "OEChildren") .Where(e => !e.Elements(ns + "OE") .Elements(ns + "Meta").Attributes(EmbeddingsMetaName).Any()); if (snippets == null || !snippets.Any()) { UIHelper.ShowInfo(one.Window, Resx.EmbedSubpageCommand_NoContent); return(null); } return(new SourceInfo { Snippets = snippets, SourceId = sourceId, Page = source, Outline = outline }); }