public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = name, Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var entry2 = new Entry { Name = name, Author = "A1" }; var revision2 = entry2.Revise(); revision2.Body = "Goodbye"; repo.Add(entry2); }); Database.WithRepository( repo => { var entry = repo.FindFirst(new EntryByNameAndRevisionQuery(name, 1)); Assert.AreEqual("A1", entry.Author); }); }
public static Func<QueryOverProjectionBuilder<Revision>, QueryOverProjectionBuilder<Revision>> FromRevision(Entry entryAlias) { var entryRevision = new EntryRevision(); return list => { list .Select(e => e.Id).WithAlias(() => entryRevision.Id) .Select(() => entryAlias.Author).WithAlias(() => entryRevision.Author) .Select(e => e.Author).WithAlias(() => entryRevision.RevisionAuthor) .Select(e => e.Body).WithAlias(() => entryRevision.Body) .Select(() => entryAlias.CommentCount).WithAlias(() => entryRevision.CommentCount) .Select(e => e.Format).WithAlias(() => entryRevision.Format) .Select(() => entryAlias.HideChrome).WithAlias(() => entryRevision.HideChrome) .Select(() => entryAlias.IsDiscussionEnabled).WithAlias(() => entryRevision.IsDiscussionEnabled) .Select(() => entryAlias.LatestRevision.RevisionNumber).WithAlias(() => entryRevision.LatestRevisionNumber) .Select(e => e.RevisionNumber).WithAlias(() => entryRevision.RevisionNumber) .Select(() => entryAlias.MetaDescription).WithAlias(() => entryRevision.MetaDescription) .Select(() => entryAlias.MetaTitle).WithAlias(() => entryRevision.MetaTitle) .Select(() => entryAlias.Name).WithAlias(() => entryRevision.Name) .Select(() => entryAlias.PageTemplate).WithAlias(() => entryRevision.PageTemplate) .Select(() => entryAlias.Published).WithAlias(() => entryRevision.Published) .Select(() => entryAlias.LatestRevision.Revised).WithAlias(() => entryRevision.Revised) .Select(() => entryAlias.Status).WithAlias(() => entryRevision.Status) .Select(() => entryAlias.Summary).WithAlias(() => entryRevision.Summary) .Select(() => entryAlias.Title).WithAlias(() => entryRevision.Title); return list; }; }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = name, Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var comment1 = entry1.Comment(); comment1.AuthorName = "A2"; comment1.AuthorEmail = "*****@*****.**"; comment1.AuthorUrl = "somesite.com"; comment1.Body = "some comment"; repo.Add(comment1); }); Database.WithRepository( repo => { var result = repo.Find(new GetFullEntriesQuery(true), 0, 1); Assert.AreEqual(1, result.Count); Assert.AreEqual(1, result.Single().Comments.Count); }); }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry = new Entry { Name = name, Author = "A1", Status = EntryStatus.PublicBlog }; var revision2 = entry.Revise(); revision2.Body = "Goodbye"; var tag = new Tag { Name = "Awesome" }; tag.Entries.Add(entry); entry.Tags.Add(tag); repo.Add(entry); repo.Add(tag); var entry1 = new Entry { Name = name, Author = "A1", Status = EntryStatus.PublicBlog }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); }); Database.WithRepository( repo => { var result = repo.Find(new GetEntriesQuery(EntryStatus.PublicBlog), 0, 2); Assert.AreEqual(2, result.Count); Assert.AreEqual(result.TotalResults, 2); Assert.AreEqual(1, result[0].TagsCommaSeparated.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Length); }); }
public void LoadsSpecifiedRevisionAsLatest() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry = new Entry { Name = name, Author = "A1" }; var revision1 = entry.Revise(); revision1.Body = "Hello"; var revision2 = entry.Revise(); revision2.Body = "Goodbye"; repo.Add(entry); }); Database.WithRepository( repo => { var entry = repo.FindFirst(new EntryByNameAndRevisionQuery(name, 1)); Assert.AreEqual("Hello", entry.Body); entry = repo.FindFirst(new EntryByNameAndRevisionQuery(name, 2)); Assert.AreEqual("Goodbye", entry.Body); }); }
public override void TestQuery() { var name = Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = "bar-" + name, Title = name.ToString(), Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var entry2 = new Entry { Name = "foo-" + name, Title = name.ToString(), Author = "A1" }; var revision2 = entry2.Revise(); revision2.Body = "Goodbye"; repo.Add(entry2); }); Database.WithRepository( repo => { var result = repo.Find(new SimpleSearchEntriesQuery(name.ToString()), 0, 1); Assert.AreEqual(1, result.Count); Assert.GreaterOrEqual(2, result.TotalResults); }); }
public void ReturnsEntryWithWithRequestedTagOnly() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry = new Entry { Name = name, Author = "A1" }; var revision2 = entry.Revise(); revision2.Body = "Goodbye"; var tag = new Tag{ Name = "Awesome"}; tag.Entries.Add(entry); entry.Tags.Add(tag); repo.Add(entry); repo.Add(tag); var entry1 = new Entry { Name = name, Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; var tag2 = new Tag { Name = "NotAwesome" }; tag2.Entries.Add(entry1); entry1.Tags.Add(tag2); repo.Add(entry1); repo.Add(tag2); }); Database.WithRepository( repo => { var result = repo.Find(new GetEntriesByTagQuery("Awesome"), 0, 2); Assert.AreEqual(1, result.Count); Assert.AreEqual(result.TotalResults, 1); Assert.AreEqual(1, result[0].TagsCommaSeparated.Split(new[]{","}, StringSplitOptions.RemoveEmptyEntries).Length); }); }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = name, Author = "A1", Status = EntryStatus.PublicBlog }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var entry2 = new Entry { Name = name, Author = "A1", Status = EntryStatus.Private }; var revision2 = entry2.Revise(); revision2.Body = "Goodbye"; repo.Add(entry2); var entry3 = new Entry { Name = name, Author = "A1", Status = EntryStatus.PublicPage }; var revision3 = entry3.Revise(); revision3.Body = "Goodbye"; repo.Add(entry3); }); Database.WithRepository( repo => { var result = repo.Find(new GetEntriesQuery(), 0, 1); Assert.AreEqual(1, result.Count); Assert.GreaterOrEqual(result.TotalResults, 2); }); }
private static string BuildMessageBody(Entry entry, Comment comment) { var builder = new StringBuilder(); builder.AppendFormat("<p>A comment was posted to the entry: {0}</p>", entry.Title).AppendLine(); builder.AppendFormat("<p>Author: {0}</p>", Encode(comment.AuthorName)).AppendLine(); builder.AppendFormat("<p>Email: {0}</p>", Encode(comment.AuthorEmail)).AppendLine(); builder.AppendFormat("<p>Blog: {0}</p>", Encode(comment.AuthorUrl)).AppendLine(); builder.AppendFormat("<p>Comment:</p><pre>{0}</pre>", Encode(comment.Body)).AppendLine(); return builder.ToString(); }
public virtual void Remove(Entry entry) { if (entry == null) throw new ArgumentNullException("entry"); var existing = Entries.FirstOrDefault(x => x == entry); if (existing != null) { Entries.Remove(existing); existing.Tags.Remove(this); } }
public virtual void Add(Entry entry) { if (entry == null) throw new ArgumentNullException("entry"); var existing = Entries.FirstOrDefault(x => x == entry); if (existing != null) return; Entries.Add(entry); entry.Tags.Add(this); }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Entry entry = null; Database.WithRepository( repo => { entry = new Entry {Name = name, Author = "A1", Status = EntryStatus.PublicBlog}; var revision = entry.Revise(); revision.Body = "Hello"; repo.Add(entry); var comment = entry.Comment(); comment.AuthorName = "Test"; comment.AuthorEmail = "*****@*****.**"; comment.AuthorUrl = ""; comment.Body = "Comment"; comment.Posted = DateTime.Now; comment.Entry = entry; comment.IsSpam = false; repo.Add(comment); var comment2 = entry.Comment(); comment2.AuthorName = "Test"; comment2.AuthorEmail = "*****@*****.**"; comment2.AuthorUrl = ""; comment2.Body = "Comment"; comment2.Posted = DateTime.Now; comment2.Entry = entry; comment2.IsSpam = false; repo.Add(comment2); var comment3 = entry.Comment(); comment3.AuthorName = "Test"; comment3.AuthorEmail = "*****@*****.**"; comment3.AuthorUrl = ""; comment3.Body = "Comment"; comment3.Posted = DateTime.Now; comment3.Entry = entry; comment3.IsSpam = true; repo.Add(comment3); }); Database.WithSession( s => { var repo = new AdminRepository(s); repo.UpdateCommentCountFor(entry.Id); }); Database.WithRepository( repo => Assert.AreEqual(2, repo.Get<Entry>(entry.Id).CommentCount)); }
public void ReturnsEntry() { var name = Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = "bar-" + name, Title = name.ToString(), Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var entry2 = new Entry { Name = "foo-" + name, Title = name.ToString(), Author = "A1" }; var revision2 = entry2.Revise(); revision2.Body = "Goodbye"; repo.Add(entry2); }); //todo: TableFullTextChangeTrackingOn doesn't check if full text is enabled for that table, need to find IsFullTextIndexEnabled property var executeScalar = Database.AdHoc.ExecuteScalar( "SELECT FullTextServiceProperty('IsFullTextInstalled') + OBJECTPROPERTY(OBJECT_ID('$schema$.Entry'), 'TableFullTextChangeTrackingOn')"); var isFullTextEnabled = (int)executeScalar; //Idealy the test will run when full text is installed and enabled, if not, still test like based search if (isFullTextEnabled == 2) { //Database.AdHoc.ExecuteNonQuery("ALTER FULLTEXT INDEX ON $schema$.[Entry] START UPDATE POPULATION"); //Database.WithRepository( //repo => //{ // var result = repo.Find(new SearchEntriesQuery(name.ToString()), 0, 1); // Assert.AreEqual(1, result.Count); // Assert.GreaterOrEqual(2, result.TotalResults); //}); Database.AdHoc.ExecuteNonQuery("ALTER FULLTEXT INDEX ON $schema$.[Entry] SET CHANGE_TRACKING = OFF"); Database.AdHoc.ExecuteNonQuery("EXEC sys.sp_fulltext_table @tabname=N'$schema$.[Entry]', @action=N'deactivate'"); } Database.WithRepository( repo => { var result = repo.Find(new SearchEntriesQuery(name.ToString()), 0, 1); Assert.AreEqual(1, result.Count); Assert.GreaterOrEqual(2, result.TotalResults); }); if (isFullTextEnabled == 2) { //Database.AdHoc.ExecuteNonQuery("EXEC sys.sp_fulltext_table @tabname=N'$schema$.[Entry]', @action=N'activate'"); } }
public void ReturnsComments() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry = new Entry { Name = name, Author = "A1" }; var revision = entry.Revise(); revision.Body = "Hello"; repo.Add(entry); var comment = new Comment { AuthorName = "Test", AuthorEmail = "*****@*****.**", AuthorUrl = "", Body = "Comment", Posted = DateTime.Now, Entry = entry, IsSpam = false }; var comment2 = new Comment { AuthorName = "Test2", AuthorEmail = "*****@*****.**", AuthorUrl = "", Body = "Comment2", Posted = DateTime.Now, Entry = entry, IsSpam = false }; entry.Comments.Add(comment); entry.Comments.Add(comment2); repo.Add(comment); repo.Add(comment2); }); Database.WithRepository( repo => { var result = repo.Find(new GetCommentsQuery(), 0, 1); Assert.AreEqual(1, result.Count); Assert.GreaterOrEqual(result.TotalResults, 2); }); }
public void MatchesEntryByName() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = name, Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); }); Database.WithRepository( repo => { var entry = repo.FindFirst(new EntryByNameQuery(name)); Assert.AreEqual("A1", entry.Author); }); }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry = new Entry { Name = name, Author = "A1" }; var revision1 = entry.Revise(); revision1.Body = "Hello"; repo.Add(entry); var comment = new Comment { AuthorName = "Test", AuthorEmail = "*****@*****.**", AuthorUrl = "", Body = "Comment", Posted = DateTime.Now, Entry = entry }; entry.Comments.Add(comment); repo.Add(comment); }); Database.WithRepository( repo => { var entry = repo.FindFirst(new EntryByNameQuery(name)); Assert.AreEqual("A1", entry.Author); Assert.AreEqual("Test", entry.Comments.First().AuthorName); }); }
public RevisionsModel(PageName page, Entry entry) { Page = page; Entry = entry; }
public IEnumerable<TaskStep> Execute(Dictionary<string, object> properties) { var inputFile = (string)properties["inputFile"]; if (!File.Exists(inputFile)) { throw new ArgumentException("The file: '{0}' does not exist."); } var progress = 0; yield return new TaskStep(progress++, "Input file '{0}' found", inputFile); using (var reader = new StreamReader(inputFile)) { yield return new TaskStep(progress++, "Deserializing input file into BlogML object model"); var blog = BlogMLSerializer.Deserialize(reader); yield return new TaskStep(progress++, "Successfully deserialized BlogML object model from input file"); yield return new TaskStep(progress++, "Blog posts found: {0}", blog.Posts.Count); var remainingProgress = 100 - progress; var postCount = blog.Posts.Count; var postIndex = 0; foreach (var post in blog.Posts) { postIndex++; progress = (int)(((double)postIndex / postCount) * (double)remainingProgress); var entry = new Entry(); entry.Author = authenticator.GetName(); entry.HideChrome = false; entry.IsDiscussionEnabled = true; entry.Status = post.PostType == BlogPostTypes.Article ? EntryStatus.PublicPage : EntryStatus.PublicBlog; entry.Title = entry.MetaTitle = NoLongerThan(200, post.Title); entry.Published = post.DateCreated < DateTime.Today.AddYears(-100) ? DateTime.UtcNow : post.DateCreated; entry.Summary = post.HasExcerpt ? NoLongerThan(500, StripHtml(post.Excerpt.UncodedText)) : ""; entry.MetaDescription = post.HasExcerpt ? NoLongerThan(200, StripHtml(post.Excerpt.UncodedText)) : NoLongerThan(200, StripHtml(post.Content.UncodedText)); entry.Name = NoLongerThan(100, (post.PostUrl ?? post.PostName ?? post.ID).Trim('/')); // Ensure this post wasn't already imported var existing = repository.FindFirstOrDefault(new EntryByNameQuery(entry.Name)); if (existing != null) { yield return new TaskStep(progress, "Did NOT import post '{0}', because a post by this name already exists", entry.Name); continue; } var revision = entry.Revise(); revision.Author = authenticator.GetName(); revision.Body = post.Content.UncodedText; revision.Format = Formats.Html; revision.Reason = "Imported from BlogML"; foreach (BlogMLComment comment in post.Comments) { var newComment = entry.Comment(); newComment.AuthorEmail = NoLongerThan(100, comment.UserEMail); newComment.AuthorName = NoLongerThan(100, comment.UserName); newComment.AuthorUrl = NoLongerThan(100, comment.UserUrl); newComment.IsSpam = !comment.Approved; newComment.Posted = comment.DateCreated < DateTime.Today.AddYears(-100) ? DateTime.UtcNow : comment.DateCreated; newComment.Body = comment.Content.UncodedText; } foreach (BlogMLCategoryReference categoryRef in post.Categories) { var category = blog.Categories.FirstOrDefault(x => x.ID == categoryRef.Ref); if (category == null) continue; var tagName = new string( (category.Title?? string.Empty) .ToLowerInvariant() .Select(x => char.IsLetterOrDigit(x) ? x : '-') .ToArray()); if (string.IsNullOrEmpty(tagName)) continue; var existingTag = repository.FindFirstOrDefault(new SearchTagsByNameQuery(tagName)); if (existingTag == null) { existingTag = new Tag {Name = tagName}; repository.Add(existingTag); } existingTag.Add(entry); } repository.Add(entry); yield return new TaskStep(progress, "Imported post '{0}'", entry.Name); } } yield break; }
public CommentPostedEvent(Entry entry, Comment comment) { this.entry = entry; this.comment = comment; }
public EntrySavedEvent(Entry entry) { this.entry = entry; }
private Entry CreateUpdatePost(string postid, Post post, bool publish) { using (var transaction = session.BeginTransaction(IsolationLevel.Serializable)) { var isOldPost = true; var author = authenticator.GetName(); var entry = repository.Get<Entry>(Int32.Parse(postid)); if (entry == null) { entry = new Entry { Author = author }; isOldPost = false; } entry.Name = post.permalink; entry.Title = post.title ?? string.Empty; entry.Summary = string.IsNullOrEmpty(post.mt_excerpt) ? entry.Summary : post.mt_excerpt; entry.MetaTitle = post.title; entry.Published = (post.dateCreated < DateTime.Today.AddYears(10) ? DateTime.Today : post.dateCreated).ToUniversalTime(); entry.Status = publish ? EntryStatus.PublicBlog : EntryStatus.Private; var revision = entry.Revise(); revision.Author = author; revision.Body = post.description; revision.Reason = "API"; revision.Format = string.Equals(post.format, Formats.Markdown, StringComparison.InvariantCultureIgnoreCase) ? Formats.Markdown : Formats.Html; if (string.IsNullOrWhiteSpace(entry.Name)) entry.Name = post.title.Replace(" ", "-"); // support for slug if (!string.IsNullOrEmpty(post.wp_slug)) entry.Name = post.wp_slug; entry.MetaDescription = entry.MetaDescription ?? post.mt_excerpt; var editTags = post.categories; var toDelete = entry.Tags.Where(t => !editTags.Contains(t.Name)).ToList(); var toAdd = editTags.Where(t => entry.Tags.All(tag => tag.Name != t)).ToList(); foreach (var tag in toDelete) { tag.Remove(entry); } foreach (var tag in toAdd) { var existingTag = repository.FindFirstOrDefault(new SearchTagsByNameQuery(tag)); if (existingTag == null) { existingTag = new Tag { Name = tag }; repository.Add(existingTag); } existingTag.Add(entry); } //Does it need to be added? if (!isOldPost) { repository.Add(entry); } session.Flush(); transaction.Commit(); return entry; } }
private Post ConvertToPost(Entry entry) { return new Post { dateCreated = entry.LatestRevision.Revised, categories = entry.Tags.Select(t => t.Name).ToArray(), description = entry.LatestRevision.Body, permalink = entry.Name.ToString(), postid = entry.Id, title = entry.Title, userid = "FunnelWeb", wp_slug = entry.Name.ToString(), mt_excerpt = entry.MetaDescription }; }
private Entry CreateUpdatePost(string username, string password, string postid, Post post, bool publish) { if (ValidateUser(username, password)) { using (var transaction = session.BeginTransaction(IsolationLevel.Serializable)) { var author = authenticator.GetName(); var entry = repository.Get<Entry>(Int32.Parse(postid)); if (entry == null) { entry = new Entry { Author = author }; repository.Add(entry); } entry.Name = post.permalink; entry.Title = post.title ?? string.Empty; entry.Summary = post.mt_excerpt ?? string.Empty; entry.MetaTitle = post.title; entry.Published = (post.dateCreated < DateTime.Today.AddYears(10) ? DateTime.Today : post.dateCreated).ToUniversalTime(); entry.Status = publish ? EntryStatus.PublicBlog : EntryStatus.Private; var revision = entry.Revise(); revision.Author = author; revision.Body = post.description; revision.Reason = "API"; revision.Format = Formats.Html; if (string.IsNullOrWhiteSpace(entry.Name)) entry.Name = post.title.Replace(" ", "-"); // support for slug if (!string.IsNullOrEmpty(post.wp_slug)) entry.Name = post.wp_slug; entry.MetaDescription = entry.Summary; var editTags = post.categories; var toDelete = entry.Tags.Where(t => !editTags.Contains(t.Name)).ToList(); var toAdd = editTags.Where(t => !entry.Tags.Any(tag=>tag.Name == t)).ToList(); foreach (var tag in toDelete) tag.Remove(entry); foreach (var tag in toAdd) { var existingTag = repository.FindFirstOrDefault(new SearchTagsByNameQuery(tag)); if (existingTag == null) { existingTag = new Tag { Name = tag }; repository.Add(existingTag); } existingTag.Add(entry); } session.Flush(); transaction.Commit(); return entry; } } return null; }