Inheritance: BlogMLNode
示例#1
0
 public static BlogMLBlog CreateBlogInstance(string title, string subtitle, string rootUrl, string author, string email, DateTime dateCreated)
 {
     BlogMLBlog blog = new BlogMLBlog();
     BlogMLAuthor blogAuthor = new BlogMLAuthor();
     blogAuthor.Title = author;
     blogAuthor.Email = email;
     blog.Authors.Add(blogAuthor);
     blog.Title = title;
     blog.SubTitle = subtitle;
     blog.RootUrl = rootUrl;
     blog.DateCreated = dateCreated;
     return blog;
 }
示例#2
0
 private void PopulateAuthors(Blog blog, BlogMLBlog bmlBlog)
 {
     var bmlAuthor = new BlogMLAuthor
     {
         ID = blog.Id.ToString(CultureInfo.InvariantCulture),
         Title = blog.Author,
         Approved = true,
         Email = blog.Email,
         DateCreated = blog.DateModifiedUtc,
         DateModified = blog.DateModifiedUtc
     };
     bmlBlog.Authors.Add(bmlAuthor);
 }
示例#3
0
        /// <summary>
        /// Returns the information about the specified blog
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        public override BlogMLBlog GetBlog(string blogId)
        {
            int blogIdentifier;
            if (int.TryParse(blogId, out blogIdentifier))
            {
                BlogInfo blog = BlogInfo.GetBlogById(blogIdentifier);
                BlogMLBlog bmlBlog = new BlogMLBlog();
                bmlBlog.Title = blog.Title;
                bmlBlog.SubTitle = blog.SubTitle;
                bmlBlog.RootUrl = blog.RootUrl.ToString();
                bmlBlog.DateCreated = blog.TimeZone.Now;

                // TODO: in Subtext 2.0 we need to account for multiple authors.
                BlogMLAuthor bmlAuthor = new BlogMLAuthor();
                bmlAuthor.ID = blog.Id.ToString();
                bmlAuthor.Title = blog.Author;
                bmlAuthor.Approved = true;
                bmlAuthor.Email = blog.Email;
                bmlAuthor.DateCreated = blog.LastUpdated;
                bmlAuthor.DateModified = blog.LastUpdated;
                bmlBlog.Authors.Add(bmlAuthor);

                // Add Extended Properties
                Pair<string, string> bmlExtProp = new Pair<string, string>();
                bmlExtProp.Key = BlogMLBlogExtendedProperties.CommentModeration;
                bmlExtProp.Value = blog.ModerationEnabled
                                       ? CommentModerationTypes.Enabled.ToString()
                                       : CommentModerationTypes.Disabled.ToString();
                bmlBlog.ExtendedProperties.Add(bmlExtProp);

                /* TODO: The blog.TrackbasksEnabled determines if Subtext will ACCEPT and SEND trackbacks.
                 * Perhaps we should separate the two out?
                 * For now, we'll assume that if a BlogML blog allows sending, it will also
                 * allow receiving track/pingbacks.
                 */
                bmlExtProp.Key = BlogMLBlogExtendedProperties.EnableSendingTrackbacks;
                bmlExtProp.Value = blog.TrackbacksEnabled
                                       ? SendTrackbackTypes.Yes.ToString()
                                       : SendTrackbackTypes.No.ToString();

                return bmlBlog;
            }
            return null;
        }
        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;
        }
    private void AddEntry(AtomEntry entry, BlogMLBlog blog)
    {
      BlogMLPost post = new BlogMLPost()
      {
        Approved = entry.Visible,
        Content = new BlogMLContent() { Text = entry.Content.ToString() },
        DateCreated = entry.Published.HasValue ? entry.Published.Value.DateTime : entry.Updated.DateTime,
        DateModified = entry.Updated.DateTime,
        HasExcerpt = entry.Summary != null,
        Excerpt = entry.Summary != null ? new BlogMLContent() { Text = entry.Summary.Text } : null,
        ID = entry.Id.ToString(),
        PostName = entry.Id.EntryPath,
        PostType = BlogML.BlogPostTypes.Normal,
        PostUrl = entry.LocationWeb.ToString(),
        Title = entry.Title.ToString()
      };

      foreach (AtomPerson author in entry.Authors)
      {
        BlogMLAuthor a = new BlogMLAuthor()
        {
          Approved = true,
          DateCreated = DateTime.UtcNow,
          DateModified = DateTime.UtcNow,
          Email = author.Email,
          ID = author.Id,
          Title = author.Name
        };

        if (blog.Authors.Where(x => x.ID == a.ID).Count() == 0) blog.Authors.Add(a);
        post.Authors.Add(new BlogMLAuthorReference() { Ref = a.ID });
      }

      foreach (AtomCategory cat in entry.Categories)
      {
        BlogMLCategory c = new BlogMLCategory()
        {
          ID = cat.Term,
          Approved = false,
          DateCreated = DateTime.UtcNow,
          DateModified = DateTime.UtcNow,
          Title = cat.ToString()
        };
        if (blog.Categories.Where(x => x.ID == c.ID).Count() == 0) blog.Categories.Add(c);
        post.Categories.Add(new BlogMLCategoryReference() { Ref = c.ID });
      }


      IPagedList<AtomEntry> anns = null;
      int page = 0;
      do
      {
        anns = AtomPubService.GetEntries(new EntryCriteria() { EntryId = entry.Id, Annotations = true, Authorized = true, Deep = true },
        page, 100); page++;
        foreach (AtomEntry ann in anns)
        {
          try
          {
            LogService.Info("Processing annotation with ID='{0}'", ann.Id);
            AddAnnotation(ann, post, blog);
          }
          catch (Exception ex)
          {
            LogService.Error(ex);
          }
        }
      } while (anns.PageIndex < anns.PageCount);

      //TODO: attachments
      //post.Attachments.Add(new BlogMLAttachment()
      //{

      //});

      blog.Posts.Add(post);
    }