예제 #1
0
        public void GetPage()
        {
            var id = "0-d17714e498b540ae8bc5656b55049fc3!145-3AE547978144BF51!147";

            var factory = new GraphPageFactory();
            var page    = factory.GetItem(id);

            Assert.IsNotNull(page);
            Assert.IsTrue(page.Id.Equals(id));
        }
예제 #2
0
파일: Program.cs 프로젝트: VicBirin/OneNote
        /// <summary>
        /// Creates OneNote page
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        private static Page OpenOrCreatePage(Document document)
        {
            Console.WriteLine("Loading pages ...");

            string title = "Microsoft Graph API example";

            var pageFactory = new GraphPageFactory();
            var allPages    = pageFactory.GetAllItems(document.Id);
            var page        = allPages.FirstOrDefault(p => p.Title.Equals(title));

            if (page != null)
            {
                return(pageFactory.GetItem(page.Id));
            }


            // create sample html page document and add some fields
            var sampleDoc = new HtmlAgilityPack.HtmlDocument();

            sampleDoc.LoadHtml(Resources.SamplePageHtml);
            var body      = sampleDoc.DocumentNode.SelectSingleNode("//body");
            var textField = sampleDoc.CreateElement("div");

            textField.SetAttributeValue("id", "dynamicElement");
            textField.InnerHtml = "Dynamically added DIV element #";
            body.AppendChild(textField);

            //save html document as HTML
            string htmlContent;

            using (var htmlStream = new MemoryStream())
            {
                sampleDoc.Save(htmlStream, Encoding.UTF8);
                htmlStream.Position = 0;

                byte[] buffer = new byte[htmlStream.Length];
                htmlStream.Read(buffer, 0, buffer.Length);
                htmlContent = Encoding.UTF8.GetString(buffer);
            }


            //MemoryStream stream = ReadImage();
            //page = pageFactory.AddItem(new Page { Content = htmlContent, StreamContent = stream, Title = title }, section.Id);

            Console.WriteLine("Created page 'Microsoft Graph API example'...");

            return(page);
        }