public static PostReference GetNextPrevPost(this IDocumentSession session, Post compareTo, bool isNext)
        {
            var queryable = session.Query<Post>()
                .WhereIsPublicPost();

            if (isNext)
            {
                queryable = queryable
                    .Where(post => post.PublishAt >= compareTo.PublishAt && post.Id != compareTo.Id)
                    .OrderBy(post => post.PublishAt);
            }
            else
            {
                queryable = queryable
                    .Where(post => post.PublishAt <= compareTo.PublishAt && post.Id != compareTo.Id)
                    .OrderByDescending(post => post.PublishAt);
            }

            var postReference = queryable
                .Select(p => new PostReference
                {
                    Id = p.Id,
                    Title = p.Title,
                    PublishAt = p.PublishAt,
                })
                .FirstOrDefault();

            return postReference;
        }
예제 #2
0
        public bool AreCommentsClosed(Post post, int numberOfDayToCloseComments)
        {
            if (numberOfDayToCloseComments < 1)
            {
                return false;
            }

            var lastCommentDate = Comments.Count == 0 ? post.PublishAt : Comments.Max(x => x.Created);
            return ApplicationTime.Current - lastCommentDate > TimeSpan.FromDays(numberOfDayToCloseComments);
        }
        public void should_return_data_error_before_bloging_if_year_is_earlier_then_first_post()
        {
            var currentDate = ApplicationTime.Current;
            var post = new Post();
            post.Title = "test";
            post.Created = post.Modified = post.PublishAt = currentDate;
            set_data(session => session.Store(post));

            var result = _validator.Validate(currentDate.Year - 1, null, null);

            Assert.Equal(DateError.BeforeBloging, result.Result);
        }
예제 #4
0
        public void should_return_redirect_result_if_post_exists()
        {
            var id = Guid.NewGuid();
             var post = new Post();
             post.Title = "title";
             post.Created = post.Modified = post.PublishAt = ApplicationTime.Current;
             post.LegacyUniqueId = id.ToString();

             set_data(session => session.Store(post));
             _queryStrings.Add("id", id.ToString());
             var result = _controller.PostByUid();

             Assert.IsType<RedirectToRouteResult>(result);
        }
예제 #5
0
        public void should_return_redirect_result_if_post_exists()
        {
            var post = new Post();
             post.Title = "title";
             post.Created = post.Modified = post.PublishAt = ApplicationTime.Current;
             post.LegacySlug = post.Slug;
             set_data(session => session.Store(post));

             var result = _controller.PostBySlug(post.Created.Year
                 , post.Created.Month
                 , post.Created.Day
                 , post.Slug);

             Assert.IsType<RedirectToRouteResult>(result);
        }
예제 #6
0
        public void should_return_redirect_pernament_result_if_post_exists()
        {
            var post = new Post();
             post.Title = "title";
             post.Created = post.Modified = post.PublishAt = ApplicationTime.Current;
             post.LegacySlug = post.Slug;
             set_data(session => session.Store(post));

             var result = _controller.PostBySlug(post.Created.Year
                 , post.Created.Month
                 , post.Created.Day
                 , post.Slug) as RedirectToRouteResult;

             Assert.True(result.Permanent, "this url is not used any more, therefore we should redirect pernamently");
        }
예제 #7
0
        public void should_return_redirect_pernament_result_if_post_exists()
        {
            var id = Guid.NewGuid();
             var post = new Post();
             post.Title = "title";
             post.Created = post.Modified = post.PublishAt = ApplicationTime.Current;
             post.LegacyUniqueId = id.ToString();

             set_data(session => session.Store(post));

             _queryStrings.Add("id", id.ToString());

             var result = _controller.PostByUid() as RedirectToRouteResult;

             Assert.True(result.Permanent, "this url is not used any more, therefore we should redirect pernamently");
        }
        public void Send(Post post, Uri itemUri)
        {
            _log.Trace("sending notification for Post: {0}", post.Title);
            var uris = get_uris(post.Content);
            foreach (var uri in uris)
            {
                _log.Trace("Uri: {0} found in post content, trying to send trackback", uri);
                var trackback = false;

                // todo: send trackback

                if (!trackback)
                {
                    _log.Trace("Trackback didnt work, sending ping to: {0}", uri);
                    send_ping(itemUri, uri);
                }
            }
        }
