/// <summary> /// Determines the next available module instance ID number in the /// page heiarchy of the identified parent PageInstance. This search /// is recursive. This method does not guarentee that the returned ID /// number is the next one that should be used, only the next lowest /// number under this page. /// </summary> /// <param name="parentPage">The PageInstance to begin at.</param> /// <returns>The next available module instance ID that can be used under this page.</returns> private int NextAvailableModuleInstanceID(PageInstance parentPage) { int nextID = -1; if (parentPage == null) { return(-1); } foreach (PageInstance page in parentPage.Pages) { int tempID = NextAvailableModuleInstanceID(page); if (tempID <= nextID) { nextID = tempID; } } foreach (ModuleInstance module in parentPage.Modules) { int tempID = module._ModuleInstanceID; if (tempID <= nextID) { nextID = tempID - 1; } } return(nextID); }
/// <summary> /// Recursively add all child pages into the list of pages. /// </summary> /// <param name="page">The page to add all child pages of into the list.</param> /// <param name="pages">The list of pages to add pages into.</param> private void OrderedPages(PageInstance page, ref List <PageInstance> pages) { foreach (PageInstance p in page.Pages) { pages.Add(p); OrderedPages(p, ref pages); } }
/// <summary> /// Finds the page that contains the specified ModuleInstance. If no page /// in this Package contains the ModuleInstance then null is returned. /// </summary> /// <param name="module">The ModuleInstance to search for.</param> /// <returns>The PageInstance that contains the ModuleInstance or null if not found.</returns> public PageInstance ParentOfModule(ModuleInstance module) { foreach (PageInstance parent in Pages) { PageInstance parentPage = ParentOfModule(parent, module); if (parentPage != null) { return(parentPage); } } return(null); }
/// <summary> /// Searches all PageInstances in the Package and determines which page /// contains the specified page as it's direct child. /// </summary> /// <param name="page">The child page to search for.</param> /// <returns>The parent PageInstance containing the child page or null if not found.</returns> public PageInstance ParentOfPage(PageInstance page) { foreach (PageInstance parent in Pages) { PageInstance parentPage = ParentOfPage(parent, page); if (parentPage != null) { return(parentPage); } } return(null); }
/// <summary> /// Determine if the module is on either the specified page or a child /// page and returns the matching page. This method is recursive. /// </summary> /// <param name="parentPage">The PageInstance to begin searching at.</param> /// <param name="module">The ModuleInstance to look for.</param> /// <returns>PageInstance containing module or null if not found.</returns> private PageInstance ParentOfModule(PageInstance parentPage, ModuleInstance module) { if (parentPage.Modules.Contains(module)) { return(parentPage); } foreach (PageInstance parent in parentPage.Pages) { PageInstance tmp = ParentOfModule(parent, module); if (tmp != null) { return(tmp); } } return(null); }
/// <summary> /// Searches the heiarchy of the specified PageInstance and determines /// which page, if any, contains the identified child page. This method is /// recursive. /// </summary> /// <param name="parentPage">The parent to begin searching at.</param> /// <param name="page">The child page to search for.</param> /// <returns>The PageInstance containing the child page or null if not found.</returns> private PageInstance ParentOfPage(PageInstance parentPage, PageInstance page) { if (parentPage.Pages.Contains(page)) { return(parentPage); } foreach (PageInstance parent in parentPage.Pages) { PageInstance tmp = ParentOfPage(parent, page); if (tmp != null) { return(tmp); } } return(null); }