Exemple #1
0
        private void ImportTags(XDocument xdoc, IContent postNode, BlogMLPost post)
        {
            //since this blobml serializer doesn't support tags (can't find one that does) we need to manually take care of that
            var xmlPost = xdoc.Descendants(XName.Get("post", xdoc.Root.Name.NamespaceName))
                .SingleOrDefault(x => ((string)x.Attribute("id")) == post.Id);

            if (xmlPost == null) return;

            var tags = xmlPost.Descendants(XName.Get("tag", xdoc.Root.Name.NamespaceName)).Select(x => (string)x.Attribute("ref")).ToArray();
            postNode.SetTags("tags", tags, true, "ArticulateTags");
        }
        private void AddBlogPosts(IContent archiveNode, BlogMLDocument blogMlDoc, string tagGroup)
        {
            const int pageSize = 1000;
            var pageIndex = 0;
            IContent[] posts;
            do
            {
                long total;
                posts = _applicationContext.Services.ContentService.GetPagedChildren(archiveNode.Id, pageIndex, pageSize, out total, "createDate").ToArray();

                foreach (var child in posts)
                {
                    string content = "";
                    if (child.ContentType.Alias.InvariantEquals("ArticulateRichText"))
                    {
                        //TODO: this would also need to export all macros
                        content = child.GetValue<string>("richText");
                    }
                    else if (child.ContentType.Alias.InvariantEquals("ArticulateMarkdown"))
                    {
                        content = child.GetValue<string>("markdown");
                        var markdown = new MarkdownDeep.Markdown();
                        content = markdown.Transform(content);
                    }

                    var blogMlPost = new BlogMLPost()
                    {
                        Id = child.Key.ToString(),
                        Name = new BlogMLTextConstruct(child.Name),
                        Title = new BlogMLTextConstruct(child.Name),
                        ApprovalStatus = BlogMLApprovalStatus.Approved,
                        PostType = BlogMLPostType.Normal,
                        CreatedOn = child.CreateDate,
                        LastModifiedOn = child.UpdateDate,
                        Content = new BlogMLTextConstruct(content, BlogMLContentType.Html),
                        Excerpt = new BlogMLTextConstruct(child.GetValue<string>("excerpt")),
                        Url = new Uri(_umbracoContext.UrlProvider.GetUrl(child.Id), UriKind.RelativeOrAbsolute)
                    };

                    var author = blogMlDoc.Authors.FirstOrDefault(x => x.Title != null && x.Title.Content.InvariantEquals(child.GetValue<string>("author")));
                    if (author != null)
                    {
                        blogMlPost.Authors.Add(author.Id);
                    }

                    var categories = _applicationContext.Services.TagService.GetTagsForEntity(child.Id, tagGroup);
                    foreach (var category in categories)
                    {
                        blogMlPost.Categories.Add(category.Id.ToString());
                    }

                    //TODO: Tags isn't natively supported

                    blogMlDoc.AddPost(blogMlPost);
                }

                pageIndex++;
            } while (posts.Length == pageSize);
        }
