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 }); }