Inheritance: BlogMLNode
Exemplo n.º 1
0
        public void Process(BlogMLPost postml)
        {
            Log.Debug("Fetching trackbacks.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Trackback WHERE PostID='" + postml.ID + "'"))
            {
                var trackbacks = query.Execute();

                foreach (var track in trackbacks)
                {
                    var trackbackml = new BlogMLTrackback
                    {
                        Approved = false, /* Oxite has no trackback approving */
                        DateCreated = track.CreatedDate,
                        DateModified = track.ModifiedDate,
                        ID = track.TrackbackID.ToString(),
                        Title = track.Title,
                        Url = track.Url
                    };

                    postml.Trackbacks.Add(trackbackml);
                }
            }

            Log.DebugFormat("Finished adding {0} trackbacks.", postml.Trackbacks.Count);
        }
        public void Process(BlogMLPost postml)
        {
            Log.DebugFormat("Fetching anonymous comments for PostID {0}", postml.ID);

            using (var query = new OxiteReader("SELECT * FROM oxite_CommentAnonymous A, oxite_Comment B WHERE A.CommentID = B.CommentID AND PostID='" + postml.ID + "'"))
            {
                var comments = query.Execute();

                foreach (var comment in comments)
                {
                    var commentml = new BlogMLComment
                    {
                        ID = comment.CommentID.ToString(),
                        DateCreated = comment.CreatedDate,
                        DateModified = comment.ModifiedDate,
                        Approved = comment.State == (int)RecordStates.Normal,
                        UserName = comment.Name,
                        UserUrl = comment.Url,
                        UserEMail = comment.Email,
                        Content = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text = comment.Body
                        }
                    };

                    postml.Comments.Add(commentml);
                }
            }

            Log.DebugFormat("Finished adding anonymous comments.");
        }
Exemplo n.º 3
0
        public Entry ConvertBlogPost(BlogMLPost post, BlogMLBlog blogMLBlog, Blog blog)
        {
            DateTime dateModified = blog != null ? blog.TimeZone.FromUtc(post.DateModified) : post.DateModified;
            DateTime dateCreated = blog != null ? blog.TimeZone.FromUtc(post.DateCreated) : post.DateCreated;

            var newEntry = new Entry((post.PostType == BlogPostTypes.Article) ? PostType.Story : PostType.BlogPost)
            {
                Title = GetTitleFromPost(post).Left(BlogPostTitleMaxLength),
                DateCreated = dateCreated,
                DateModified = dateModified,
                DateSyndicated = post.Approved ? dateModified : DateTime.MaxValue,
                Body = post.Content.UncodedText,
                IsActive = post.Approved,
                DisplayOnHomePage = post.Approved,
                IncludeInMainSyndication = post.Approved,
                IsAggregated = post.Approved,
                AllowComments = true,
                Description = post.HasExcerpt ? post.Excerpt.UncodedText: null
            };

            if(!string.IsNullOrEmpty(post.PostName))
            {
                newEntry.EntryName = post.PostName;
            }
            else
            {
                SetEntryNameForBlogspotImport(post, newEntry);
            }

            SetEntryAuthor(post, newEntry, blogMLBlog);

            SetEntryCategories(post, newEntry, blogMLBlog);
            return newEntry;
        }
Exemplo n.º 4
0
        public void Write_WithBlogContainingEmbeddedAttachmentsWithComments_WritesPostAttachmentsToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime };
            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost { Title = "This is a blog post" };
            var attachment = new BlogMLAttachment
            {
                Data = new byte[] {1, 2, 3, 4, 5},
                Path = @"c:\\path-to-attachment.jpg",
                Url = "/foo/path-to-attachment.jpg",
                Embedded = true,
                MimeType = "img/jpeg"
            };
            post.Attachments.Add(attachment);
            var posts = new List<BlogMLPost> { post };

            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Assert.Contains(output, @"external-uri=""c:\\path-to-attachment.jpg""");
            Assert.Contains(output, @"url=""/foo/path-to-attachment.jpg""");
            Assert.Contains(output, @"mime-type=""img/jpeg""");
            Assert.Contains(output, @"embedded=""true""");
            Assert.Contains(output, @"AQIDBAU=</attachment>");
        }
        public void ConvertBlogPost_WithNullPostNameButWithPostUrlContainingBlogSpotDotCom_UsesLastSegmentAsEntryName()
        {
            // arrange
            var post = new BlogMLPost { PostUrl = "http://example.blogspot.com/2003/07/the-last-segment.html" };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual("the-last-segment", entry.EntryName);
        }
