Obtains data from epub file
コード例 #1
0
		public static void MyClassInitialize(TestContext testContext)
		{
			if (!Directory.Exists(Utility.RootFolder))
			{
				Directory.CreateDirectory(Utility.RootFolder);
			}

			_mEpubReader = new EpubReader(TestEpubPath, Utility.RootFolder);
		}
コード例 #2
0
		public void ValidateNonExistFile()
		{
			var epubReader = new EpubReader(Utility.NonExistentInputFile, Utility.RootFolder);
		}
コード例 #3
0
		/// <summary>
		/// Converts the ePub document input file into OneNote
		/// </summary>
		/// <param name="inputFile"></param>
		/// <param name="outputDir"></param>
		/// <returns></returns>
		public virtual bool ConvertEpubToOneNote(string inputFile, string outputDir)
		{
			try
			{
				// Initialize epub reader class
				var epub = new EpubReader(inputFile, outputDir);

				// Get the page contents
				List<string> pageTitles = epub.GetPageTitles();
				List<HtmlDocument> pagesHtml = epub.GetPagesAsHtmlDocuments();
				List<string> pagePaths = epub.GetPagePaths();
				Dictionary<string, int> pagesLevel = epub.GetPagesLevel();

				// Create a new OneNote Notebook
				var note = new OneNoteGenerator(outputDir);
				string notebookId = note.CreateNotebook(GetSupportedInputFormat());
				string sectionId = note.CreateSection(epub.GetTitle(), notebookId);

				// Create pages
				var pageIds = pageTitles.Select(pageTitle => note.CreatePage(pageTitle, sectionId)).ToArray();

				// Get links to pages
				var pageLinks = pageIds.Select(pageId => note.GetHyperLinkToObject(pageId)).ToList();

				// Replace links to .html with .one
				ReplaceEpubLinksFromHtmlToOneNote(pagesHtml, pagePaths, pageLinks);

				// Add content to pages
				for (var i = 0; i < pageIds.Length; i++)
				{
					note.AppendPageContentAsHtmlBlock(pageIds[i], pagesHtml[i].DocumentNode.OuterHtml);
					if (pagesLevel.ContainsKey(pagePaths[i]))
					{
						note.SetPageLevel(pageIds[i], pagesLevel[pagePaths[i]]);
					}
				}

				return true;
			}
			catch (Exception e)
			{
				Console.WriteLine(@"Error in ConvertEpubToOneNote for file {0}: {1}", inputFile, e.Message);
				return false;
			}
		}