当前位置: 首页>>代码示例>>C#>>正文


C# BlogPost.SetContents方法代码示例

本文整理汇总了C#中OpenLiveWriter.Extensibility.BlogClient.BlogPost.SetContents方法的典型用法代码示例。如果您正苦于以下问题:C# BlogPost.SetContents方法的具体用法?C# BlogPost.SetContents怎么用?C# BlogPost.SetContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenLiveWriter.Extensibility.BlogClient.BlogPost的用法示例。


在下文中一共展示了BlogPost.SetContents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        public override BlogPost Parse(XmlElement entryNode, bool includeCategories, Uri documentUri)
        {
            BlogPost post = new BlogPost();
            AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, entryNode);

            post.Title = atomEntry.Title;
            post.Excerpt = atomEntry.Excerpt;
            post.Id = PostUriToPostId(atomEntry.EditUri);
            post.Permalink = atomEntry.Permalink;

            string content = atomEntry.ContentHtml;
            if (content.Trim() != string.Empty)
            {
                HtmlExtractor ex = new HtmlExtractor(content);
                int start, length;
                if (Options.SupportsExtendedEntries && ex.Seek("<a name=\"more\">").Success)
                {
                    start = ex.Element.Offset;
                    length = ex.Element.Length;
                    if (ex.Seek("</a>").Success)
                    {
                        post.SetContents(content.Substring(0, start), content.Substring(ex.Element.Offset + ex.Element.Length));
                    }
                    else
                    {
                        post.SetContents(content.Substring(0, start), content.Substring(start + length));
                    }
                }
                else
                {
                    post.Contents = content;
                }
            }

            post.DatePublished = atomEntry.PublishDate;
            if (Options.SupportsCategories && includeCategories)
                post.Categories = atomEntry.Categories;

            return post;
        }
开发者ID:uQr,项目名称:OpenLiveWriter,代码行数:40,代码来源:BloggerAtomClient.cs

