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()); }
internal static string GetSectionGroupId(this OneNote.IApplication application, string groupName, string notebookId) { var objId = application.GetObjectId(notebookId, ONE_HS_CHILDREN, groupName); // Open the section group; create it if it doesn't exist var cft = (objId == null) ? ONE_CFT_FOLDER : ONE_CFT_NONE; application.OpenHierarchy(groupName, notebookId, out objId, cft); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}; SectionGroup {2}", groupName, objId, (cft == ONE_CFT_NONE) ? STATUS_OPENED : STATUS_CREATED); using (var filter = new MessageFilter()) { // Synchronize SectionGroup child content if (cft == ONE_CFT_NONE) { application.SyncChildren(objId); } } return(objId); }
static string GetNotebookPath(this OneNote.IApplication application, string notebookName) { var account = Properties.Settings.Default.StorageAccount; if (account == Config.StorageAccount.DEFAULT) { string path; application.GetSpecialLocation(ONE_SL_DEFAULT_NOTEBOOK_FOLDER, out path); return(Path.Combine(path, notebookName)); } // Normalize notebook folder relative path (user configured) const char Slash = '/'; var folder = Component.AppSettings[API_NOTEBOOK_FOLDER_PROPERTY]? .Replace('\\', Slash).TrimEnd(Slash).TrimStart(Slash).Trim() ?? DEFAULT_NOTEBOOK_FOLDER; var cid = new Config.StorageAccount().CID[account]; var notebookUri = new Uri($"/{cid}/{folder}/{notebookName}/", UriKind.Relative); Uri result = null; var valid = Uri.TryCreate(s_webDAV_Uri, notebookUri, out result); if (!valid || !result.AbsolutePath.StartsWith($"/{cid}/", StringComparison.InvariantCulture)) { var message = "Notebook URI is invalid."; throw new COMException(message, HR_INVALID_NAME); } return(result.AbsoluteUri); }
internal static string GetSectionId(this OneNote.IApplication application, string sectionName, string groupId) { var objId = application.GetObjectId(groupId, ONE_HS_SECTIONS, sectionName); // Open the section; create it if it doesn't exist var cft = (objId == null) ? ONE_CFT_SECTION : ONE_CFT_NONE; var fileName = sectionName + ".one"; application.OpenHierarchy(fileName, groupId, out objId, cft); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}; Section {2}", sectionName, objId, (cft == ONE_CFT_NONE) ? STATUS_OPENED : STATUS_CREATED); using (var filter = new MessageFilter()) { // Synchronize Section child content if (cft == ONE_CFT_NONE) { application.SyncChildren(objId); } } return(objId); }
internal static string GetPageId(this OneNote.IApplication application, string pageName, string sectionId) { var objId = application.GetObjectId(sectionId, ONE_HS_PAGES, pageName); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}", pageName, objId); return(objId); }
/// <summary> /// XML document wrapper for OneNote Application.GetPageContent method. /// </summary> /// <param name="application">A reference to the OneNote Application /// Interface.</param> /// <param name="pageId">A string containing the OneNote Page ID to be /// retrieved.</param> /// <returns>An XML document containing the page content.</returns> internal static XDocument GetPage(this OneNote.IApplication application, string pageId) { string xml; application.GetPageContent(pageId, out xml, OneNote.PageInfo.piAll, ONE_XML_SCHEMA); return(XDocument.Parse(xml)); }
internal static string GetSectionGroupId(this OneNote.IApplication application, string groupName, string notebookId) { string objId; application.OpenHierarchy(groupName, notebookId, out objId, ONE_CFT_FOLDER); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}", groupName, objId); return(objId); }
internal static string GetSectionId(this OneNote.IApplication application, string sectionName, string groupId) { string fileName = sectionName + ".one", objId; application.OpenHierarchy(fileName, groupId, out objId, ONE_CFT_SECTION); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}", sectionName, objId); return(objId); }
internal static PageContext CurrentWindow(OneNote.IApplication application) { var context = new PageContext(application); var currentWindow = application.Windows.CurrentWindow; context.NotebookId = currentWindow.CurrentNotebookId; context.SectionGroupId = currentWindow.CurrentSectionGroupId; context.SectionId = currentWindow.CurrentSectionId; context.PageId = currentWindow.CurrentPageId; context.PageName = context._CurrentPage?.Root.Attribute("name").Value; return(context); }
CreatePageTemplate(OneNote.IApplication application) { var type = PageTemplateType; Tracer.WriteTraceMethodLine("Template = {0}", type.FullName); var flags = BindingFlags.NonPublic | BindingFlags.Instance; return((IPageTemplatePresenter) Activator.CreateInstance( type, flags, null, new[] { application }, null)); }
internal static string GetNotebookId(this OneNote.IApplication application, string notebookName) { string objId, path, s = string.Empty; application.GetSpecialLocation(ONE_SL_DEFAULT_NOTEBOOK_FOLDER, out path); var notebookPath = Path.Combine(path, notebookName); application.OpenHierarchy(notebookPath, s, out objId, ONE_CFT_NOTEBOOK); Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}", notebookName, objId); return(objId); }
internal PageContext(OneNote.IApplication application, PageTitleEnum pageTitle) : this(application) { var today = DateTime.Today; var sectionGroup = today.Year.ToString(); var section = today.ToString("MMMM"); NotebookId = _Application.GetNotebookId(Component.FriendlyName); SectionGroupId = _Application.GetSectionGroupId(sectionGroup, NotebookId); SectionId = _Application.GetSectionId(section, SectionGroupId); PageName = today.Format(pageTitle); PageId = _Application.GetPageId(PageName, SectionId); }
/// <summary> /// XML document wrapper for OneNote Application.CreateNewPage method. /// </summary> /// <param name="application">A reference to the OneNote Application /// Interface.</param> /// <param name="sectionId">A string containing the OneNote Section ID in /// which the new page is created.</param> /// <param name="pageId">(Output parameter) A string containing the OneNote /// ID for the new Page.</param> /// <returns>An XML document containing the new blank page with title.</returns> internal static XDocument CreatePage(this OneNote.IApplication application, string sectionId, out string pageId) { application.CreateNewPage(sectionId, out pageId, OneNote.NewPageStyle.npsBlankPageWithTitle); var xmlDocument = GetPage(application, pageId); // Take snapshot of OneNote XML for page style: // OneNote.NewPageStyle.npsBlankPageWithTitle // Utils.WinHelper.SendXmlToClipboard(xmlDocument.ToString()); return(xmlDocument); }
/// <summary> /// XML document wrapper for OneNote Application.UpdatePageContent method. /// </summary> /// <param name="application">A reference to the OneNote Application /// Interface.</param> /// <param name="document">A XML document that contains the updated Page /// content.</param> /// <param name="lastModified">A DateTime value that must match the Page /// lastModifiedTime attribute value.</param> internal static void UpdatePage(this OneNote.IApplication application, XDocument document, DateTime lastModified) { var one = application.GetXmlNamespace(); if (document.Root.Name != (one + "Page")) { throw new ArgumentException( "Document root element name != \"one:Page\"", nameof(document)); } var xml = document.ToString(); // Take snapshot of OneNote XML before updating page content // Utils.WinHelper.SendXmlToClipboard(xml); application.UpdatePageContent(xml, lastModified, ONE_XML_SCHEMA); }
internal static string GetNotebookId(this OneNote.IApplication application, string notebookName) { string objId, s = string.Empty; var path = application.GetNotebookPath(notebookName); Tracer.WriteDebugLine("Path = {0}", path); // Open the notebook; create it if it doesn't exist var cft = ONE_CFT_NONE; try { application.OpenHierarchy(path, s, out objId, cft); } catch (COMException ce) { if (ce.HResult == HR_FILE_DOES_NOT_EXIST) { cft = ONE_CFT_NOTEBOOK; application.OpenHierarchy(path, s, out objId, cft); } else { throw; } } Tracer.WriteTraceMethodLine("Name = {0}, ID = {1}; Notebook {2}", notebookName, objId, (cft == ONE_CFT_NONE) ? STATUS_OPENED : STATUS_CREATED); using (var filter = new MessageFilter()) { application.NavigateTo(objId); // Synchronize Notebook child content if (cft == ONE_CFT_NONE) { application.SyncChildren(objId); } } return(objId); }
/// <summary> /// Synchronize child XML content. /// </summary> /// <param name="application">A reference to the OneNote Application /// Interface.</param> /// <param name="objId">The OneNote parent object ID to be synced.</param> static void SyncChildren(this OneNote.IApplication application, string objId) { Tracer.WriteTraceMethodLine(); string xml; application.SyncHierarchy(objId); application.GetHierarchy(objId, ONE_HS_CHILDREN, out xml, ONE_XML_SCHEMA); if (XDocument.Parse(xml).Root.IsEmpty) { const HRESULT HrNotYetSynchronized = Utils.ExceptionHandler.SYNCHRONIZING_NOTEBOOK; throw new COMException("Content not yet synced.", HrNotYetSynchronized); } }
internal static XNamespace GetXmlNamespace( this OneNote.IApplication application) { if (s_namespace == null) { string xml = null; lock (s_syncApplication) { if (s_namespace == null) { // Set OneNote XML Namespace value application.GetHierarchy(null, ONE_HS_NOTEBOOKS, out xml, ONE_XML_SCHEMA); s_namespace = XDocument.Parse(xml).Root.Name.Namespace; } } } return(s_namespace); }
internal PageTemplate(OneNote.IApplication application) { try { Application = application; var i = 0; var symbol = Component.AppSettings[TEMPLATES_BULLET_SYMBOL_PROPERTY]; BulletSymbol = int.TryParse(symbol, out i) ? symbol : "2"; ExclusiveScheduler = new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler; ExclusiveTaskFactory = new TaskFactory(ExclusiveScheduler); OneNS = application.GetXmlNamespace(); } catch (Exception ex) { Utils.ExceptionHandler.HandleException(ex); } }
private void BindTemplate(OneNote.IApplication application) { var template = PageTemplate; if (template != null) { UnbindTemplate(template); } var model = PageSettings; template = TemplateFactory.CreatePageTemplate(application); model.ColorChanged += template.ChangeColor; model.RuleLinesHorizontalColorChanged += template.ChangeRuleLinesHorizontalColor; model.RuleLinesHorizontalSpacingChanged += template.ChangeRuleLinesHorizontalSpacing; model.RuleLinesMarginColorChanged += template.ChangeRuleLinesMarginColor; model.RuleLinesVisibleChanged += template.ChangeRuleLinesVisible; model.TitleChanged += template.ChangeTitle; PageTemplate = template; Tracer.WriteTraceMethodLine(); }
internal HappyDayPageTemplate(OneNote.IApplication application) : base(application) { }
internal BulletPageTemplate(OneNote.IApplication application) : base(application) { }
private PageContext(OneNote.IApplication application) { _Application = application; }
internal OrdinalDayPageTemplate(OneNote.IApplication application) : base(application) { }
internal DefaultPageTemplate(OneNote.IApplication application) : base(application) { }
internal RibbonView(OneNote.IApplication application) { Tracer.WriteTraceTypeLine(); System.Windows.Forms.Application.EnableVisualStyles(); _binder = new Binder(application); }
/// <summary> /// Provides a one-way binding between the page settings data model /// (source) and page template presentation logic (target). /// </summary> internal Binder(OneNote.IApplication application) { PageSettings = PageSettingsDataSource.Load(); BindTemplate(application); }
internal void Rebind(OneNote.IApplication application) => BindTemplate(application);