//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ BlogMLCategory value = obj as BlogMLCategory; if (value != null) { int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.ParentId, value.ParentId, StringComparison.OrdinalIgnoreCase); result = result | BlogMLUtility.CompareCommonObjects(this, value); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { if (obj == null) { return(1); } BlogMLCategory value = obj as BlogMLCategory; if (value != null) { int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.ParentId, value.ParentId, StringComparison.OrdinalIgnoreCase); result = result | BlogMLUtility.CompareCommonObjects(this, value); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
private async Task<IEnumerable<IContent>> ImportPosts(int userId, XDocument xdoc, IContent rootNode, IEnumerable<BlogMLPost> posts, BlogMLAuthor[] authors, BlogMLCategory[] categories, IDictionary<string, string> authorIdsToName, bool overwrite, string regexMatch, string regexReplace, bool publishAll) { var result = new List<IContent>(); var postType = _applicationContext.Services.ContentTypeService.GetContentType("ArticulateRichText"); if (postType == null) { throw new InvalidOperationException("Articulate is not installed properly, the ArticulateRichText doc type could not be found"); } var children = rootNode.Children().ToArray(); var archiveNode = children.FirstOrDefault(x => x.ContentType.Alias.InvariantEquals("ArticulateArchive")); if (archiveNode == null) { //create teh authors node archiveNode = _applicationContext.Services.ContentService.CreateContent( "Articles", rootNode, "ArticulateArchive"); _applicationContext.Services.ContentService.Save(archiveNode); } var allPostNodes = archiveNode.Children().ToArray(); foreach (var post in posts) { //check if one exists IContent postNode; //Use post.id if it's there if (!string.IsNullOrWhiteSpace(post.Id)) { postNode = allPostNodes.FirstOrDefault(x => x.GetValue<string>("importId") == post.Id); } else { //Use the "slug" (post name) if post.id is not there postNode = allPostNodes .FirstOrDefault(x => x.GetValue<string>("umbracoUrlName") != null && x.GetValue<string>("umbracoUrlName").InvariantStartsWith(post.Name.Content)); } //it exists and we don't wanna overwrite, skip it if (!overwrite && postNode != null) continue; //create it if it doesn't exist if (postNode == null) { postNode = _applicationContext.Services.ContentService.CreateContent( post.Title.Content, archiveNode, "ArticulateRichText"); } postNode.SetValue("publishedDate", post.CreatedOn); if (post.Excerpt != null && post.Excerpt.Content.IsNullOrWhiteSpace() == false) { postNode.SetValue("excerpt", post.Excerpt.Content); } postNode.SetValue("importId", post.Id); var content = post.Content.Content; if (post.Content.ContentType == BlogMLContentType.Base64) content = Encoding.UTF8.GetString(Convert.FromBase64String(post.Content.Content)); if (!regexMatch.IsNullOrWhiteSpace() && !regexReplace.IsNullOrWhiteSpace()) { //run the replacement content = Regex.Replace(content, regexMatch, regexReplace, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); } postNode.SetValue("richText", content); postNode.SetValue("enableComments", true); if (post.Url != null && !string.IsNullOrWhiteSpace(post.Url.OriginalString)) { //we're only going to use the last url segment var slug = post.Url.OriginalString.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); postNode.SetValue("umbracoUrlName", slug[slug.Length - 1].Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0]); } if (post.Authors.Count > 0) { var author = authors.FirstOrDefault(x => x.Id.InvariantEquals(post.Authors[0])); if (author != null) { var name = authorIdsToName[author.Id]; postNode.SetValue("author", name); } } ImportTags(xdoc, postNode, post); ImportCategories(postNode, post, categories); if (publishAll) { _applicationContext.Services.ContentService.SaveAndPublishWithStatus(postNode, userId); } else { _applicationContext.Services.ContentService.Save(postNode, userId); } //if (!publicKey.IsNullOrWhiteSpace()) //{ // await ImportComments(userId, postNode, post, publicKey); //} result.Add(postNode); } return await Task.FromResult(result); }
private void AddBlogCategories(BlogMLDocument blogMlDoc, string tagGroup) { var categories = _applicationContext.Services.TagService.GetAllContentTags(tagGroup); foreach (var category in categories) { if (category.NodeCount == 0) continue; var blogMlCategory = new BlogMLCategory(); blogMlCategory.Id = category.Id.ToString(); blogMlCategory.CreatedOn = category.CreateDate; blogMlCategory.LastModifiedOn = category.UpdateDate; blogMlCategory.ApprovalStatus = BlogMLApprovalStatus.Approved; blogMlCategory.ParentId = "0"; blogMlCategory.Title = new BlogMLTextConstruct(category.Text); blogMlDoc.Categories.Add(blogMlCategory); } }
/// <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); } } } }
//============================================================ // 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. </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 }