public bool PublishArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate) { if (articleId == null) { throw new ArgumentNullException("articleId"); } if (revisionDate == null) { throw new ArgumentNullException("revisionDate"); } var article = this.GetArticle(articleId); if (article == null) { return(false); } var articleRevision = this.GetArticleRevision(articleId, revisionDate); if (articleRevision == null) { return(false); } articleRevision.LastPublishedAt = DateTime.UtcNow; article.ActiveRevisionId = articleRevision.Id; this.CurrentSession.SaveChanges(); return(true); }
public bool DeleteArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate) { var articleRevision = this.GetArticleRevision(articleId, revisionDate); if (articleRevision == null) { return(false); } this.CurrentSession.Delete(articleRevision); var article = this.GetArticle(articleId); if (article.ActiveRevisionId == articleRevision.Id) { var latestRevision = this.CurrentSession.Query <ArticleRevision, ArticleRevisionsIndex>() .OrderByDescending(x => x.CreatedAt) .FirstOrDefault(); article.ActiveRevisionId = (latestRevision != null) ? latestRevision.Id : null; } this.CurrentSession.SaveChanges(); return(true); }
public bool DeleteArticle(ArticleId articleId) { var article = this.GetArticle(articleId); if (article == null) { return(false); } this.CurrentSession.Delete(article); var articleRevisions = this.CurrentSession.Query <ArticleRevision, ArticleRevisionsIndex>() .Where(x => x.ArticleId == article.Id); var articleRedirects = this.CurrentSession.Query <ArticleRedirect, ArticleRedirectsIndex>() .Where(x => x.RedirectToArticleSlug == article.Id); articleRevisions.ToList().ForEach(x => this.CurrentSession.Delete(x)); articleRedirects.ToList().ForEach(x => this.CurrentSession.Delete(x)); this.CurrentSession.SaveChanges(); return(true); }
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)); }
public ArticleRevision GetArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate) { string id = (articleId != null) ? articleId.Id : null; string articleRevisionId = IdUtility.CreateArticleRevisionId(id, revisionDate); return(this.GetArticleRevision(articleRevisionId)); }
public static string CreateArticleId(ArticleId articleId) { if (articleId == null) { throw new ArgumentNullException("articleId"); } return(String.Format("{0}{1}", ArticleIdPrefix, articleId.Slug)); }
public static string CreateArticleRedirectId(ArticleId originalArticleId) { if (originalArticleId == null) { throw new ArgumentNullException("originalArticleId"); } return(String.Format("{0}{1}", ArticleRedirectIdPrefix, originalArticleId.Slug)); }
public static string CreateArticleId(Article article) { if (article == null) { throw new ArgumentNullException("article"); } var articleId = new ArticleId(article.Slug); return(CreateArticleId(articleId)); }
public Article(ArticleId articleId, IEnumerable <string> tags = null, ArticleAccess articleAccess = null) { if (articleId == null) { throw new ArgumentNullException("articleId"); } this.Slug = articleId.Slug; this.Tags = tags ?? Enumerable.Empty <string>(); this.ArticleAccess = articleAccess ?? ArticleAccess.Default(); }
public IReadOnlyCollection <string> SaveArticleTags(ArticleId articleId, IEnumerable <string> tags) { var normalizedTags = GetNormalizedCollection(tags); var article = this.GetArticle(articleId) ?? new Article(articleId); article.Tags = normalizedTags; this.CurrentSession.SaveChanges(); return(normalizedTags); }
public ArticleRevision GetArticleRevisionLatest(ArticleId articleId) { if (articleId == null || !articleId.HasValue) { return(null); } var query = this.GetArticleRevisionsQuery <ArticleRevisionsIndex>(articleId); var result = query.OrderByDescending(x => x.CreatedAt); return(result.As <ArticleRevision>().FirstOrDefault()); }
public static string CreateArticleRevisionId(ArticleId articleId, ArticleRevisionDate articleRevisionDate) { if (articleId == null) { throw new ArgumentNullException("articleId"); } if (articleRevisionDate == null) { throw new ArgumentNullException("articleRevisionDate"); } return(CreateArticleRevisionId(articleId, articleRevisionDate.DateTime)); }
private IReadOnlyCollection <ArticleRedirect> SaveArticleRedirectsInternal( ArticleId redirectToArticleId, IEnumerable <ArticleRedirect> articleRedirects) { if (articleRedirects == null) { throw new ArgumentNullException("articleRedirects"); } var redirects = articleRedirects.ToList(); if (!redirects.Any()) { return(redirects); } var articleRedirectIds = redirects.Select(IdUtility.CreateArticleRedirectId).ToList(); var storedRedirects = this.CurrentSession.Load <ArticleRedirect>(articleRedirectIds); var ensuredRedirects = new List <ArticleRedirect>(); for (int i = 0; i < storedRedirects.Length; i++) { var redirect = storedRedirects[i] ?? redirects[i]; bool redirectExistsAsArticle = GetRedirectExistsAsArticle(redirect); if (redirectExistsAsArticle) { continue; } this.CurrentSession.Store(redirect); ensuredRedirects.Add(redirect); } var ensuredOriginalArticleSlugs = ensuredRedirects.Select(x => x.RedirectFromArticleSlug).ToList(); var deletedRedirects = this.CurrentSession.Query <ArticleRedirect, ArticleRedirectsIndex>() .Where( x => x.RedirectToArticleSlug == redirectToArticleId.Slug && !x.RedirectFromArticleSlug.In(ensuredOriginalArticleSlugs)) .ToList(); deletedRedirects.ForEach(x => this.CurrentSession.Delete(x)); return(ensuredRedirects.OrderBy(x => x.RedirectFromArticleSlug).ToList()); }
public IReadOnlyCollection <ArticleId> GetArticleRedirectsList(ArticleId redirectToArticleId) { if (redirectToArticleId == null || !redirectToArticleId.HasValue) { return(Enumerable.Empty <ArticleId>().ToList()); } var result = (from redirect in this.CurrentSession.Query <ArticleRedirect, ArticleRedirectsIndex>() where redirect.RedirectToArticleSlug == redirectToArticleId.Slug orderby redirect.RedirectFromArticleSlug select redirect).As <ArticleRedirect>().ToList(); return(result.Select(x => new ArticleId(x.RedirectFromArticleSlug)).ToList()); }
private IRavenQueryable <ArticleRevisionsIndex.Result> GetArticleRevisionsQuery <TIndexCreator>( ArticleId articleId = null) where TIndexCreator : AbstractIndexCreationTask, new() { var query = from revision in this.CurrentSession.Query <ArticleRevisionsIndex.Result, TIndexCreator>() where (revision.LastPublishedAt != null || revision.CreatedByUserName == this.principalId) orderby revision.CreatedAt descending select revision; if (articleId != null && articleId.HasValue) { query = query.Where(x => x.ArticleId == articleId.Id); } return(query); }
public IReadOnlyCollection <ArticleRevisionItem> GetArticleRevisionsList(ArticleId articleId) { if (articleId == null || !articleId.HasValue) { return(Enumerable.Empty <ArticleRevisionItem>().ToList()); } var query = this.GetArticleRevisionsQuery <ArticleRevisionsIndex>(articleId); var result = query.Customize(x => x.WaitForNonStaleResults(TimeSpan.FromSeconds(15))) .AsProjection <ArticleRevisionItem>(); return(result.ToList()); }
public IReadOnlyCollection <ArticleRedirect> SaveArticleRedirects( ArticleId redirectToArticleId, IEnumerable <string> articleRedirects) { if (redirectToArticleId == null) { throw new ArgumentNullException("redirectToArticleId"); } var normalizedRedirects = GetNormalizedCollection(articleRedirects); var redirects = normalizedRedirects.Select(x => new ArticleRedirect(x, redirectToArticleId)); return(this.SaveArticleRedirects(redirectToArticleId, redirects)); }
public static string CreateArticleRevisionId(ArticleId articleId, DateTime articleRevisionDate) { if (articleId == null) { throw new ArgumentNullException("articleId"); } if (articleRevisionDate == DateTime.MinValue) { throw new ArgumentOutOfRangeException("articleRevisionDate"); } string createdAtFormatted = articleRevisionDate.ToString(ArticleRevisionDate.IdDateTimeFormat); return(String.Format("{0}/{1}", articleId.Id, createdAtFormatted)); }
public ArticleId GetArticleExists(ArticleId articleId) { var article = this.GetArticle(articleId); if (article != null) { return(article.Id); } var redirect = this.GetArticleRedirect(articleId); if (redirect != null) { return(redirect.RedirectToArticleSlug); } return(null); }
public ArticleResult SaveArticleRevision( ArticleId articleId, ArticleRevision articleRevision, bool publishRevision = false) { if (articleId == null) { throw new ArgumentNullException("articleId"); } if (articleRevision == null) { throw new ArgumentNullException("articleRevision"); } var article = this.GetArticle(articleId) ?? new Article(articleId); return(this.SaveArticle(article, articleRevision, publishRevision)); }
public IReadOnlyCollection <ArticleRedirect> SaveArticleRedirects( ArticleId redirectToArticleId, IEnumerable <ArticleRedirect> articleRedirects) { if (redirectToArticleId == null) { throw new ArgumentNullException("redirectToArticleId"); } if (articleRedirects == null) { throw new ArgumentNullException("articleRedirects"); } var savedArticleRedirects = this.SaveArticleRedirectsInternal(redirectToArticleId, articleRedirects); this.CurrentSession.SaveChanges(); return(savedArticleRedirects); }
public bool RevertArticleToDraft(ArticleId articleId) { if (articleId == null) { throw new ArgumentNullException("articleId"); } var article = this.GetArticle(articleId); if (article == null) { return(false); } article.ActiveRevisionId = null; this.CurrentSession.SaveChanges(); return(true); }
public ArticleRevision( ArticleId articleId, IPrincipal principal, string markdownContent, string editSummary = null) { if (articleId == null) { throw new ArgumentNullException("articleId"); } if (principal == null) { throw new ArgumentNullException("principal"); } this.ArticleId = articleId.Id; this.CreatedByUserName = principal.Identity.Name; this.EditSummary = editSummary; this.MarkdownContent = markdownContent; this.TextContent = MarkdownService.MakeTextFlat(this.MarkdownContent); this.CreatedAt = DateTime.UtcNow; }
public static bool GetIsEnsured(ArticleId articleId) { string ensuredSlug = articleId.Slug; return(articleId.OriginalSlug == ensuredSlug); }
public ArticleRedirect GetArticleRedirect(ArticleId originalArticleId) { string articleRedirectId = IdUtility.CreateArticleRedirectId(originalArticleId); return(this.CurrentSession.Load <ArticleRedirect>(articleRedirectId)); }
public ArticleResult GetArticleResult(string articleId, DateTime?revisionDate = null) { var articleIdValue = new ArticleId(articleId); return(this.GetArticleResult(articleIdValue, revisionDate)); }
public Article GetArticle(ArticleId articleId) { return((articleId != null && articleId.HasValue) ? this.CurrentSession.Load <Article>(articleId.Id) : null); }
public ArticleRedirect(ArticleId redirectFromArticleId, ArticleId redirectToArticleId) { this.RedirectFromArticleSlug = redirectFromArticleId.Slug; this.RedirectToArticleSlug = redirectToArticleId.Slug; }