Exemplo n.º 6
0
 protected void WritePostCategories(BlogMLPost.CategoryReferenceCollection categoryRefs)
 {
     if (categoryRefs.Count > 0)
     {
         WriteStartCategories();
         foreach (BlogMLCategoryReference categoryRef in categoryRefs)
         {
             WriteCategoryReference(categoryRef.Ref);
         }
         WriteEndElement();
     }
 }
Exemplo n.º 7
0
 public static BlogMLPost CreatePostInstance(string id, string title, string url, bool approved, string content, DateTime dateCreated, DateTime dateModified)
 {
     BlogMLPost post = new BlogMLPost();
     post.ID = id;
     post.Title = title;
     post.PostUrl = url;
     post.Approved = approved;
     post.Content = new BlogMLContent();
     post.Content.Text = content;
     post.DateCreated = dateCreated;
     post.DateModified = dateModified;
     return post;
 }
Exemplo n.º 8
0
 private ICollection<Category> GetPostCategoryies(BlogMLBlog.CategoryCollection categories, BlogMLPost blogMLPost)
 {
     var list = new List<Category>();
     if (blogMLPost == null || blogMLPost.Categories == null) return new Collection<Category>();
     for (int i = 0; i < blogMLPost.Categories.Count; i++)
     {
         string postCategoryId = blogMLPost.Categories[i].Ref;
         list.AddRange(from category in categories
                       where category.ID == postCategoryId
                       select new Category {CategoryName = category.Title});
     }
     return list;
 }
Exemplo n.º 9
0
        public void ConvertBlogPost_WithDateModified_ReturnsItAsDatePublishedUtc()
        {
            // arrange
            DateTime utcNow = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            var post = new BlogMLPost { Approved = true, DateModified = utcNow };
            var blog = new Mock<Blog>();
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), blog.Object);

            // assert
            Assert.AreEqual(utcNow, entry.DatePublishedUtc);
        }
        public void ConvertBlogPost_WithApprovedPost_SetsAppropriatePublishPropertiesOfEntry()
        {
            // arrange
            var post = new BlogMLPost {Approved = true};
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.IsTrue(entry.IsActive);
            Assert.IsTrue(entry.DisplayOnHomePage);
            Assert.IsTrue(entry.IncludeInMainSyndication);
            Assert.IsTrue(entry.IsAggregated);
        }
        public void ConvertBlogPost_WithAuthorTitleTooLong_TruncatesTitleToMaxLength()
        {
            // arrange
            var title = new string('a', 51);
            var blog = new BlogMLBlog();
            blog.Authors.Add(new BlogMLAuthor{ID = "123", Title = title});
            var post = new BlogMLPost();
            post.Authors.Add("123");
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual(50, entry.Author.Length);
        }
        public void ConvertBlogPost_WithAuthorMatchingBlogAuthor_SetsAuthorNameAndEmail()
        {
            // arrange
            var blog = new BlogMLBlog();
            blog.Authors.Add(new BlogMLAuthor { ID = "111", Title = "Not-Haacked", Email = "*****@*****.**"});
            blog.Authors.Add(new BlogMLAuthor { ID = "222", Title = "Haacked", Email = "*****@*****.**"});
            var post = new BlogMLPost();
            post.Authors.Add("222");
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual("Haacked", entry.Author);
            Assert.AreEqual("*****@*****.**", entry.Email);
        }
        public void CreateBlogPost_WithEntryPublisher_PublishesBlogPostAndReturnsId()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            var entryPublisher = new Mock<IEntryPublisher>();
            entryPublisher.Setup(p => p.Publish(It.IsAny<Entry>())).Returns(310);
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher.Object, new BlogMLImportMapper());

            // act
            var id = repository.CreateBlogPost(blog, post);

            // assert
            Assert.AreEqual("310", id);
        }
        public void Process(BlogMLPost postml)
        {
            Log.DebugFormat("Setting up category references on post {0}", postml.ID);

            using (var query = new OxiteReader("SELECT * FROM oxite_Post A, oxite_PostTagRelationship B WHERE A.PostID=B.PostID AND A.PostID='" + postml.ID + "'"))
            {
                var tagRefs = query.Execute();

                foreach(var tag in tagRefs)
                {
                    var commentRef = new BlogMLCategoryReference
                    {
                        Ref = tag.TagID.ToString()
                    };

                    postml.Categories.Add(commentRef);
                }
            }
        }
        public void CreateBlogPost_WithEntryPublisher_RemovesKeywordExpander()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            context.Setup(c => c.Repository.Create(It.IsAny<Entry>(), It.IsAny<IEnumerable<int>>()));
            var transformation = new CompositeTextTransformation();
            var searchengine = new Mock<IIndexingService>();
            var entryPublisher = new EntryPublisher(context.Object, transformation, null, searchengine.Object);
            var keywordExpander = new KeywordExpander((IEnumerable<KeyWord>)null);
            transformation.Add(keywordExpander);
            var blog = new BlogMLBlog() { Title = "MyBlog" };
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher, new BlogMLImportMapper());

            // act
            repository.CreateBlogPost(blog, post);

            // assert
            Assert.IsFalse(transformation.Contains(keywordExpander));
        }
