Bloom.Book.Book.DuplicatePage C# (CSharp) Method

DuplicatePage() public method

public DuplicatePage ( IPage page ) : void
page IPage
return void
        public void DuplicatePage(IPage page)
        {
            Guard.Against(Type != BookType.Publication, "Tried to edit a non-editable book.");

            var pages = GetPageElements();
            var pageDiv = FindPageDiv(page);
            var newpageDiv = (XmlElement) pageDiv.CloneNode(true);
            BookStarter.SetupIdAndLineage(pageDiv, newpageDiv);
            var body = pageDiv.ParentNode;
            int currentPageIndex = -1;

            // Have to compare Ids; can't use _pagesCache.IndexOf(page) -- (BL-467)
            foreach (IPage cachedPage in _pagesCache)
                if (cachedPage.Id.Equals(page.Id))
                {
                    currentPageIndex = _pagesCache.IndexOf(cachedPage);
                    break;
                }

            // This should never happen. But just in case, don't do something we don't want to do.
            if (currentPageIndex < 0)
                return;

            // If we copy audio markup, the new page will be linked to the SAME audio files,
            // and the pages might well continue to share markup even when text on one of them
            // is changed. If we WANT to copy the audio links, we need to do something like
            // assigning a new guid each time a new recording is made, or at least if we
            // find another sentence in the book sharing the same recording and with different
            // text.
            RemoveAudioMarkup(newpageDiv);

            body.InsertAfter(newpageDiv, pages[currentPageIndex]);

            ClearPagesCache();
            Save();
            if (_pageListChangedEvent != null)
                _pageListChangedEvent.Raise(null);

            InvokeContentsChanged(null);

            if (_pagesCache == null)
                BuildPageCache();
            _pageSelection.SelectPage(_pagesCache[currentPageIndex + 1]);
        }
Book