コード例 #1
0
        private void DoExportItem(XPathNavigator nav)
        {
            // Create a new page in the section "General", with the
            // title from the item:
            string title = StripAndDecode(nav.Evaluate("string(//item/title/text())").ToString());
            Page   p     = new Page(configInfo.Page, title);

            p.Date = DateTime.Parse(nav.Evaluate("string(//item/pubDate/text())").ToString());

            // Create a new Outline, and add some content to it:
            OutlineObject outline = new OutlineObject();

            if (configInfo.ItemLinkBelowContent)
            {
                outline.AddContent(new HtmlContent(String.Format(configInfo.ItemContentTemplate, nav.Evaluate("string(//item/description/text())").ToString())));
                outline.AddContent(new HtmlContent(String.Format(configInfo.ItemLinkTemplate, nav.Evaluate("string(//item/link/text())").ToString())));
            }
            else
            {
                outline.AddContent(new HtmlContent(String.Format(configInfo.ItemLinkTemplate, nav.Evaluate("string(//item/link/text())").ToString())));
                outline.AddContent(new HtmlContent(String.Format(configInfo.ItemContentTemplate, nav.Evaluate("string(//item/description/text())").ToString())));
            }
            // Add the outline to our page:
            p.AddObject(outline);
            // Commit the changes to OneNote, and set the actively viewed page:
            p.Commit();
            p.NavigateTo();
        }
コード例 #2
0
ファイル: OneNote.cs プロジェクト: brhinescot/CropperPlugins
        private void SendToOneNote(byte[] imageData, string title)
        {
            Page          page1    = new Page("Side Notes.one", title);
            OutlineObject obj1     = new OutlineObject();
            ImageContent  content1 = new ImageContent(imageData);
            HtmlContent   content2 = new HtmlContent("<font size=small>Capture taken at " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "</font>");

            obj1.AddContent(content1);
            obj1.AddContent(content2);
            page1.AddObject(obj1);
            page1.Commit();
            page1.NavigateTo();
        }
コード例 #3
0
        public void Image()
        {
            Page page = new Page(sectionPath, pageTitle);

            OutlineObject outline = new OutlineObject();

            page.AddObject(outline);

            Bitmap bitmap = new Bitmap(200, 200);

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    bitmap.SetPixel(x, y, Color.FromArgb(255, 0, 128));
                }
            }

            MemoryStream stream = new MemoryStream();

            bitmap.Save(stream, ImageFormat.Bmp);

            outline.AddContent(new ImageContent(stream.ToArray()));

            XmlDocument serializedPage = new XmlDocument();

            serializedPage.LoadXml(page.ToString());
        }
コード例 #4
0
        public void Serialization()
        {
            Page page = new Page(sectionPath);

            string      htmlString  = "<html><body><p>hello world</p></body></html>";
            HtmlContent htmlContent = new HtmlContent(htmlString);

            OutlineObject outlineObject = new OutlineObject();

            outlineObject.AddContent(htmlContent);

            page.AddObject(outlineObject);

            IFormatter formatter  = new BinaryFormatter();
            Stream     serialized = new MemoryStream();

            formatter.Serialize(serialized, page);

            serialized.Seek(0, SeekOrigin.Begin);
            Page deserialized = (Page)formatter.Deserialize(serialized);

            serialized.Close();

            Assert.AreEqual(page, deserialized);
            Assert.AreEqual(page.ToString(), deserialized.ToString());
        }
コード例 #5
0
ファイル: Post2OneNotePlugin.cs プロジェクト: mo5h/omeo
            private void PostItem(string html, bool isHtml, string name)
            {
                try
                {
                    Page          p       = new Page("General.one", "Import from " + Core.ProductFullName + ": " + name);
                    OutlineObject outline = new OutlineObject();

                    if (!isHtml)
                    {
                        html = HttpUtility.HtmlEncode(html);
                    }

                    outline.AddContent(new HtmlContent(html));
                    p.AddObject(outline);
                    p.Commit();
                    p.NavigateTo();
                }
                catch
                {
                    Core.UIManager.QueueUIJob(new ErrorReportJob(ReportError), new object[] { "Can not create OneNote post. Is OneNote installed?" });
                }
            }
コード例 #6
0
        public void Text()
        {
            Page page = new Page(sectionPath);

            string      htmlString  = "hello world";
            HtmlContent htmlContent = new HtmlContent(htmlString);

            Assert.IsNotNull(htmlContent.HtmlData);
            OutlineObject outlineObject = new OutlineObject();

            outlineObject.AddContent(htmlContent);

            page.AddObject(outlineObject);

            XmlDocument serializedPage = new XmlDocument();

            serializedPage.LoadXml(page.ToString());

            XmlElement import = serializedPage.DocumentElement;

            string validHtml = "<html><body>" + htmlString + "</body></html>";

            Assert.AreEqual(validHtml, import.InnerText);
        }
コード例 #7
0
        public void Html()
        {
            Page page = new Page(sectionPath);

            string      htmlString  = "<html><body><p>hello world</p></body></html>";
            HtmlContent htmlContent = new HtmlContent(htmlString);

            Assert.IsNotNull(htmlContent.HtmlData);

            OutlineObject outlineObject = new OutlineObject();

            outlineObject.AddContent(htmlContent);

            int cContent = 0;

            foreach (OutlineContent content in outlineObject)
            {
                Assert.AreSame(htmlContent, content);
                cContent++;
            }
            Assert.IsTrue(cContent == 1);

            page.AddObject(outlineObject);

            int cObjects = 0;

            foreach (PageObject pageObject in page)
            {
                Assert.AreSame(outlineObject, pageObject);
                cObjects++;
            }
            Assert.IsTrue(cObjects == 1);

            XmlDocument serializedPage = new XmlDocument();

            serializedPage.LoadXml(page.ToString());

            XmlElement import = serializedPage.DocumentElement;

            Assert.IsTrue(import.ChildNodes.Count == 2);

            XmlElement placeObjectsVerb = (XmlElement)import.ChildNodes.Item(1);

            Assert.IsTrue(placeObjectsVerb.ChildNodes.Count == 1);

            XmlElement objectElement = (XmlElement)placeObjectsVerb.ChildNodes.Item(0);

            Assert.IsTrue(objectElement.ChildNodes.Count == 2);

            XmlElement positionElement = (XmlElement)objectElement.ChildNodes.Item(0);

            Assert.AreEqual(positionElement.GetAttribute("x"), outlineObject.Position.X.ToString());
            Assert.AreEqual(positionElement.GetAttribute("y"), outlineObject.Position.Y.ToString());

            XmlElement outlineElement = (XmlElement)objectElement.ChildNodes.Item(1);

            Assert.IsTrue(outlineElement.ChildNodes.Count == 1);

            XmlElement htmlElement = (XmlElement)outlineElement.ChildNodes.Item(0);
            XmlElement dataElement = (XmlElement)htmlElement.ChildNodes.Item(0);

            Assert.AreEqual(htmlString, dataElement.InnerText);
        }