示例#1
0
        /// <summary>
        ///     Call this to get the running powerpoint application, or create a new instance
        /// </summary>
        /// <returns>IPowerpointApplication</returns>
        private static IPowerpointApplication GetOrCreatePowerpointApplication()
        {
            var powerpointApplication = ComWrapper.GetOrCreateInstance <IPowerpointApplication>();

            InitializeVariables(powerpointApplication);
            return(powerpointApplication);
        }
示例#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));
     }
 }
示例#3
0
        /// <summary>
        ///     Call this to get the running Excel application, or create a new instance
        /// </summary>
        /// <returns>IExcelApplication</returns>
        private static IExcelApplication GetOrCreateExcelApplication()
        {
            var excelApplication = ComWrapper.GetOrCreateInstance <IExcelApplication>();

            InitializeVariables(excelApplication);
            return(excelApplication);
        }
示例#4
0
        /// <summary>
        ///     Call this to get the running word application, or create a new instance
        /// </summary>
        /// <returns>IWordApplication</returns>
        private static IWordApplication GetOrCreateWordApplication()
        {
            var wordApplication = ComWrapper.GetOrCreateInstance <IWordApplication>();

            InitializeVariables(wordApplication);
            return(wordApplication);
        }
        /// <summary>
        ///     Call this to get the running outlook application, or create a new instance
        /// </summary>
        /// <returns>IOutlookApplication</returns>
        private static IOutlookApplication GetOrCreateOutlookApplication()
        {
            var outlookApplication = ComWrapper.GetOrCreateInstance <IOutlookApplication>();

            InitializeVariables(outlookApplication);
            return(outlookApplication);
        }
示例#6
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));
            }
        }
示例#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;
                            }
                        }
                    }
            }
        }