Example #1
0
 protected OneNoteDestination(OneNotePage page,
                              ICoreConfiguration coreConfiguration,
                              IGreenshotLanguage greenshotLanguage
                              ) : this(coreConfiguration, greenshotLanguage)
 {
     _page = page;
 }
Example #2
0
 /// <summary>
 ///     Export the capture to the specified page
 /// </summary>
 /// <param name="surfaceToUpload">ISurface</param>
 /// <param name="page">OneNotePage</param>
 /// <returns>bool true if everything worked</returns>
 public static bool ExportToPage(ISurface surfaceToUpload, OneNotePage page)
 {
     using (var oneNoteApplication = ComWrapper.GetOrCreateInstance <IOneNoteApplication>())
     {
         return(ExportToPage(oneNoteApplication, surfaceToUpload, page));
     }
 }
Example #3
0
        /// <summary>
        ///     Create a new page in the "unfiled notes section", with the title of the capture, and export the capture there.
        /// </summary>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <returns>bool true if export worked</returns>
        public static bool ExportToNewPage(ISurface surfaceToUpload)
        {
            using (var oneNoteApplication = ComWrapper.GetOrCreateInstance <IOneNoteApplication>())
            {
                var newPage = new OneNotePage();
                var unfiledNotesSectionId = GetSectionId(oneNoteApplication, SpecialLocation.slUnfiledNotesSection);
                if (unfiledNotesSectionId == null)
                {
                    return(false);
                }

                // ReSharper disable once RedundantAssignment
                oneNoteApplication.CreateNewPage(unfiledNotesSectionId, out var pageId, NewPageStyle.npsDefault);
                newPage.ID = pageId;
                // Set the new name, this is automatically done in the export to page
                newPage.Name = surfaceToUpload.CaptureDetails.Title;
                return(ExportToPage(oneNoteApplication, surfaceToUpload, newPage));
            }
        }
Example #4
0
 public OneNoteDestination(OneNotePage page)
 {
     this.page = page;
 }
Example #5
0
 public OneNoteDestination(OneNotePage page) : this()
 {
     _page = page;
 }
Example #6
0
 /// <summary>
 ///     Export the capture to the specified page
 /// </summary>
 /// <param name="oneNoteApplication">IOneNoteApplication</param>
 /// <param name="surfaceToUpload">ISurface</param>
 /// <param name="page">OneNotePage</param>
 /// <returns>bool true if everything worked</returns>
 private static bool ExportToPage(IOneNoteApplication oneNoteApplication, ISurface surfaceToUpload, OneNotePage page)
 {
     if (oneNoteApplication == null)
     {
         return(false);
     }
     using (var pngStream = new MemoryStream())
     {
         var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
         ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
         var base64String   = Convert.ToBase64String(pngStream.GetBuffer());
         var imageXmlStr    = string.Format(XmlImageContent, base64String, surfaceToUpload.Screenshot.Width, surfaceToUpload.Screenshot.Height);
         var pageChangesXml = string.Format(XmlOutline, imageXmlStr, page.ID, OnenoteNamespace2010, page.Name);
         Log.Info().WriteLine("Sending XML: {0}", pageChangesXml);
         oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
         try
         {
             oneNoteApplication.NavigateTo(page.ID, null, false);
         }
         catch (Exception ex)
         {
             Log.Warn().WriteLine(ex, "Unable to navigate to the target page");
         }
         return(true);
     }
 }
Example #7
0
        /// <summary>
        ///     Get the captions of all the open word documents
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <OneNotePage> GetPages()
        {
            using (var oneNoteApplication = ComWrapper.GetOrCreateInstance <IOneNoteApplication>())
            {
                if (oneNoteApplication == null)
                {
                    yield break;
                }

                // ReSharper disable once RedundantAssignment
                var notebookXml = "";
                oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010);
                if (string.IsNullOrEmpty(notebookXml))
                {
                    yield break;
                }

                using (var reader = new StringReader(notebookXml))
                    using (var xmlReader = new XmlTextReader(reader))
                    {
                        OneNoteSection  currentSection  = null;
                        OneNoteNotebook currentNotebook = null;
                        while (xmlReader.Read())
                        {
                            switch (xmlReader.Name)
                            {
                            case "one:Notebook":
                            {
                                var id = xmlReader.GetAttribute("ID");
                                if (id != null && (currentNotebook == null || !id.Equals(currentNotebook.ID)))
                                {
                                    currentNotebook = new OneNoteNotebook
                                    {
                                        ID   = xmlReader.GetAttribute("ID"),
                                        Name = xmlReader.GetAttribute("name")
                                    };
                                }

                                break;
                            }

                            case "one:Section":
                            {
                                var id = xmlReader.GetAttribute("ID");
                                if (id != null && (currentSection == null || !id.Equals(currentSection.ID)))
                                {
                                    currentSection = new OneNoteSection
                                    {
                                        ID     = xmlReader.GetAttribute("ID"),
                                        Name   = xmlReader.GetAttribute("name"),
                                        Parent = currentNotebook
                                    };
                                }

                                break;
                            }

                            case "one:Page":
                                // Skip deleted items
                                if ("true".Equals(xmlReader.GetAttribute("isInRecycleBin")))
                                {
                                    continue;
                                }
                                var page = new OneNotePage
                                {
                                    Parent = currentSection,
                                    Name   = xmlReader.GetAttribute("name"),
                                    ID     = xmlReader.GetAttribute("ID")
                                };
                                if (page.ID == null || page.Name == null)
                                {
                                    continue;
                                }
                                page.IsCurrentlyViewed = "true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"));
                                yield return(page);

                                break;
                            }
                        }
                    }
            }
        }