Exemplo n.º 16
0
        private void ProcessPosts(BlogMLBlog blogml)
        {
            Log.Info("Fetching blog posts.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Post"))
            {
                var posts = query.Execute();

                foreach (var post in posts)
                {
                    var postml = new BlogMLPost
                    {
                        Content = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text = post.Body
                        },
                        Excerpt = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text = post.BodyShort
                        },
                        Approved = post.State == (int)RecordStates.Normal,
                        DateCreated = post.CreatedDate,
                        DateModified = post.ModifiedDate,
                        HasExcerpt = !string.IsNullOrWhiteSpace(post.BodyShort),
                        ID = post.PostID.ToString(),
                        PostName = post.Title,
                        PostType = BlogPostTypes.Normal,
                        PostUrl = post.Slug,
                        Title = post.Title,
                    };

                    blogml.Posts.Add(postml);
                }

                Log.InfoFormat("Finished adding {0} posts.", blogml.Posts.Count);
            }
        }
Exemplo n.º 17
0
        public void Write_WithBlogContainingBase64EncodedPosts_WritesPostsToWriterAsBase64Encoded()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented };
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime };
            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost { Content = BlogMLContent.Create("<p>This is a Test</p>", ContentTypes.Base64) };
            var posts = new List<BlogMLPost> { post };
            blog.Posts.Add(post);
            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes("<p>This is a Test</p>")));
            Assert.Contains(output, @"<content type=""base64""><![CDATA[PHA+VGhpcyBpcyBhIFRlc3Q8L3A+]]></content>");
        }
Exemplo n.º 18
0
        public void Import_WithEmbeddedAttachments_CreatesFilesForAttachmentsAndRewritesBlogPost()
        {
            // arrange
            var data = new byte[] { 1, 2, 3 };
            var attachment = new BlogMLAttachment { Url = "http://old.example.com/images/my-mug.jpg", Embedded = true, Data = data };
            var post = new BlogMLPost { Content = new BlogMLContent { Text = @"<img src=""http://old.example.com/images/my-mug.jpg"" />" } };
            post.Attachments.Add(attachment);
            var blog = new BlogMLBlog();
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.GetAttachmentDirectoryPath()).Returns(ImageDirectory + "/wlw");
            repository.Setup(r => r.GetAttachmentDirectoryUrl()).Returns("http://example.com/images/wlw/");
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(File.Exists(Path.Combine(ImageDirectory, @"wlw\my-mug.jpg")));
            Assert.AreEqual(@"<img src=""http://example.com/images/wlw/my-mug.jpg"" />", post.Content.UncodedText);
        }
