コード例 #1
0
        /// <summary>
        /// Reverts to a particular version, creating a new version in the process.
        /// </summary>
        /// <param name="versionId">The version ID to revert to.</param>
        /// <param name="context">The current logged in user's context.</param>
        /// <exception cref="HistoryException">An databaseerror occurred while reverting to the version.</exception>
        public void RevertTo(Guid versionId, IUserContext context)
        {
            try
            {
                string currentUser = context.CurrentUsername;

                PageContent versionContent = Repository.GetPageContentById(versionId);
                Page        page           = Repository.GetPageById(versionContent.Page.Id);

                int      versionNumber        = MaxVersion(page.Id) + 1;
                string   text                 = versionContent.Text;
                string   editedBy             = currentUser;
                DateTime editedOn             = DateTime.UtcNow;
                DateTime projectStart         = versionContent.ProjectStart;
                DateTime projectEnd           = versionContent.ProjectEnd;
                bool     projectEstimatedTime = versionContent.ProjectEstimatedTime;
                string   projectLanguage      = versionContent.ProjectLanguage;
                string   projectStatus        = versionContent.ProjectStatus;
                int      orgID                = versionContent.orgID;

                Repository.AddNewPageContentVersion(page, text, editedBy, editedOn, versionNumber, projectStart, projectEnd, projectEstimatedTime, projectStatus, projectLanguage, orgID);

                // Clear the cache
                _pageViewModelCache.Remove(page.Id);
            }
            catch (ArgumentNullException ex)
            {
                throw new HistoryException(ex, "An ArgumentNullException occurred when reverting to version ID {0}", versionId);
            }
            catch (DatabaseException ex)
            {
                throw new HistoryException(ex, "A DatabaseException occurred when reverting to version ID {0}", versionId);
            }
        }
コード例 #2
0
ファイル: PageHistoryService.cs プロジェクト: wei772/roadkill
        /// <summary>
        /// Reverts to a particular version, creating a new version in the process.
        /// </summary>
        /// <param name="versionId">The version ID to revert to.</param>
        /// <param name="context">The current logged in user's context.</param>
        /// <exception cref="HistoryException">An databaseerror occurred while reverting to the version.</exception>
        public void RevertTo(Guid versionId, IUserContext context)
        {
            try
            {
                string currentUser = context.CurrentUsername;

                PageContent versionContent = PageRepository.GetPageContentById(versionId);
                Page        page           = PageRepository.GetPageById(versionContent.Page.Id);

                int      versionNumber = MaxVersion(page.Id) + 1;
                string   text          = versionContent.Text;
                string   editedBy      = currentUser;
                DateTime editedOn      = DateTime.UtcNow;
                PageRepository.AddNewPageContentVersion(page, text, editedBy, editedOn, versionNumber);

                // Clear the cache
                _pageViewModelCache.Remove(page.Id);
            }
            catch (ArgumentNullException ex)
            {
                throw new HistoryException(ex, "An ArgumentNullException occurred when reverting to version ID {0}", versionId);
            }
            catch (DatabaseException ex)
            {
                throw new HistoryException(ex, "A DatabaseException occurred when reverting to version ID {0}", versionId);
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates the provided page.
        /// </summary>
        /// <param name="model">The summary.</param>
        /// <exception cref="DatabaseException">An databaseerror occurred while updating.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public void UpdatePage(PageViewModel model)
        {
            try
            {
                string currentUser = _context.CurrentUsername;

                Page page = Repository.GetPageById(model.Id);
                page.Title                = model.Title;
                page.Tags                 = model.CommaDelimitedTags();
                page.ModifiedOn           = DateTime.UtcNow;
                page.ModifiedBy           = AppendIpForDemoSite(currentUser);
                page.ProjectStart         = model.ProjectStart;
                page.ProjectEnd           = model.ProjectEnd;
                page.ProjectEstimatedTime = model.ProjectEstimatedTime;
                page.ProjectLanguage      = model.ProjectLanguage;
                page.ProjectStatus        = model.ProjectStatus;
                page.OrgID                = model.OrgID;

                // A second check to ensure a fake IsLocked POST doesn't work.
                if (_context.IsAdmin)
                {
                    page.IsLocked = model.IsLocked;
                }

                Repository.SaveOrUpdatePage(page);

                //
                // Update the cache - updating a page is expensive for the cache right now
                // this could be improved by updating the item in the listcache instead of invalidating it
                //
                _pageViewModelCache.Remove(model.Id, 0);

                if (model.Tags.Contains("homepage"))
                {
                    _pageViewModelCache.RemoveHomePage();
                }

                _listCache.RemoveAll();

                int         newVersion  = _historyService.MaxVersion(model.Id) + 1;
                PageContent pageContent = Repository.AddNewPageContentVersion(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow, newVersion, model.ProjectStart, model.ProjectEnd, model.ProjectEstimatedTime, model.ProjectStatus, model.ProjectLanguage, model.OrgID);

                // Update all links to this page (if it has had its title renamed). Case changes don't need any updates.
                if (model.PreviousTitle != null && model.PreviousTitle.ToLower() != model.Title.ToLower())
                {
                    UpdateLinksToPage(model.PreviousTitle, model.Title);
                }

                // Update the lucene index
                PageViewModel updatedModel = new PageViewModel(Repository.GetLatestPageContent(page.Id), _markupConverter);
                _searchService.Update(updatedModel);
            }
            catch (DatabaseException ex)
            {
                throw new DatabaseException(ex, "An error occurred updating the page with title '{0}' in the database", model.Title);
            }
        }