Exemple #3
0
        //private async Task ImportComments(int userId, IContent postNode, BlogMLPost post,
        //    string publicKey/*, string privateKey, string accessToken*/)
        //{

        //    var importer = new DisqusImporter(publicKey);

        //    foreach (var comment in post.Comments)
        //    {
        //        var result = await importer.Import(
        //            postNode.Id.ToString(CultureInfo.InvariantCulture),
        //            comment.Content.Content,
        //            comment.UserName,
        //            comment.UserEmailAddress,
        //            comment.UserUrl != null ? comment.UserUrl.ToString() : string.Empty,
        //            comment.CreatedOn);

        //        if (!result)
        //        {
        //            HasErrors = true;
        //        }
        //        else
        //        {
        //            postNode.SetValue("disqusCommentsImported", 1);
        //            //just save it, we don't need to publish it (if publish = true then its already published), we just need
        //            // this for reference.
        //            _applicationContext.Services.ContentService.Save(postNode, userId);    
        //        }
        //    }
        //}

        private void ImportCategories(IContent postNode, BlogMLPost post, IEnumerable<BlogMLCategory> allCategories)
        {
            var postCats = allCategories.Where(x => post.Categories.Contains(x.Id))
                .Select(x => x.Title.Content)
                .ToArray();

            postNode.SetTags("categories", postCats, true, "ArticulateCategories");
        }
        /// <summary>
        /// Modifies the <see cref="BlogMLDocument"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="document">The <see cref="BlogMLDocument"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="BlogMLDocument"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="document"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillDocumentCollections(BlogMLDocument document, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(document, "document");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNodeIterator authorsIterator               = source.Select("blog:authors/blog:author", manager);
            XPathNodeIterator extendedPropertiesIterator    = source.Select("blog:extended-properties/blog:property", manager);
            XPathNodeIterator categoriesIterator            = source.Select("blog:categories/blog:category", manager);
            XPathNodeIterator postsIterator                 = source.Select("blog:posts/blog:post", manager);

            if (authorsIterator != null && authorsIterator.Count > 0)
            {
                while (authorsIterator.MoveNext())
                {
                    BlogMLAuthor author = new BlogMLAuthor();
                    if (author.Load(authorsIterator.Current, settings))
                    {
                        document.Authors.Add(author);
                    }
                }
            }

            if (extendedPropertiesIterator != null && extendedPropertiesIterator.Count > 0)
            {
                while (extendedPropertiesIterator.MoveNext())
                {
                    if (extendedPropertiesIterator.Current.HasAttributes)
                    {
                        string propertyName     = extendedPropertiesIterator.Current.GetAttribute("name", String.Empty);
                        string propertyValue    = extendedPropertiesIterator.Current.GetAttribute("value", String.Empty);

                        if (!String.IsNullOrEmpty(propertyName) && !document.ExtendedProperties.ContainsKey(propertyName))
                        {
                            document.ExtendedProperties.Add(propertyName, propertyValue);
                        }
                    }
                }
            }

            if (categoriesIterator != null && categoriesIterator.Count > 0)
            {
                while (categoriesIterator.MoveNext())
                {
                    BlogMLCategory category = new BlogMLCategory();
                    if (category.Load(categoriesIterator.Current, settings))
                    {
                        document.Categories.Add(category);
                    }
                }
            }

            if (postsIterator != null && postsIterator.Count > 0)
            {
                int counter = 0;
                while (postsIterator.MoveNext())
                {
                    BlogMLPost post = new BlogMLPost();
                    counter++;

                    if (post.Load(postsIterator.Current, settings))
                    {
                        if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit)
                        {
                            break;
                        }

                        ((Collection<BlogMLPost>)document.Posts).Add(post);
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Modifies the <see cref="BlogMLPost"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="post">The <see cref="BlogMLPost"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="BlogMLPost"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="post"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static bool FillPostCollections(BlogMLPost post, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded  = false;

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(post, "post");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNodeIterator categoriesIterator    = source.Select("blog:categories/blog:category", manager);
            XPathNodeIterator commentsIterator      = source.Select("blog:comments/blog:comment", manager);
            XPathNodeIterator trackbacksIterator    = source.Select("blog:trackbacks/blog:trackback", manager);
            XPathNodeIterator attachmentsIterator   = source.Select("blog:attachments/blog:attachment", manager);
            XPathNodeIterator authorsIterator       = source.Select("blog:authors/blog:author", manager);

            if (categoriesIterator != null && categoriesIterator.Count > 0)
            {
                while (categoriesIterator.MoveNext())
                {
                    string referenceId  = categoriesIterator.Current.GetAttribute("ref", String.Empty);
                    if (!String.IsNullOrEmpty(referenceId))
                    {
                        post.Categories.Add(referenceId);
                        wasLoaded       = true;
                    }
                }
            }

            if (commentsIterator != null && commentsIterator.Count > 0)
            {
                while (commentsIterator.MoveNext())
                {
                    BlogMLComment comment   = new BlogMLComment();
                    if (comment.Load(commentsIterator.Current, settings))
                    {
                        post.Comments.Add(comment);
                        wasLoaded           = true;
                    }
                }
            }

            if (trackbacksIterator != null && trackbacksIterator.Count > 0)
            {
                while (trackbacksIterator.MoveNext())
                {
                    BlogMLTrackback trackback   = new BlogMLTrackback();
                    if (trackback.Load(trackbacksIterator.Current, settings))
                    {
                        post.Trackbacks.Add(trackback);
                        wasLoaded               = true;
                    }
                }
            }

            if (attachmentsIterator != null && attachmentsIterator.Count > 0)
            {
                while (attachmentsIterator.MoveNext())
                {
                    BlogMLAttachment attachment = new BlogMLAttachment();
                    if (attachment.Load(attachmentsIterator.Current, settings))
                    {
                        post.Attachments.Add(attachment);
                        wasLoaded               = true;
                    }
                }
            }

            if (authorsIterator != null && authorsIterator.Count > 0)
            {
                while (authorsIterator.MoveNext())
                {
                    string referenceId  = authorsIterator.Current.GetAttribute("ref", String.Empty);
                    if (!String.IsNullOrEmpty(referenceId))
                    {
                        post.Authors.Add(referenceId);
                        wasLoaded       = true;
                    }
                }
            }

            return wasLoaded;
        }
Exemple #6
0
        //============================================================
        //    CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the BlogMLPost class.
        /// </summary>
        public static void ClassExample()
        {
            #region BlogMLPost
            BlogMLDocument document = new BlogMLDocument();

            document.RootUrl        = new Uri("/blogs/default.aspx");
            document.GeneratedOn    = new DateTime(2006, 9, 5, 18, 22, 10);
            document.Title          = new BlogMLTextConstruct("BlogML 2.0 Example");
            document.Subtitle       = new BlogMLTextConstruct("This is some sample blog content for BlogML 2.0");

            BlogMLAuthor administrator      = new BlogMLAuthor();
            administrator.Id                = "2100";
            administrator.CreatedOn         = new DateTime(2006, 8, 10, 8, 44, 35);
            administrator.LastModifiedOn    = new DateTime(2006, 9, 4, 13, 46, 38);
            administrator.ApprovalStatus    = BlogMLApprovalStatus.Approved;
            administrator.EmailAddress      = "*****@*****.**";
            administrator.Title             = new BlogMLTextConstruct("admin");
            document.Authors.Add(administrator);

            document.ExtendedProperties.Add("CommentModeration", "Anonymous");
            document.ExtendedProperties.Add("SendTrackback", "yes");

            BlogMLCategory category1    = new BlogMLCategory();
            category1.Id                = "1018";
            category1.CreatedOn         = new DateTime(2006, 9, 5, 17, 54, 58);
            category1.LastModifiedOn    = new DateTime(2006, 9, 5, 17, 54, 58);
            category1.ApprovalStatus    = BlogMLApprovalStatus.Approved;
            category1.Description       = "Sample Category 1";
            category1.ParentId          = "0";
            category1.Title             = new BlogMLTextConstruct("Category 1");
            document.Categories.Add(category1);

            BlogMLCategory category2    = new BlogMLCategory();
            category2.Id                = "1019";
            category2.CreatedOn         = new DateTime(2006, 9, 5, 17, 54, 59);
            category2.LastModifiedOn    = new DateTime(2006, 9, 5, 17, 54, 59);
            category2.ApprovalStatus    = BlogMLApprovalStatus.Approved;
            category2.Description       = "Sample Category 2";
            category2.ParentId          = "0";
            category2.Title             = new BlogMLTextConstruct("Category 2");
            document.Categories.Add(category2);

            BlogMLCategory category3    = new BlogMLCategory();
            category3.Id                = "1020";
            category3.CreatedOn         = new DateTime(2006, 9, 5, 17, 55, 0);
            category3.LastModifiedOn    = new DateTime(2006, 9, 5, 17, 55, 0);
            category3.ApprovalStatus    = BlogMLApprovalStatus.NotApproved;
            category3.Description       = "Sample Category 3";
            category3.ParentId          = "0";
            category3.Title             = new BlogMLTextConstruct("Category 3");
            document.Categories.Add(category3);

            //  Create a blog entry
            BlogMLPost post         = new BlogMLPost();
            post.Id                 = "34";
            post.CreatedOn          = new DateTime(2006, 9, 5, 3, 19, 0);
            post.LastModifiedOn     = new DateTime(2006, 9, 5, 3, 19, 0);
            post.ApprovalStatus     = BlogMLApprovalStatus.Approved;
            post.Url                = new Uri("/blogs/archive/2006/09/05/Sample-Blog-Post.aspx");
            post.PostType           = BlogMLPostType.Normal;
            post.Views              = "0";
            post.Title              = new BlogMLTextConstruct("Sample Blog Post");
            post.Content            = new BlogMLTextConstruct("<p>This is <b>HTML encoded</b> content.&nbsp;</p>", BlogMLContentType.Html);
            post.Name               = new BlogMLTextConstruct("Sample Blog Post");

            post.Categories.Add("1018");
            post.Categories.Add("1020");

            post.Authors.Add("2100");

            BlogMLComment comment   = new BlogMLComment();
            comment.Id              = "35";
            comment.CreatedOn       = new DateTime(2006, 9, 5, 11, 36, 50);
            comment.LastModifiedOn  = new DateTime(2006, 9, 5, 11, 36, 50);
            comment.Title           = new BlogMLTextConstruct("re: Sample Blog Post");
            comment.Content         = new BlogMLTextConstruct("This is a test comment.");
            post.Comments.Add(comment);
            #endregion
        }
Exemple #7
0
        /// <summary>
        /// Adds the supplied <see cref="BlogMLPost"/> to the current instance's <see cref="Posts"/> collection.
        /// </summary>
        /// <param name="post">The <see cref="BlogMLPost"/> to be added.</param>
        /// <returns><b>true</b> if the <see cref="BlogMLPost"/> was added to the <see cref="Posts"/> collection, otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="post"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool AddPost(BlogMLPost post)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasAdded   = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(post, "post");

            //------------------------------------------------------------
            //	Add post to collection
            //------------------------------------------------------------
            ((Collection<BlogMLPost>)this.Posts).Add(post);
            wasAdded    = true;

            return wasAdded;
        }
Exemple #8
0
        /// <summary>
        /// Removes the supplied <see cref="BlogMLPost"/> from the current instance's <see cref="Posts"/> collection.
        /// </summary>
        /// <param name="post">The <see cref="BlogMLPost"/> to be removed.</param>
        /// <returns><b>true</b> if the <see cref="BlogMLPost"/> was removed from the <see cref="Posts"/> collection, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     If the <see cref="Posts"/> collection of the current instance does not contain the specified <see cref="BlogMLPost"/>, will return <b>false</b>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="post"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool RemovePost(BlogMLPost post)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasRemoved = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(post, "post");

            //------------------------------------------------------------
            //	Remove post from collection
            //------------------------------------------------------------
            if (((Collection<BlogMLPost>)this.Posts).Contains(post))
            {
                ((Collection<BlogMLPost>)this.Posts).Remove(post);
                wasRemoved  = true;
            }

            return wasRemoved;
        }