Exemplo n.º 19
0
        public void Import_WithCreateTrackbackThrowingException_DoesNotPropagateException()
        {
            // arrange
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            post.Trackbacks.Add(new BlogMLTrackback());
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.CreateTrackback(It.IsAny<BlogMLTrackback>(), It.IsAny<string>())).Throws(new InvalidOperationException());
            var service = new BlogImportService(repository.Object);

            // act, assert
            service.Import(blog);
        }
Exemplo n.º 20
0
        public void Import_WithBlogPostHavingTrackback_CreatesTrackbackUsingPostId()
        {
            // arrange
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            var trackback = new BlogMLTrackback();
            post.Trackbacks.Add(trackback);
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.CreateBlogPost(blog, post)).Returns("98053");
            bool trackbackCreated = false;
            repository.Setup(r => r.CreateTrackback(trackback, "98053")).Callback(() => trackbackCreated = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(trackbackCreated);
        }
Exemplo n.º 21
0
        public void Import_WithBlogPostHavingComments_CreatesCommentUsingPostId()
        {
            // arrange
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            var comment = new BlogMLComment();
            post.Comments.Add(comment);
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.CreateBlogPost(blog, post)).Returns("98053");
            bool commentCreated = false;
            repository.Setup(r => r.CreateComment(comment, "98053")).Callback(() => commentCreated = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(commentCreated);
        }
Exemplo n.º 22
0
        public void Import_WithBlogPostHavingBase64EncodedContentWithAttachments_ProperlyRewritesAttachments()
        {
            // arrange
            var blog = new BlogMLBlog();
            const string originalPostContent = @"<img src=""http://old.example.com/images/my-mug.jpg"" />";
            var post = new BlogMLPost { Content = BlogMLContent.Create(originalPostContent, ContentTypes.Base64) };
            var attachment = new BlogMLAttachment { Url = "http://old.example.com/images/my-mug.jpg", Embedded = false};
            post.Attachments.Add(attachment);
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.GetAttachmentDirectoryUrl()).Returns("http://new.example.com/images/");
            repository.Setup(r => r.GetAttachmentDirectoryPath()).Returns(@"c:\web\images");
            BlogMLPost publishedPost = null;
            repository.Setup(r => r.CreateBlogPost(blog, post)).Callback<BlogMLBlog, BlogMLPost>((b, p) => publishedPost = p);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.AreEqual(ContentTypes.Base64, publishedPost.Content.ContentType);
            Assert.AreEqual(@"<img src=""http://new.example.com/images/my-mug.jpg"" />", publishedPost.Content.UncodedText);
        }
