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 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 override void TestQuery()
        {
            var name = Guid.NewGuid().ToString();

            Database.WithRepository(
                repo =>
                {
                    var tag = new Tag { Name = name };
                    repo.Add(tag);
                });

            Database.WithRepository(
                repo =>
                {
                    var result = repo.FindFirstOrDefault(new SearchTagsByNameQuery(name));
                    Assert.NotNull(result);
                    Assert.AreEqual(name, result.Name);
                });
        }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }
예제 #6
0
        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;
            }
        }