Beispiel #1
0
        public ArticleResult GetArticleResult(ArticleId articleId, DateTime?revisionDate = null)
        {
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }

            ArticleRedirect articleRedirect = null;

            var article = this.CurrentSession.Include <Article>(x => x.ActiveRevisionId).Load(articleId.Id);

            if (article == null)
            {
                articleRedirect = this.GetArticleRedirect(articleId);
                if (articleRedirect != null)
                {
                    article = this.GetArticle(articleRedirect.RedirectToArticleSlug);
                }
            }

            string articleRevisionId = revisionDate.HasValue
                                           ? IdUtility.CreateArticleRevisionId(articleId, revisionDate.Value)
                                           : ((article != null) ? article.ActiveRevisionId : null);

            var articleRevision = this.GetArticleRevision(articleRevisionId);

            return(new ArticleResult(article, articleRevision, articleRedirect));
        }
Beispiel #2
0
 public ArticlePage(
     ArticleSlug articleSlug,
     Article article,
     ArticleRevision articleRevision = null,
     ArticleRedirect articleRedirect = null)
     : base(articleSlug, article, articleRevision, articleRedirect)
 {
     this.PopulateArticleRevision(articleRevision);
 }
Beispiel #3
0
        public static string CreateArticleRedirectId(ArticleRedirect articleRedirect)
        {
            if (articleRedirect == null)
            {
                throw new ArgumentNullException("articleRedirect");
            }

            return(CreateArticleRedirectId(articleRedirect.RedirectFromArticleSlug));
        }
Beispiel #4
0
        public ArticlePageBase(
            ArticleSlug articleSlug,
            Article article,
            ArticleRevision articleRevision = null,
            ArticleRedirect articleRedirect = null)
        {
            this.ArticleSlug = articleSlug;

            PopulateArticle(article);
            PopulateArticleRevision(articleRevision);
            PopulateArticleRedirect(articleRedirect);

            this.ArticleAccess = this.ArticleAccess ?? ArticleAccess.Default();
            this.ArticleSlug = this.ArticleSlug ?? ArticleSlug.Empty;
            this.ArticleTags = this.ArticleTags ?? Enumerable.Empty<string>();
            this.ArticleRevisionDate = this.ArticleRevisionDate ?? ArticleRevisionDate.Empty;
            this.RedirectedFromArticleSlug = this.RedirectedFromArticleSlug ?? ArticleSlug.Empty;
            this.ArticleRevisionOutboundArticleSlugs = this.ArticleRevisionOutboundArticleSlugs
                                                       ?? Enumerable.Empty<string>();
        }
        public static ArticleSlugStatus FromArticleRedirect(ArticleSlug articleSlug, ArticleRedirect articleRedirect)
        {
            if (articleSlug == null)
            {
                throw new ArgumentNullException("articleSlug");
            }
            if (articleRedirect == null)
            {
                throw new ArgumentNullException("articleRedirect");
            }

            return new ArticleSlugStatus
                       {
                           ArticleSlug = articleSlug,
                           ArticleRedirectToSlug = articleRedirect.RedirectToArticleSlug
                       };
        }
Beispiel #6
0
        public void MoveArticle(ArticleSlug fromArticleSlug, ArticleSlug toArticleSlug)
        {
            AssertArticleSlug(fromArticleSlug, "fromArticleSlug");
            AssertArticleSlug(toArticleSlug, "toArticleSlug");

            var targetArticle = this.TryGetArticle(toArticleSlug);
            if (targetArticle != null)
            {
                string errorMessage = string.Format("Article with ID '{0}' already exists.", toArticleSlug);
                throw new ArticleSlugConflictException(toArticleSlug, errorMessage);
            }

            var article = this.GetOrCreateArticle(fromArticleSlug);

            article.Slug = toArticleSlug.Slug;

            var articleRedirect = this.GetArticleRedirect(toArticleSlug);
            if (articleRedirect != null)
            {
                articleRedirect.TargetArticleSlug = fromArticleSlug.Slug;
                articleRedirect.RedirectToArticleSlug = toArticleSlug.Slug;
            }
            else
            {
                articleRedirect = new ArticleRedirect(fromArticleSlug, toArticleSlug);
                this.CurrentSession.Store(articleRedirect);
            }

            var articleRedirects = this.QueryArticleRedirects(fromArticleSlug);
            foreach (var redirect in articleRedirects)
            {
                redirect.RedirectToArticleSlug = toArticleSlug.Slug;
            }
        }
Beispiel #7
0
        public void AddArticleRedirect(
            ArticleSlug redirectToArticleSlug,
            ArticleSlug targetArticleSlug,
            string redirectToArticleHash = null)
        {
            AssertArticleSlug(redirectToArticleSlug, "redirectToArticleSlug");
            AssertArticleSlug(targetArticleSlug, "targetArticleSlug");

            var articleSlugStatus = this.GetArticleSlugStatus(targetArticleSlug);
            if (articleSlugStatus.HasArticleSlug || articleSlugStatus.HasArticleRedirectSlug)
            {
                string errorMessagePrefix = articleSlugStatus.HasArticleSlug ? "Article" : "Redirect";
                string errorMessage = string.Format("{0} '{1}' already exists.", errorMessagePrefix, targetArticleSlug);
                throw new ArticleSlugConflictException(targetArticleSlug, errorMessage);
            }

            var article = this.GetArticleAsserted(redirectToArticleSlug);

            var articleRedirect = new ArticleRedirect(targetArticleSlug, article.Slug, redirectToArticleHash);
            this.CurrentSession.Store(articleRedirect);
        }
Beispiel #8
0
        private bool GetRedirectExistsAsArticle(ArticleRedirect articleRedirect)
        {
            var article = this.GetArticle(articleRedirect.RedirectFromArticleSlug);

            return(article != null);
        }
Beispiel #9
0
        private void PopulateArticleRedirect(ArticleRedirect articleRedirect)
        {
            if (articleRedirect == null)
            {
                return;
            }

            this.ArticleSlug = articleRedirect.RedirectToArticleSlug;
            this.RedirectedFromArticleSlug = articleRedirect.TargetArticleSlug;
            this.RedirectToArticleHash = articleRedirect.RedirectToArticleHash;
        }