Exemplo n.º 23
0
        public BlogMLPost ConvertEntry(EntryStatsView entry, bool embedAttachments)
        {
            string postUrl = null;
            var entryVirtualPath = Url.EntryUrl(entry);
            if (entryVirtualPath != null)
            {
                postUrl = entryVirtualPath.ToFullyQualifiedUrl(Blog).ToString();
            }
            var post = new BlogMLPost
            {
                Title = entry.Title,
                PostUrl = postUrl,
                PostType = (entry.PostType == PostType.Story) ? BlogPostTypes.Article : BlogPostTypes.Normal,
                Approved = entry.IsActive,
                Content = BlogMLContent.Create(entry.Body ?? string.Empty, ContentTypes.Base64),
                HasExcerpt = entry.HasDescription,
                Excerpt = BlogMLContent.Create(entry.Description ?? string.Empty, ContentTypes.Base64),
                DateCreated = entry.DateCreatedUtc,
                DateModified = entry.IsActive ? entry.DatePublishedUtc : entry.DateModifiedUtc,
                Views = (uint)entry.WebCount
            };

            if (entry.HasEntryName)
            {
                post.PostName = entry.EntryName;
            }

            // When we support multiple authors, this will have to change
            post.Authors.Add(Blog.Id.ToString(CultureInfo.InvariantCulture));
            post.Attachments.AddRange(GetPostAttachments(entry.Body, embedAttachments).ToArray());
            var comments = (from c in entry.Comments where c.FeedbackType == FeedbackType.Comment select ConvertComment(c)).ToList();
            if (comments.Count > 0)
            {
                post.Comments.AddRange(comments);
            }
            var trackbacks = (from c in entry.Comments where c.FeedbackType == FeedbackType.PingTrack select ConvertTrackback(c)).ToList();
            if (trackbacks.Count > 0)
            {
                post.Trackbacks.AddRange(trackbacks);
            }
            return post;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Loads the post from data reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static BlogMLPost LoadPostFromDataReader(IDataReader reader)
        {
            Entry entry = DataHelper.LoadEntry(reader);
            BlogMLPost bmlPost = new BlogMLPost();
            bmlPost.ID = entry.Id.ToString(CultureInfo.InvariantCulture);
            bmlPost.Title = entry.Title;
            bmlPost.PostUrl = entry.FullyQualifiedUrl.ToString();
            bmlPost.Approved = entry.IsActive;
            bmlPost.Content.Text = entry.Body;
            bmlPost.DateCreated = entry.DateCreated;
            bmlPost.DateModified = entry.DateModified;
            bmlPost.PostType = (entry.PostType == PostType.Story) ? BlogPostTypes.Article : BlogPostTypes.Normal;
            bmlPost.Views = 0; // I think we have this statistic in the db... right?

            if (entry.HasEntryName)
            {
                bmlPost.PostName = entry.EntryName;
            }

            bmlPost.HasExcerpt = entry.HasDescription;
            if (entry.HasDescription)
            {
                bmlPost.Excerpt.Text = entry.Description;
            }

            return bmlPost;
        }
Exemplo n.º 25
0
 private string getAuthorId(Dictionary<string, User> usersList, BlogMLPost post)
 {
     string authorId;
     User user;
     if (post.Authors.Count > 0 &&
         usersList.TryGetValue(post.Authors.Cast<BlogMLAuthorReference>().First().Ref, out user))
     {
         authorId = user.Id;
     }
     else
     {
         authorId = usersList.First().Value.Id;
     }
     return authorId;
 }
Exemplo n.º 26
0
 public void Setup()
 {
     TestData.Init();
     _mlPost = new PostToBlogMLMapper().MapFrom(TestData.PublishedPost);
 }
Exemplo n.º 27
0
        private BlogMLBlog BuildBlogML()
        {
            var mlBlog = new BlogMLBlog();
            var author = new BlogMLAuthor {Title = "admin"};
            mlBlog.Authors.Add(author);
            var cat = new BlogMLCategory {Title = "Title 1", ID = "1"};
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 2", ID = "2" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 3", ID = "3" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 4", ID = "4" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 5", ID = "5" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 6", ID = "6" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 7", ID = "7" };
            mlBlog.Categories.Add(cat);
            cat = new BlogMLCategory { Title = "Title 8", ID = "8" };
            mlBlog.Categories.Add(cat);

            var mlPost = new BlogMLPost();
            mlPost.Categories.Add("1");
            mlPost.Approved = true;
            mlPost.Content = new BlogMLContent {ContentType = ContentTypes.Text, Text = "post 1"};
            mlPost.DateCreated = new DateTime(2012, 2, 2);
            mlPost.DateModified = new DateTime(2012, 2, 2);
            mlPost.Excerpt = new BlogMLContent { ContentType = ContentTypes.Text, Text = "post 1" };
            mlPost.HasExcerpt = true;
            mlPost.ID = "1";
            mlPost.PostName = "name 1";
            mlPost.PostType = BlogPostTypes.Normal;
            var trackback = new BlogMLTrackback
                                            {
                                                Approved = true,
                                                DateCreated = new DateTime(2012, 2, 2),
                                                DateModified = new DateTime(2012, 2, 2),
                                                ID = "2",
                                                Title = "trackback title 2",
                                                Url = "url2"
                                            };
            mlPost.Trackbacks.Add(trackback);
            mlPost.Title = "Title 1";
            mlPost.Views = 0;
            mlBlog.Posts.Add(mlPost);

            mlPost = new BlogMLPost();
            mlPost.Categories.Add("1");
            mlPost.Approved = true;
            mlPost.Content = new BlogMLContent { ContentType = ContentTypes.Text, Text = "post 3" };
            mlPost.DateCreated = new DateTime(2032, 3, 3);
            mlPost.DateModified = new DateTime(2032, 3, 3);
            mlPost.Excerpt = new BlogMLContent { ContentType = ContentTypes.Text, Text = "post 3" };
            mlPost.HasExcerpt = true;
            mlPost.ID = "3";
            mlPost.PostName = "name 3";
            mlPost.PostType = BlogPostTypes.Normal;
            trackback = new BlogMLTrackback
            {
                Approved = true,
                DateCreated = new DateTime(2032, 3, 3),
                DateModified = new DateTime(2032, 3, 3),
                ID = "3",
                Title = "trackback title 3",
                Url = "url1"
            };
            mlPost.Trackbacks.Add(trackback);
            mlPost.Title = "Title 2";
            mlPost.Views = 0;
            mlBlog.Posts.Add(mlPost);

            return mlBlog;
        }
