Exemple #1
0
        /// <summary>
        /// Get all posts from the WXR.
        /// </summary>
        /// <param name="blog">
        /// The <see cref="WPBlogML.BlogML.Blog"/> being constructed
        /// </param>
        /// <param name="channel">
        /// The RSS channel in the WXR feed
        /// </param>
        private void GetPosts(Blog blog, XElement channel)
        {
            var posts =
                from item in channel.Elements("item")
                where item.Element(Util.wpNamespace + "status").Value == "publish"
                select item;

            foreach (var item in posts)
            {
                var post = new Post(item);

                // We need to get the thumbnail image seperately, as we need the attachment items from the blog.
                var attachment = GetThumbnailAttachment(item, channel);
                if (attachment != null)
                {
                    post.Attachments.AttachmentList.Add(attachment);
                }

                // We need to get the author reference separately, as we need the AuthorList from the blog.
                var author = new AuthorReference();
                author.ID = GetAuthorReference(blog, ((XCData)item.Element(Util.dcNamespace + "creator").FirstNode).Value);

                post.Authors.AuthorReferenceList.Add(author);

                blog.Posts.PostList.Add(post);
            }
        }
Exemple #2
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            ((Fhir.R4.Models.Element) this).SerializeJson(writer, options, false);

            if (AuthorReference != null)
            {
                writer.WritePropertyName("authorReference");
                AuthorReference.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(AuthorString))
            {
                writer.WriteString("authorString", (string)AuthorString !);
            }

            if (_AuthorString != null)
            {
                writer.WritePropertyName("_authorString");
                _AuthorString.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Time))
            {
                writer.WriteString("time", (string)Time !);
            }

            if (_Time != null)
            {
                writer.WritePropertyName("_time");
                _Time.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Text))
            {
                writer.WriteString("text", (string)Text !);
            }

            if (_Text != null)
            {
                writer.WritePropertyName("_text");
                _Text.SerializeJson(writer, options);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemple #3
0
        private void GetPosts(Blog blog, WordpressNamespaces namespaces, XElement channel)
        {
            IEnumerable <XElement> posts =
                from item in channel.Elements("item")
                where item.WordpressElement(namespaces, "status").Value == "publish"
                select item;

            // NGM Might want update urls within content to stop redirects?

            foreach (XElement item in posts)
            {
                Post post = InternalSchemaAssemblers.AssemblePost(namespaces, item);

                // We need to get the author reference separately, as we need the AuthorList from the blog.
                AuthorReference author = new AuthorReference();
                author.ID = GetAuthorReference(blog,
                                               ((XText)item.Element(namespaces.DcNamespace + "creator").FirstNode).Value);
                post.Authors.AuthorReferenceList.Add(author);

                blog.Posts.PostList.Add(post);
            }
        }
Exemple #4
0
        private void GetPosts(Blog blog, BlogMLBlog blogMLBlog)
        {
            foreach (var blogMLPost in blogMLBlog.Posts)
            {
                Post post = new Post();
                post.ID = blogMLPost.ID;

                post.HasExcerpt = blogMLPost.HasExcerpt;
                if (post.HasExcerpt)
                {
                    post.Excerpt = new Content {
                        Type = blogMLPost.Excerpt.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Excerpt.Text
                    }
                }
                ;

                foreach (BlogMLAttachment blogMLAttachment in blogMLPost.Attachments)
                {
                    Attachment attachment = new Attachment();
                    attachment.Embedded    = blogMLAttachment.Embedded;
                    attachment.Value       = blogMLAttachment.Data;
                    attachment.MimeType    = blogMLAttachment.MimeType;
                    attachment.ExternalURI = blogMLAttachment.Path;
                    attachment.URL         = blogMLAttachment.Url;
                    post.Attachments.AttachmentList.Add(attachment);
                }

                foreach (BlogMLAuthorReference blogMLAuthor in blogMLPost.Authors)
                {
                    AuthorReference authorReference = new AuthorReference();
                    authorReference.ID = blogMLAuthor.Ref;
                    post.Authors.AuthorReferenceList.Add(authorReference);
                }

                foreach (BlogMLCategoryReference blogMLCategory in blogMLPost.Categories)
                {
                    CategoryReference categoryReference = new CategoryReference();
                    categoryReference.ID = blogMLCategory.Ref;
                    post.Categories.CategoryReferenceList.Add(categoryReference);
                }

                foreach (BlogMLComment blogMLComment in blogMLPost.Comments)
                {
                    Comment comment = new Comment();
                    comment.ID       = blogMLComment.ID;
                    comment.Approved = blogMLComment.Approved;
                    comment.Content  = new Content {
                        Type = blogMLComment.Content.ContentType.ToString().ToLowerInvariant(), Value = blogMLComment.Content.Text
                    };
                    comment.DateCreated  = blogMLComment.DateCreated;
                    comment.DateModified = blogMLComment.DateModified;
                    comment.Title        = blogMLComment.Title;
                    comment.UserEmail    = blogMLComment.UserEMail;
                    comment.UserName     = blogMLComment.UserName;
                    comment.UserURL      = blogMLComment.UserUrl;
                    post.Comments.CommentList.Add(comment);
                }

                // hmm do I care?
                //foreach (BlogMLTrackback blogMLTrackback in blogMLPost.Trackbacks) {
                //    Trackback trackback = new Trackback();
                //    trackback.ID = blogMLTrackback.ID;
                //    trackback.Approved = blogMLTrackback.Approved;
                //    trackback.DateCreated = blogMLTrackback.DateCreated;
                //    trackback.DateModified = blogMLTrackback.DateModified;
                //    trackback.Title = blogMLTrackback.Title;
                //    trackback.Url = blogMLTrackback.Url;
                //}

                post.Approved = blogMLPost.Approved;

                post.Content = new Content {
                    Type = blogMLPost.Content.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Content.Text
                };

                post.DateCreated  = blogMLPost.DateCreated;
                post.DateModified = blogMLPost.DateModified;
                post.HasExcerpt   = blogMLPost.HasExcerpt;

                if (post.HasExcerpt)
                {
                    post.Excerpt = new Content {
                        Type = blogMLPost.Excerpt.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Excerpt.Text
                    }
                }
                ;

                post.PostName = new Title {
                    Type = Content.TypeHTML, Value = blogMLPost.PostName
                };
                post.PostUrl = blogMLPost.PostUrl;
                post.Title   = blogMLPost.Title;
                post.Type    = blogMLPost.PostType.ToString();
                post.Views   = blogMLPost.Views;

                blog.Posts.PostList.Add(post);
            }
        }