Shared Source Object Model Update 1

I wanted to share the status of our shared object model over on https://www.codeplex.com/onom

So far, we have 7 people willing to contribute in different roles.  This is a great start, and I look forward to more contributors as word gets out about this project.

 

Here's one way of looking at the work to complete and the benefits it produces.  Let's take a look at the relatively simple task of creating a new page with some text put on it.  This is what I did with my text importer powertoy. 

 

What I would like to see is the final code I need to write to take some text and put it on a page would be something like:

 

string myTextToSave="New Text for the new page";

page myNewPage= CreateNewPage();

AddStringToPage(myTextToSave);

CommitChanges();

 

Three lines.  I'm not 100% sold on the syntax or names of the commands, but you get the idea.

 

Compare this to what I had to write (appended below).  Ugh.  I promise not to show code like that too often in this blog.  Each time anyone creates an addin, most of the code below is cut and pasted in between addins since it's all needed.  The big benefit of the OM is preventing the cutting and pasting - the OM will provide all those common functions.

 

This highlights two areas where people can contribute.  First, we need help creating the final design of the objects.  Like I mentioned, I'm not completely committed to my syntax above, and you should feel to jump over to the discussion site and start throwing your suggestions out there.  Second, we need people to actually write the code (and test it too).

 

Comments, questions, criticisms and concerns always welcome,

John Guin

 

 

 

      string sectionID; //section where the new pages will be created

        XmlDocument xmlDoc = new XmlDocument();

        static String strNamespace = "https://schemas.microsoft.com/office/onenote/2007/onenote";

        private string m_xmlNewOutlineContent =

            "<one:Meta name=\u0022{2}\u0022 content=\u0022{1}\u0022/>" +

            "<one:OEChildren><one:HTMLBlock><one:Data><![CDATA[{0}]]></one:Data></one:HTMLBlock></one:OEChildren>";

        private string m_xmlNewOutline =

           "<?xml version=\u00221.0\u0022?>" +

           "<one:Page xmlns:one=\u0022{2}\u0022 ID=\u0022{1}\u0022>" +

           "<one:Title><one:OE><one:T><![CDATA[{3}]]></one:T></one:OE></one:Title>" +

           "<one:Outline>{0}</one:Outline></one:Page>";

 

        string[] notebookID, pathToNotebook;

        private string m_outlineIDMetaName = "OneNote Text File Importer";

        bool notebookSelected = false;

        string inputFileString, pathToTextFiles, newSectionName;

 

        OneNote.ApplicationClass onApp = new OneNote.ApplicationClass();

 

 

 

 

        /// <summary>

        /// create the page in the desired section with pText as body

        /// </summary>

        /// <param name="pageText"></param>

        private void CreatePage(string pText, string pageTitle)

        {

            pText = "<html><body>" + pText + "</body></html>";

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("one", strNamespace);

            //Create a page in the given sectionID

            string strNewPageID;

            onApp.CreateNewPage(sectionID, out strNewPageID, OneNote.NewPageStyle.npsBlankPageWithTitle);

            int outlineID = new System.Random().Next();

            //take the xml strings and add in the data unique to this book being imported

            string outlineContent = string.Format(m_xmlNewOutlineContent, pText, outlineID, m_outlineIDMetaName);

            string xml = string.Format(m_xmlNewOutline, outlineContent, strNewPageID, strNamespace, pageTitle);

            onApp.UpdatePageContent(xml, DateTime.MinValue);

        }

 

 

 

        }

    }

}