static string GetObjectId(this OneNote.IApplication application,
                                  string parentId, OneNote.HierarchyScope scope, string objectName)
        {
            string xml;

            application.GetHierarchy(parentId, scope, out xml, ONE_XML_SCHEMA);

            // Take snapshot of OneNote XML Hierarchy
            //Utils.WinHelper.SendXmlToClipboard(xml);

            var doc      = XDocument.Parse(xml);
            var nodeName = string.Empty;

            switch (scope)
            {
            case ONE_HS_PAGES: nodeName = "Page"; break;

            case ONE_HS_SECTIONS: nodeName = "Section"; break;

            case ONE_HS_CHILDREN: nodeName = "SectionGroup"; break;

            case ONE_HS_NOTEBOOKS: nodeName = "Notebook"; break;

            default: return(null);
            }

            // Each hierarchy scope element has a name attribute
            // E.G., For a Page element, it's name attribute contains the page title

            return(doc.Descendants(application.GetXmlNamespace() + nodeName)
                   .Where(x => x.Attribute("name").Value == objectName)
                   .Select(x => x.Attribute("ID").Value)
                   .FirstOrDefault());
        }
Пример #2
0
        protected override void ProcessRecord()
        {
            // start node ID 'null' gets root node XML
            string startNodeId = null;

            if (this.Object != null)
            {
                startNodeId = ((IIdentifiableObject)this.Object).ID;
            }
            else if (this.ID != null)
            {
                startNodeId = this.ID;
            }

            Microsoft.Office.Interop.OneNote.HierarchyScope rawScope = (Microsoft.Office.Interop.OneNote.HierarchyScope) this.Scope;

            string xml;

            ApplicationManager.Application.GetHierarchy(startNodeId, rawScope, out xml);

            WriteObject(xml);
        }