SetSubPage() public method

Make the page as subpage (if isSet true) or promote it (if isSet if false)
public SetSubPage ( string sectionId, string pageId, bool isSet = true ) : void
sectionId string
pageId string
isSet bool defaults to true, if true, increment pageLevel, else decrement pageLevel
return void
		/// <summary>
		/// Helper method to include the common code between the trainer and the student create notebook when converting 
		/// Power Point files that have sections
		/// </summary>
		/// <param name="pptOpenXml"></param>
		/// <param name="imgsPath"></param>
		/// <param name="note"></param>
		/// <param name="sectionId"></param>
		/// <param name="sectionNames"></param>
		/// <param name="slidesInSections"></param>
		/// <param name="isTrainer"></param>
		private void ConvertPowerPointWithSectionsToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, 
			string sectionId, List<string> sectionNames, List<List<int>> slidesInSections, bool isTrainer)
		{
			var pptSectionsPageIds = new List<string>();

			for (int i = 0; i < sectionNames.Count; i++)
			{
				string pptSectionPageId = note.CreatePage(sectionNames[i], sectionId);
				foreach (var slideNumber in slidesInSections[i])
				{
					string pageId;
					if (isTrainer)
					{
						pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId,
							true, StudentNotesTitle, true, TrainerNotesTitle);

					}
					else
					{
						pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId,
							true, StudentNotesTitle, false);
					}
					if (!pageId.Equals(String.Empty))
					{
						note.SetSubPage(sectionId, pageId);
						note.SetShowDate(pageId, false);
						note.SetShowTime(pageId, false);
					}
				}
				pptSectionsPageIds.Add(pptSectionPageId);
			}

			string tocPageId = note.CreateTableOfContentPage(sectionId);
			note.SetShowDate(tocPageId, false);
			note.SetShowTime(tocPageId, false);

			foreach (var pptSectionPageId in pptSectionsPageIds)
			{
				note.SetCollapsePage(pptSectionPageId);
				note.SetShowDate(pptSectionPageId, false);
				note.SetShowTime(pptSectionPageId, false);
			}
		}
		/// <summary>
		/// Converts PowerPoint presentan to OneNote while converting the sections in power point to main pages, and slides to sub pages
		/// </summary>
		/// <param name="pptOpenXml"></param>
		/// <param name="imgsPath"></param>
		/// <param name="note"></param>
		/// <param name="sectionName"></param>
		protected virtual void ConvertPowerPointToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note,
			string sectionName)
		{
			string notebookId = note.CreateNotebook(GetSupportedInputFormat());
			string sectionId = note.CreateSection(sectionName, notebookId);

			if (pptOpenXml.HasSections())
			{
				List<string> sectionNames = pptOpenXml.GetSectionNames();
				List<List<int>> slidesInSections = pptOpenXml.GetSlidesInSections();
				var pptSectionsPageIds = new List<string>();
				for (int i = 0; i < sectionNames.Count; i++)
				{
					string pptSectionPageId = note.CreatePage(sectionNames[i], sectionId);
					foreach (var slideNumber in slidesInSections[i])
					{
						string pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId);
						if (!String.IsNullOrEmpty(pageId))
						{
							note.SetSubPage(sectionId, pageId);
						}
					}
					pptSectionsPageIds.Add(pptSectionPageId);
				}

				note.CreateTableOfContentPage(sectionId);

				foreach (var pptSectionPageId in pptSectionsPageIds)
				{
					note.SetCollapsePage(pptSectionPageId);
				}
			}
			else
			{
				for (var i = 1; i <= pptOpenXml.NumberOfSlides(); i++)
				{
					InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId);
				}
			}
		}
		/// <summary>
		/// Converts Html file into OneNote Section of Pages
		/// </summary>
		/// <param name="inputFile"></param>
		/// <param name="originalPicFolder"></param>
		/// <param name="auxInputFolder"></param>
		/// <param name="onGenerator"></param>
		/// <param name="sectionId"></param>
		/// <returns></returns>
		protected override bool ConvertHtmlToOneNote(string inputFile, string originalPicFolder, string auxInputFolder, OneNoteGenerator onGenerator, string sectionId)
		{
			var retVal = false;

			try
			{
				string htmlContent;
				using (var sr = new StreamReader(inputFile, Encoding.Default))
				{
					htmlContent = sr.ReadToEnd();
				}

				var doc = new HtmlDocument();
				doc.LoadHtml(htmlContent);

				var content = doc.DocumentNode;

				//outer html contains format information
				var htmlBox = doc.DocumentNode;
				//list of onenote page Id 
				var pageIdList = new List<string>();
				//list of onenote page/subpage name
				var pageNameList = new List<string>();
				//separate the whole doc into pages
				var pages = SeparatePages(content) as List<List<HtmlNode>>;
				//get chapter names from table contents
				var chapterNameList = new List<string>();

				//may produce problem by calling first()
				//maybe empty page with pageNameList[0] = null, fix later
				var tableContent = pages.FirstOrDefault();
				if (tableContent != null)
				{
					foreach (var node in tableContent)
					{
						chapterNameList.Add(node.InnerText.Replace("\r\n", " ").Trim());
					}
				}

				//store errors occurred during conversion 
				var errorList = new List<Dictionary<InfoType, string>>();

				//print pages to onenote
				foreach (var page in pages)
				{
					var pageTitle = GetPageTitle(page);
					var pageId = onGenerator.CreatePage(pageTitle, sectionId);

					var errorInfo = new Dictionary<InfoType, string>();
					var pageContent = GeneratePageContent(htmlBox, page, originalPicFolder, auxInputFolder, errorInfo);
					onGenerator.AddPageContentAsHtmlBlock(pageId, pageContent);

					pageIdList.Add(pageId);
					pageNameList.Add(pageTitle);

					if (errorInfo.Count > 0)
					{
						errorInfo.Add(InfoType.Id, pageId);
						errorInfo.Add(InfoType.Title, pageTitle);
						errorList.Add(errorInfo);
					}
				}
				if (errorList.Count > 0)
				{
					CreateErrorPage(onGenerator, sectionId, errorList);
				}
				//set some pages as subpages according to observed rules
				var lastSeenChapterName = String.Empty;
				for (int i = 0; i < pageIdList.Count; i++)
				{
					var pageId = pageIdList[i];
					var name = pageNameList[i];
					//check if the page name is a chapter name (a substring of table content items)
					var isChapterName = chapterNameList.Any(x => x.Contains(name));

					bool isSubpage = !isChapterName && name != lastSeenChapterName;

					//if it is a new chapter name, set it as a page
					//if it is not a chapter name, but it is the first of consecutive same name pages, set it as a page
					if (isChapterName == false 
						&& i > 0 && name != pageNameList[i - 1] 
						&& i < pageNameList.Count && name == pageNameList[i + 1])
					{
						isSubpage = false;
					}

					if (isSubpage)
					{
						onGenerator.SetSubPage(sectionId, pageId);
					}
					if (isChapterName)
					{
						lastSeenChapterName = name;
					}
				}
				retVal = true;
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				retVal = false;
			}

			return retVal;
		}
		/// <summary>
		/// Converts Html file into OneNote Section of Pages
		/// </summary>
		/// <param name="inputFile"></param>
		/// <param name="originalPicFolder"></param>
		/// <param name="auxPicFolder"></param>
		/// <param name="onGenerator"></param>
		/// <param name="sectionId"></param>
		/// <returns></returns>
		protected virtual bool ConvertHtmlToOneNote(string inputFile, string originalPicFolder, string auxPicFolder, OneNoteGenerator onGenerator, string sectionId)
		{
			var retVal = false;
			var htmlContent = string.Empty;

			try
			{
				using (var sr = new StreamReader(inputFile, Encoding.Default))
				{
					htmlContent = sr.ReadToEnd();
				}

				var htmlDoc = new HtmlDocument();
				htmlDoc.LoadHtml(htmlContent);

				//Preserve the HTML surrounding tags
				var content = htmlDoc.DocumentNode;

				var previousPageTitle = string.Empty;

				//store error info
				var errorList = new List<Dictionary<InfoType, string>>();

				foreach (var page in SeparatePages(content))
				{
					if (page != null)
					{
						//Get page title
						var pageTitle = GetPageTitle(page);

						//Create the page
						var pageId = onGenerator.CreatePage(pageTitle, sectionId);

						//error info
						var errorInfo = new Dictionary<InfoType, string>();

						//Add the content of the page
						var pageContent = GeneratePageContent(content, page, originalPicFolder, auxPicFolder, errorInfo);
						onGenerator.AddPageContentAsHtmlBlock(pageId, pageContent);

						//Attempt to do subpage
						if (!pageTitle.Equals(DefaultPageTitle, StringComparison.CurrentCultureIgnoreCase) &&
							pageTitle.Equals(previousPageTitle, StringComparison.CurrentCultureIgnoreCase))
						{
							onGenerator.SetSubPage(sectionId, pageId);
						}

						previousPageTitle = pageTitle;

						if (errorInfo.Count > 0)
						{
							errorInfo.Add(InfoType.Id, pageId);
							errorInfo.Add(InfoType.Title, pageTitle);
							errorList.Add(errorInfo);
						}
					}
				}
				if (errorList.Count > 0)
				{
					CreateErrorPage(onGenerator, sectionId, errorList);
				}

				retVal = true;
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				retVal = false;
			}

			return retVal;
		}