Exemplo n.º 28
0
        private bool ValidateModel(BlogPostViewModel blogPostModel, BlogMLPost blogML, out BlogPostImportResult failedResult)
        {
            failedResult = null;

            if (string.IsNullOrWhiteSpace(blogML.ID))
            {
                failedResult = new BlogPostImportResult
                {
                    Title = blogML.Title,
                    PageUrl = blogML.PostUrl,
                    Success = false,
                    ErrorMessage = BlogGlobalization.ImportBlogPosts_ImportingBlogPostIdIsNotSet_Message,
                    Id = blogML.ID
                };
                return false;
            }

            var validationContext = new ValidationContext(blogPostModel, null, null);
            var validationResults = new List<ValidationResult>();
            if (!Validator.TryValidateObject(blogPostModel, validationContext, validationResults, true)
                && validationResults.Count > 0)
            {
                failedResult = new BlogPostImportResult
                    {
                        Title = blogML.Title,
                        PageUrl = blogML.PostUrl,
                        Success = false,
                        ErrorMessage = validationResults[0].ErrorMessage,
                        Id = blogML.ID
                    };
                return false;
            }

            try
            {
                pageService.ValidatePageUrl(blogPostModel.BlogUrl);
            }
            catch (Exception exc)
            {
                failedResult = new BlogPostImportResult
                {
                    Title = blogML.Title,
                    PageUrl = blogML.PostUrl,
                    Success = false,
                    ErrorMessage = exc.Message,
                    Id = blogML.ID
                };
                return false;
            }

            return true;
        }
Exemplo n.º 29
0
        private BlogPostViewModel MapViewModel(BlogMLPost blogML, bool useOriginalUrls, BlogPostImportResult modification = null, List<string> unsavedUrls = null)
        {
            var model = new BlogPostViewModel
                    {
                        Title = blogML.PostName ?? blogML.Title,
                        IntroText = blogML.Excerpt != null ? blogML.Excerpt.UncodedText : null,
                        LiveFromDate = blogML.DateCreated.Date,
                        LiveToDate = null,
                        DesirableStatus = ContentStatus.Published,
                        Content = blogML.Content != null ? blogML.Content.UncodedText : null
                    };

            if (modification != null)
            {
                model.BlogUrl = modification.PageUrl;
                model.Title = modification.Title;
            }
            else if (useOriginalUrls)
            {
                model.BlogUrl = blogService.CreateBlogPermalink(FixUrl(blogML.PostUrl), unsavedUrls);
            }
            else
            {
                model.BlogUrl = blogService.CreateBlogPermalink(blogML.Title, unsavedUrls);
            }

            return model;
        }
Exemplo n.º 30
0
 private static bool BlogHasCategory(BlogMLPost blog, string categoryId)
 {
     for (int j = 0; j < blog.Categories.Count; j++)
     {
         if (blog.Categories[j].Ref == categoryId)
         {
             return true;
         }
     }
     return false;
 }