コード例 #1
0
ファイル: PageManager.cs プロジェクト: Yodadude/Roadkill
        /// <summary>
        /// Adds the page to the database.
        /// </summary>
        /// <param name="summary">The summary details for the page.</param>
        /// <returns>A <see cref="PageSummary"/> for the newly added page.</returns>
        /// <exception cref="DatabaseException">An NHibernate (database) error occurred while saving.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public PageSummary AddPage(PageSummary summary)
        {
            try
            {
                string currentUser = RoadkillContext.Current.CurrentUsername;

                Page page = new Page();
                page.Title = summary.Title;
                page.Tags = summary.Tags.CleanTags();
                page.CreatedBy = AppendIpForAppHarbor(currentUser);
                page.CreatedOn = DateTime.Now;
                page.ModifiedOn = DateTime.Now;
                page.ModifiedBy = AppendIpForAppHarbor(currentUser);
                NHibernateRepository.Current.SaveOrUpdate<Page>(page);

                PageContent pageContent = new PageContent();
                pageContent.VersionNumber = 1;
                pageContent.Text = summary.Content;
                pageContent.EditedBy = AppendIpForAppHarbor(currentUser);
                pageContent.EditedOn = DateTime.Now;
                pageContent.Page = page;
                NHibernateRepository.Current.SaveOrUpdate<PageContent>(pageContent);

                // Update the lucene index
                try
                {
                    SearchManager.Current.Add(page.ToSummary());
                }
                catch (SearchException)
                {
                    // TODO: log
                }

                return page.ToSummary();
            }
            catch (HibernateException e)
            {
                throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", summary.Title);
            }
        }
コード例 #2
0
ファイル: PageManager.cs プロジェクト: Yodadude/Roadkill
        /// <summary>
        /// Updates the provided page.
        /// </summary>
        /// <param name="summary">The summary.</param>
        /// <exception cref="DatabaseException">An NHibernate (database) error occurred while updating.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public void UpdatePage(PageSummary summary)
        {
            try
            {
                string currentUser = RoadkillContext.Current.CurrentUsername;
                HistoryManager manager = new HistoryManager();

                Page page = Pages.FirstOrDefault(p => p.Id == summary.Id);
                page.Title = summary.Title;
                page.Tags = summary.Tags.CleanTags();
                page.ModifiedOn = DateTime.Now;
                page.ModifiedBy = AppendIpForAppHarbor(currentUser);

                // A second check to ensure a fake IsLocked POST doesn't work.
                if (RoadkillContext.Current.IsAdmin)
                    page.IsLocked = summary.IsLocked;

                NHibernateRepository.Current.SaveOrUpdate<Page>(page);

                PageContent pageContent = new PageContent();
                pageContent.VersionNumber = manager.MaxVersion(summary.Id) + 1;
                pageContent.Text = summary.Content;
                pageContent.EditedBy = AppendIpForAppHarbor(currentUser);
                pageContent.EditedOn = DateTime.Now;
                pageContent.Page = page;
                NHibernateRepository.Current.SaveOrUpdate<PageContent>(pageContent);

                // Update the lucene index
                SearchManager.Current.Update(page.ToSummary());
            }
            catch (HibernateException ex)
            {
                throw new DatabaseException(ex, "An error occurred updating the page with title '{0}' in the database", summary.Title);
            }
        }