示例2: ParseBlogPost

        private BlogPost ParseBlogPost(XmlNode postNode, bool includeCategories)
        {
            // create blog post
            BlogPost blogPost = new BlogPost();

            // get node values
            blogPost.Id = NodeText(postNode.SelectSingleNode("member[name='postid']/value"));
            if (blogPost.Id == String.Empty)
                blogPost.Id = NodeText(postNode.SelectSingleNode("member[name='page_id']/value"));

            SetPostTitleFromXmlValue(blogPost, NodeText(postNode.SelectSingleNode("member[name='title']/value")));

            // attempt to discover the permalink
            blogPost.Permalink = NodeText(postNode.SelectSingleNode("member[name='permaLink']/value"));
            if (blogPost.Permalink == String.Empty)
                blogPost.Permalink = NodeText(postNode.SelectSingleNode("member[name='permalink']/value"));
            if (blogPost.Permalink == String.Empty)
                blogPost.Permalink = NodeText(postNode.SelectSingleNode("member[name='link']/value"));

            // contents and extended contents
            string mainContents = NodeText(postNode.SelectSingleNode("member[name='description']/value"));
            string extendedContents = NodeText(postNode.SelectSingleNode("member[name='mt_text_more']/value"));
            blogPost.SetContents(mainContents, extendedContents);

            // date published
            XmlNode dateCreatedNode = postNode.SelectSingleNode("member[name='date_created_gmt']/value");
            if (dateCreatedNode == null)
                dateCreatedNode = postNode.SelectSingleNode("member[name='dateCreated']/value");
            blogPost.DatePublished = ParseBlogDate(dateCreatedNode);

            // extract comment field
            if (Options.SupportsCommentPolicy)
            {
                string commentPolicy = NodeText(postNode.SelectSingleNode("member[name='mt_allow_comments']/value"));
                if (commentPolicy != String.Empty)
                {
                    switch (commentPolicy)
                    {
                        case "0":
                            blogPost.CommentPolicy = BlogCommentPolicy.None;
                            break;
                        case "1":
                            blogPost.CommentPolicy = BlogCommentPolicy.Open;
                            break;
                        case "2":
                            blogPost.CommentPolicy = BlogCommentPolicy.Closed;
                            break;
                        default:
                            Trace.Fail("Unexpected value for mt_allow_comments: " + commentPolicy);
                            break;
                    }
                }
            }

            // extract trackback field
            if (Options.SupportsPingPolicy)
            {
                string allowTrackbacks = NodeText(postNode.SelectSingleNode("member[name='mt_allow_pings']/value"));
                if (allowTrackbacks != String.Empty)
                    blogPost.TrackbackPolicy = (allowTrackbacks == "1") ? BlogTrackbackPolicy.Allow : BlogTrackbackPolicy.Deny;
            }

            // extract keywords field
            if (Options.SupportsKeywords)
            {
                string keywords = NodeText(postNode.SelectSingleNode("member[name='mt_keywords']/value"));
                blogPost.Keywords = HtmlUtils.UnEscapeEntities(keywords, HtmlUtils.UnEscapeMode.Default);
            }

            // extract excerpt field
            if (Options.SupportsExcerpt)
            {
                blogPost.Excerpt = NodeText(postNode.SelectSingleNode("member[name='mt_excerpt']/value"));
            }

            // extract ping url array
            if (Options.SupportsTrackbacks)
            {

                XmlNode pingUrlsNode = postNode.SelectSingleNode("member[name='mt_tb_ping_urls']/value");
                if (pingUrlsNode != null)
                {
                    ArrayList sentPingUrls = new ArrayList();
                    if (Options.TrackbackDelimiter == TrackbackDelimiter.ArrayElement)
                    {
                        XmlNodeList pingUrlNodes = pingUrlsNode.SelectNodes("array/data/value");
                        foreach (XmlNode node in pingUrlNodes)
                            sentPingUrls.Add(node.InnerText.Trim());
                    }
                    else
                    {
                        string delimiter = null;
                        if (Options.TrackbackDelimiter == TrackbackDelimiter.Space)
                            delimiter = " ";
                        else if (Options.TrackbackDelimiter == TrackbackDelimiter.Comma)
                            delimiter = ",";
                        sentPingUrls.AddRange(StringHelper.Split(pingUrlsNode.InnerText, delimiter));
                    }

                    blogPost.PingUrlsSent = sentPingUrls.ToArray(typeof(string)) as string[];
//.........这里部分代码省略.........
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:101,代码来源:MetaweblogClient.cs

示例3: ParsePostContent

        private void ParsePostContent(XmlNode xmlNode, BlogPost blogPost)
        {
            // get raw content (decode base64 if necessary)
            string content;
            XmlNode base64Node = xmlNode.SelectSingleNode("base64");
            if (base64Node != null)
            {
                byte[] contentBytes = Convert.FromBase64String(base64Node.InnerText);
                content = _utf8EncodingNoBOM.GetString(contentBytes);
            }
            else // no base64 encoding, just read text
            {
                content = xmlNode.InnerText;
            }

            // parse out the title and contents of the post
            HtmlExtractor ex = new HtmlExtractor(content);
            if (ex.Seek("<title>").Success)
            {
                SetPostTitleFromXmlValue(blogPost, ex.CollectTextUntil("title"));
                content = content.Substring(ex.Parser.Position).TrimStart('\r', '\n');

            }

            if (content.Trim() != string.Empty)
            {
                HtmlExtractor ex2 = new HtmlExtractor(content);
                if (Options.SupportsExtendedEntries && ex2.Seek("<lj-cut>").Success)
                    blogPost.SetContents(content.Substring(0, ex2.Element.Offset), content.Substring(ex2.Element.Offset + ex2.Element.Length));
                else
                    blogPost.Contents = content;
            }

        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:34,代码来源:LiveJournalClient.cs


注:本文中的OpenLiveWriter.Extensibility.BlogClient.BlogPost.SetContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。