예제 #9
0
        public void should_redirect_to_details_action_on_post_details_controller()
        {
            var id = Guid.NewGuid();
             var post = new Post();
             post.Title = "title";
             post.Created = post.Modified = post.PublishAt = ApplicationTime.Current;
             post.LegacyUniqueId = id.ToString();

             set_data(session => session.Store(post));

             _queryStrings.Add("id", id.ToString());
             var result = _controller.PostByUid() as RedirectToRouteResult;

             Assert.Equal("PostDetails", result.RouteValues["controller"]);
             Assert.Equal("Details", result.RouteValues["action"]);
             Assert.Equal(post.Created.Year, result.RouteValues["year"]);
             Assert.Equal(post.Created.Month, Convert.ToInt32(result.RouteValues["month"]));
             Assert.Equal(post.Created.Day, Convert.ToInt32(result.RouteValues["day"]));
             Assert.Equal(post.Slug, result.RouteValues["slug"]);
        }
예제 #10
0
 public void SendAsync(Post post, Uri itemUri)
 {
     new Task(() => Send(post, itemUri)).Start();
 }
예제 #11
0
        public void ImportBlogMl()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tCreating Users...");
            using (var session = _store.OpenSession())
            {
                var user = new BlogOwner
                {
                    Id = "Blog/Owner",
                    Email = "",
                    FirstName = "",
                    LastName = "",
                    Nick = "",
                    Twitter = ""
                };

                user.ResetPassword("admin123");

                session.Store(user);
                session.SaveChanges();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tImporting Posts...");

            foreach (var oldPost in _blog.Posts)
            {
                var post = new Post
                {
                    AuthorId = "Blog/Owner",
                    Created = new DateTimeOffset(oldPost.DateCreated),
                    Modified = new DateTimeOffset(oldPost.DateCreated),
                    PublishAt = new DateTimeOffset(oldPost.DateCreated),
                    Content = oldPost.Content.Text.Replace("http:/URL/image.axd?picture=", "http://URL/content/old-images/"),

                    Title = HttpUtility.HtmlDecode(oldPost.Title),
                    Slug = SlugConverter.TitleToSlug(HttpUtility.HtmlDecode(oldPost.Title)),
                    LegacyUniqueId = oldPost.ID,
                    LegacySlug = Regex.Match(oldPost.PostUrl, @"([^/]+)(?=\.\w+$)").Value,

                    AllowComments = true
                };

                var categoriesRefs = oldPost.Categories.OfType<BlogMLCategoryReference>();
                var oldCategories = from x in categoriesRefs
                                    join z in _blog.Categories on x.Ref equals z.ID
                                    select new Post.SlugItem
                                    {
                                        Title = z.Title
                                    };

                var oldTags = from x in oldPost.Tags.OfType<BlogMLTagReference>()
                              select new Post.SlugItem
                              {
                                Title = x.Ref
                              };

                post.Categories = oldCategories.ToList();
                post.Tags = oldTags.ToList();

                var commentsCollection = new PostComments();

                foreach (var oldComment in oldPost.Comments.OfType<BlogMLComment>())
                {
                    var comment = new PostComments.Comment
                    {
                        Id = commentsCollection.GenerateNewCommentId(),
                        Author = oldComment.UserName,
                        Content = convert_to_markdown(oldComment.Content.Text),
                        Created = oldComment.DateCreated,
                        Email = oldComment.UserEMail,
                        Type = CommentType.Comment,
                        Url = oldComment.UserUrl,
                        Important = oldComment.UserEMail.Equals("EMAIL", StringComparison.OrdinalIgnoreCase),
                        UserAgent = string.Empty,
                        UserHostAddress = oldComment.UserIp,
                        IsSpam = oldComment.Approved == false,
                    };

                    if (oldComment.Approved)
                    {
                        commentsCollection.Comments.Add(comment);
                    }
                    else
                    {
                        commentsCollection.Spam.Add(comment);
                    }

                }

                foreach (var trackbacks in oldPost.Trackbacks.OfType<BlogMLTrackback>())
                {
                    var comment = new PostComments.Comment
                    {
                        Id = commentsCollection.GenerateNewCommentId(),
                        Type = CommentType.Trackback,
                        Author = trackbacks.UserName,
                        Content = trackbacks.Content.Text,
                        Created = trackbacks.DateCreated,
                        Email = CommentType.Trackback.ToString(),
                        Url = trackbacks.Url,
                        Important = false,
                        UserAgent = string.Empty,
                        UserHostAddress = trackbacks.UserIp,
                        IsSpam = trackbacks.Approved == false,
                    };

                    if (trackbacks.Approved)
                    {
                        commentsCollection.Comments.Add(comment);
                    }
                    else
                    {
                        commentsCollection.Spam.Add(comment);
                    }
                }

                post.CommentsCount = commentsCollection.Comments.Count;

                using (IDocumentSession session = _store.OpenSession())
                {
                    session.Store(commentsCollection);
                    post.CommentsId = commentsCollection.Id;

                    session.Store(post);
                    commentsCollection.Post = new PostComments.PostReference
                    {
                        Id = post.Id,
                        Published = post.PublishAt,
                        Slug = post.Slug
                    };

                    session.SaveChanges();
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tDone...");
        }