/// <summary>
        /// metaWeblog.getRecentPosts method
        /// </summary>
        /// <param name="blogId">
        /// always 1000 in BlogEngine since it is a singlar blog instance
        /// </param>
        /// <param name="userName">
        /// login username
        /// </param>
        /// <param name="password">
        /// login password
        /// </param>
        /// <param name="numberOfPosts">
        /// number of posts to return
        /// </param>
        /// <returns>
        /// array of post structs
        /// </returns>
        internal async Task <List <MWAPost> > GetRecentPosts(string blogId, string userName, string password, int numberOfPosts)
        {
            var currentUser = await GetVerifyUserAsync(userName, password);

            //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.Posts))
            //{
            //    throw new MetaWeblogException("11", "User authentication failed");
            //}

            var sendPosts = new List <MWAPost>();
            var posts     = _postManager.GetQueryable().Where(t => !t.IsDraft).Take(numberOfPosts).ToList();

            foreach (var post in posts)
            {
                var tempPost = new MWAPost
                {
                    postID        = post.Id.ToString(),
                    postDate      = post.PublishedTime,
                    title         = post.Title,
                    description   = post.Content,
                    link          = Url.RouteUrl(RouteNames.Post, new { id = post.Id }, Request.Scheme),
                    slug          = post.Slug,
                    excerpt       = post.Description,
                    commentPolicy = post.EnableComment ? string.Empty : "0",
                    publish       = !post.IsDraft,
                };

                tempPost.categories = post.Categories.Select(t => t.Category.Name).ToList();

                tempPost.tags = post.Tags.Select(t => t.Tags.Name).ToList();

                sendPosts.Add(tempPost);
            }

            return(sendPosts);
        }
Exemplo n.º 2
0
        /// <summary>
        /// metaWeblog.newPost
        /// </summary>
        /// <param name="blogID">always 1000 in BlogEngine since it is a singlar blog instance</param>
        /// <param name="userName">login username</param>
        /// <param name="password">login password</param>
        /// <param name="sentPost">struct with post details</param>
        /// <param name="publish">mark as published?</param>
        /// <returns>postID as string</returns>
        internal string NewPost(string blogID, string userName, string password, MWAPost sentPost, bool publish)
        {
            ValidateRequest(userName, password);

            return(NewOrUpdatePost(blogID, "", userName, password, sentPost, publish, OperateType.Insert).ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加或修改文章
        /// </summary>
        /// <param name="blogID"></param>
        /// <param name="postID"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="sentPost"></param>
        /// <param name="publish"></param>
        /// <param name="operate"></param>
        /// <returns></returns>
        private int NewOrUpdatePost(string blogID, string postID, string userName, string password, MWAPost sentPost, bool publish, OperateType operate)
        {
            ValidateRequest(userName, password);

            PostInfo post = new PostInfo();

            if (operate == OperateType.Update)
            {
                post = PostManager.GetPost(StringHelper.StrToInt(postID, 0));
            }
            else
            {
                post.CommentCount = 0;
                post.ViewCount    = 0;
                post.CreateDate   = DateTime.Now;

                UserInfo user = UserManager.GetUser(userName);
                if (user != null)
                {
                    post.UserId = user.UserId;
                }
            }

            post.Title   = StringHelper.HtmlEncode(sentPost.title);
            post.Content = sentPost.description;
            post.Status  = publish == true ? 1 : 0;
            post.Slug    = PageUtils.FilterSlug(sentPost.slug, "post", true);
            post.Summary = sentPost.excerpt;

            post.UrlFormat  = (int)PostUrlFormat.Default;
            post.Template   = string.Empty;
            post.Recommend  = 0;
            post.TopStatus  = 0;
            post.HideStatus = 0;
            post.UpdateDate = DateTime.Now;

            if (sentPost.commentPolicy != "")
            {
                if (sentPost.commentPolicy == "1")
                {
                    post.CommentStatus = 1;
                }
                else
                {
                    post.CommentStatus = 0;
                }
            }


            foreach (string item in sentPost.categories)
            {
                CategoryInfo cat;
                if (LookupCategoryGuidByName(item, out cat))
                {
                    post.CategoryId = cat.CategoryId;
                }
                else
                {
                    CategoryInfo newcat = new CategoryInfo();
                    newcat.Count        = 0;
                    newcat.CreateDate   = DateTime.Now;
                    newcat.Description  = "由离线工具创建";
                    newcat.Displayorder = 1000;
                    newcat.Name         = StringHelper.HtmlEncode(item);
                    newcat.Slug         = PageUtils.FilterSlug(item, "cate", false);

                    newcat.CategoryId = CategoryManager.InsertCategory(newcat);
                    post.CategoryId   = newcat.CategoryId;
                }
            }
            post.Tag = GetTagIdList(sentPost.tags);

            if (operate == OperateType.Update)
            {
                PostManager.UpdatePost(post);
            }
            else
            {
                post.PostId = PostManager.InsertPost(post);

                //    SendEmail(p);
            }

            return(post.PostId);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a Metaweblog Post object from the XML struct
        /// </summary>
        /// <param name="node">XML contains a Metaweblog Post Struct</param>
        /// <returns>Metaweblog Post Struct Obejct</returns>
        private MWAPost GetPost(XmlNode node)
        {
            MWAPost       temp = new MWAPost();
            List <string> cats = new List <string>();
            List <string> tags = new List <string>();

            // Require Title and Description
            try
            {
                temp.title       = node.SelectSingleNode("value/struct/member[name='title']").LastChild.InnerText;
                temp.description = node.SelectSingleNode("value/struct/member[name='description']").LastChild.InnerText;
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("05", "Post Struct Element, Title or Description,  not Sent. (" + ex.Message + ")");
            }
            if (node.SelectSingleNode("value/struct/member[name='link']") == null)
            {
                temp.link = "";
            }
            else
            {
                temp.link = node.SelectSingleNode("value/struct/member[name='link']").LastChild.InnerText;
            }

            if (node.SelectSingleNode("value/struct/member[name='mt_allow_comments']") == null)
            {
                temp.commentPolicy = "";
            }
            else
            {
                temp.commentPolicy = node.SelectSingleNode("value/struct/member[name='mt_allow_comments']").LastChild.InnerText;
            }

            if (node.SelectSingleNode("value/struct/member[name='mt_excerpt']") == null)
            {
                temp.excerpt = "";
            }
            else
            {
                temp.excerpt = node.SelectSingleNode("value/struct/member[name='mt_excerpt']").LastChild.InnerText;
            }

            if (node.SelectSingleNode("value/struct/member[name='wp_slug']") == null)
            {
                temp.slug = "";
            }
            else
            {
                temp.slug = node.SelectSingleNode("value/struct/member[name='wp_slug']").LastChild.InnerText;
            }

            if (node.SelectSingleNode("value/struct/member[name='wp_author_id']") == null)
            {
                temp.author = "";
            }
            else
            {
                temp.author = node.SelectSingleNode("value/struct/member[name='wp_author_id']").LastChild.InnerText;
            }

            if (node.SelectSingleNode("value/struct/member[name='categories']") != null)
            {
                XmlNode categoryArray = node.SelectSingleNode("value/struct/member[name='categories']").LastChild;
                foreach (XmlNode catnode in categoryArray.SelectNodes("array/data/value/string"))
                {
                    cats.Add(catnode.InnerText);
                }
            }
            temp.categories = cats;

            // postDate has a few different names to worry about
            if (node.SelectSingleNode("value/struct/member[name='dateCreated']") != null)
            {
                try
                {
                    string tempDate = node.SelectSingleNode("value/struct/member[name='dateCreated']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }
            else if (node.SelectSingleNode("value/struct/member[name='pubDate']") != null)
            {
                try
                {
                    string tempPubDate = node.SelectSingleNode("value/struct/member[name='pubDate']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempPubDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }

            // WLW tags implementation using mt_keywords
            if (node.SelectSingleNode("value/struct/member[name='mt_keywords']") != null)
            {
                string tagsList = node.SelectSingleNode("value/struct/member[name='mt_keywords']").LastChild.InnerText;
                foreach (string item in tagsList.Split(','))
                {
                    if (string.IsNullOrEmpty(tags.Find(delegate(string t) { return(t.Equals(item.Trim(), StringComparison.OrdinalIgnoreCase)); })))
                    {
                        tags.Add(item.Trim());
                    }
                }
            }
            temp.tags = tags;

            return(temp);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads object properties with contents of passed xml
        /// </summary>
        /// <param name="xml">xml doc with methodname and parameters</param>
        private void LoadXMLRequest(string xml)
        {
            XmlDocument request = new XmlDocument();

            try
            {
                if (!(xml.StartsWith("<?xml") || xml.StartsWith("<method")))
                {
                    xml = xml.Substring(xml.IndexOf("<?xml"));
                }
                request.LoadXml(xml);
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("01", "Invalid XMLRPC Request. (" + ex.Message + ")");
            }

            // Method name is always first
            _methodName = request.DocumentElement.ChildNodes[0].InnerText;

            // Parameters are next (and last)
            _inputParams = new List <XmlNode>();
            foreach (XmlNode node in request.SelectNodes("/methodCall/params/param"))
            {
                _inputParams.Add(node);
            }

            // Determine what params are what by method name
            switch (_methodName)
            {
            case "metaWeblog.newPost":
                _blogID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                _post     = GetPost(_inputParams[3]);
                if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                {
                    _publish = false;
                }
                else
                {
                    _publish = true;
                }
                break;

            case "metaWeblog.editPost":
                _postID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                _post     = GetPost(_inputParams[3]);
                if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                {
                    _publish = false;
                }
                else
                {
                    _publish = true;
                }
                break;

            case "metaWeblog.getPost":
                _postID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                break;

            case "metaWeblog.newMediaObject":
                _blogID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                _media    = GetMediaObject(_inputParams[3]);
                break;

            case "metaWeblog.getCategories":
            case "wp.getAuthors":
            case "wp.getPageList":
            case "wp.getPages":
            case "wp.getTags":
                _blogID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                break;

            case "metaWeblog.getRecentPosts":
                _blogID        = _inputParams[0].InnerText;
                _userName      = _inputParams[1].InnerText;
                _password      = _inputParams[2].InnerText;
                _numberOfPosts = Int32.Parse(_inputParams[3].InnerText, CultureInfo.InvariantCulture);
                break;

            case "blogger.getUsersBlogs":
            case "metaWeblog.getUsersBlogs":
                _appKey   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                break;

            case "blogger.deletePost":
                _appKey   = _inputParams[0].InnerText;
                _postID   = _inputParams[1].InnerText;
                _userName = _inputParams[2].InnerText;
                _password = _inputParams[3].InnerText;
                if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                {
                    _publish = false;
                }
                else
                {
                    _publish = true;
                }
                break;

            case "blogger.getUserInfo":
                _appKey   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                break;

            case "wp.newPage":
                _blogID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                _page     = GetPage(_inputParams[3]);
                if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                {
                    _publish = false;
                }
                else
                {
                    _publish = true;
                }
                break;

            case "wp.getPage":
                _blogID   = _inputParams[0].InnerText;
                _pageID   = _inputParams[1].InnerText;
                _userName = _inputParams[2].InnerText;
                _password = _inputParams[3].InnerText;
                break;

            case "wp.editPage":
                _blogID   = _inputParams[0].InnerText;
                _pageID   = _inputParams[1].InnerText;
                _userName = _inputParams[2].InnerText;
                _password = _inputParams[3].InnerText;
                _page     = GetPage(_inputParams[4]);
                if (_inputParams[5].InnerText == "0" || _inputParams[5].InnerText == "false")
                {
                    _publish = false;
                }
                else
                {
                    _publish = true;
                }
                break;

            case "wp.deletePage":
                _blogID   = _inputParams[0].InnerText;
                _userName = _inputParams[1].InnerText;
                _password = _inputParams[2].InnerText;
                _pageID   = _inputParams[3].InnerText;
                break;

            default:
                throw new MetaWeblogException("02", "未知方法. (" + _methodName + ")");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加或修改文章
        /// </summary>
        /// <param name="blogID"></param>
        /// <param name="postID"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="sentPost"></param>
        /// <param name="publish"></param>
        /// <param name="operate"></param>
        /// <returns></returns>
        private int NewOrUpdatePost(string blogID, string postID, string userName, string password, MWAPost sentPost, bool publish, OperateType operate)
        {
            ValidateRequest(userName, password);

            PostInfo    post         = new PostInfo();
            PostService _postService = new PostService();

            if (operate == OperateType.Update)
            {
                post = new PostService().GetPost(Jqpress.Framework.Utils.TypeConverter.StrToInt(postID, 0));
            }
            else
            {
                post.CommentCount = 0;
                post.ViewCount    = 0;
                post.PostTime     = DateTime.Now;

                UserInfo user = (new UserService()).GetUser(userName);
                if (user != null)
                {
                    post.UserId = user.UserId;
                }
            }

            post.Title       = Jqpress.Framework.Web.HttpHelper.HtmlEncode(sentPost.title);
            post.PostContent = sentPost.description;
            post.Status      = publish == true ? 1 : 0;
            post.PageName    = Jqpress.Framework.Utils.StringHelper.FilterPageName(sentPost.pagename, "post", true);
            post.Summary     = sentPost.excerpt;

            post.UrlFormat  = (int)PostUrlFormat.Default;
            post.Template   = string.Empty;
            post.Recommend  = 0;
            post.TopStatus  = 0;
            post.PostStatus = 0;
            post.UpdateTime = DateTime.Now;

            if (sentPost.commentPolicy != "")
            {
                if (sentPost.commentPolicy == "1")
                {
                    post.CommentStatus = 1;
                }
                else
                {
                    post.CommentStatus = 0;
                }
            }


            foreach (string item in sentPost.categories)
            {
                CategoryInfo cat;
                if (LookupCategoryGuidByName(item, out cat))
                {
                    post.CategoryId = cat.CategoryId;
                }
                else
                {
                    CategoryInfo newcat = new CategoryInfo();
                    newcat.PostCount   = 0;
                    newcat.CreateTime  = DateTime.Now;
                    newcat.Description = "由离线工具创建";
                    newcat.SortNum     = 1000;
                    newcat.CateName    = Jqpress.Framework.Web.HttpHelper.HtmlEncode(item);
                    newcat.PageName    = Jqpress.Framework.Utils.StringHelper.FilterPageName(item, "cate", false);

                    newcat.CategoryId = new CategoryService().InsertCategory(newcat);
                    post.CategoryId   = newcat.CategoryId;
                }
            }
            post.Tag = GetTagIdList(sentPost.tags);

            if (operate == OperateType.Update)
            {
                new PostService().UpdatePost(post);
            }
            else
            {
                post.PostId = new PostService().InsertPost(post);

                //    SendEmail(p);
            }

            return(post.PostId);
        }
        /// <summary>
        /// metaWeblog.newPost method
        /// </summary>
        /// <param name="blogId">
        /// always 1000 in BlogEngine since it is a singlar blog instance
        /// </param>
        /// <param name="userName">
        /// login username
        /// </param>
        /// <param name="password">
        /// login password
        /// </param>
        /// <param name="sentPost">
        /// struct with post details
        /// </param>
        /// <param name="publish">
        /// mark as published?
        /// </param>
        /// <returns>
        /// postID as string
        /// </returns>
        internal async Task <string> NewPost(string blogId, string userName, string password, MWAPost sentPost, bool publish)
        {
            var currentUser = await GetVerifyUserAsync(userName, password);

            //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.PostCreate))
            //{
            //    throw new MetaWeblogException("11", "User authentication failed");
            //}

            var post = new Post
            {
                UserId      = currentUser.Id,
                Title       = sentPost.title,
                Content     = sentPost.description,
                IsDraft     = !publish,
                Slug        = sentPost.slug,
                Description = sentPost.excerpt,
            };

            string authorName = String.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author;

            var user = await _userManager.FindByEmailAsync(authorName);

            if (user != null)
            {
                post.UserId = user.Id;
            }

            if (sentPost.commentPolicy != string.Empty)
            {
                post.EnableComment = sentPost.commentPolicy == "1";
            }

            post.Categories.Clear();
            foreach (var item in sentPost.categories.Where(c => c != null && c.Trim() != string.Empty))
            {
                Category cat;
                if (LookupCategoryGuidByName(item, out cat))
                {
                    post.Categories.Add(new PostCategory()
                    {
                        CategoryId = cat.Id, PostId = post.Id
                    });
                }
                else
                {
                    // Allowing new categories to be added.  (This breaks spec, but is supported via WLW)
                    var newcat = new Category()
                    {
                        Name         = item,
                        DisplayOrder = 1,
                    };

                    post.Categories.Add(new PostCategory()
                    {
                        Category = newcat, PostId = post.Id
                    });
                }
            }

            post.Tags.Clear();
            foreach (var item in sentPost.tags.Where(item => item != null && item.Trim() != string.Empty))
            {
                var tag = await _tagsManager.CreateOrUpdateAsync(item);

                post.Tags.Add(new PostTags()
                {
                    TagsId = tag.Id, PostId = post.Id
                });
            }

            post.CreationTime = sentPost.postDate == new DateTime() ? DateTime.Now : sentPost.postDate;

            await _postManager.CreateAsync(post);

            return(post.Id.ToString());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads object properties with contents of passed xml
        /// </summary>
        /// <param name="xml">xml doc with methodname and parameters</param>
        private void LoadXMLRequest(string xml)
        {
            XmlDocument request = new XmlDocument();
            try
            {
                if (!(xml.StartsWith("<?xml") || xml.StartsWith("<method")))
                {
                    xml = xml.Substring(xml.IndexOf("<?xml"));
                }
                request.LoadXml(xml);
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("01", "Invalid XMLRPC Request. (" + ex.Message + ")");
            }

            // Method name is always first
            _methodName = request.DocumentElement.ChildNodes[0].InnerText;

            // Parameters are next (and last)
            _inputParams = new List<XmlNode>();
            foreach (XmlNode node in request.SelectNodes("/methodCall/params/param"))
            {
                _inputParams.Add(node);
            }

            // Determine what params are what by method name
            switch (_methodName)
            {
                case "metaWeblog.newPost":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _post = GetPost(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "metaWeblog.editPost":
                    _postID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _post = GetPost(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "metaWeblog.getPost":
                    _postID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "metaWeblog.newMediaObject":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _media = GetMediaObject(_inputParams[3]);
                    break;
                case "metaWeblog.getCategories":
                case "wp.getAuthors":
                case "wp.getPageList":
                case "wp.getPages":
                case "wp.getTags":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "metaWeblog.getRecentPosts":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _numberOfPosts = Int32.Parse(_inputParams[3].InnerText, CultureInfo.InvariantCulture);
                    break;
                case "blogger.getUsersBlogs":
                case "metaWeblog.getUsersBlogs":
                    _appKey = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "blogger.deletePost":
                    _appKey = _inputParams[0].InnerText;
                    _postID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "blogger.getUserInfo":
                    _appKey = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "wp.newPage":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _page = GetPage(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "wp.getPage":
                    _blogID = _inputParams[0].InnerText;
                    _pageID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    break;
                case "wp.editPage":
                    _blogID = _inputParams[0].InnerText;
                    _pageID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    _page = GetPage(_inputParams[4]);
                    if (_inputParams[5].InnerText == "0" || _inputParams[5].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "wp.deletePage":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _pageID = _inputParams[3].InnerText;
                    break;
                default:
                    throw new MetaWeblogException("02", "未知方法. (" + _methodName + ")");

            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a Metaweblog Post object from the XML struct
        /// </summary>
        /// <param name="node">XML contains a Metaweblog Post Struct</param>
        /// <returns>Metaweblog Post Struct Obejct</returns>
        private MWAPost GetPost(XmlNode node)
        {
            MWAPost temp = new MWAPost();
            List<string> cats = new List<string>();
            List<string> tags = new List<string>();

            // Require Title and Description
            try
            {
                temp.title = node.SelectSingleNode("value/struct/member[name='title']").LastChild.InnerText;
                temp.description = node.SelectSingleNode("value/struct/member[name='description']").LastChild.InnerText;
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("05", "Post Struct Element, Title or Description,  not Sent. (" + ex.Message + ")");
            }
            if (node.SelectSingleNode("value/struct/member[name='link']") == null)
                temp.link = "";
            else
                temp.link = node.SelectSingleNode("value/struct/member[name='link']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='mt_allow_comments']") == null)
                temp.commentPolicy = "";
            else
                temp.commentPolicy = node.SelectSingleNode("value/struct/member[name='mt_allow_comments']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='mt_excerpt']") == null)
                temp.excerpt = "";
            else
                temp.excerpt = node.SelectSingleNode("value/struct/member[name='mt_excerpt']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='wp_slug']") == null)
                temp.slug = "";
            else
                temp.slug = node.SelectSingleNode("value/struct/member[name='wp_slug']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='wp_author_id']") == null)
                temp.author = "";
            else
                temp.author = node.SelectSingleNode("value/struct/member[name='wp_author_id']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='categories']") != null)
            {
                XmlNode categoryArray = node.SelectSingleNode("value/struct/member[name='categories']").LastChild;
                foreach (XmlNode catnode in categoryArray.SelectNodes("array/data/value/string"))
                {
                    cats.Add(catnode.InnerText);
                }
            }
            temp.categories = cats;

            // postDate has a few different names to worry about
            if (node.SelectSingleNode("value/struct/member[name='dateCreated']") != null)
            {
                try
                {
                    string tempDate = node.SelectSingleNode("value/struct/member[name='dateCreated']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }
            else if (node.SelectSingleNode("value/struct/member[name='pubDate']") != null)
            {
                try
                {
                    string tempPubDate = node.SelectSingleNode("value/struct/member[name='pubDate']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempPubDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }

            // WLW tags implementation using mt_keywords
            if (node.SelectSingleNode("value/struct/member[name='mt_keywords']") != null)
            {
                string tagsList = node.SelectSingleNode("value/struct/member[name='mt_keywords']").LastChild.InnerText;
                foreach (string item in tagsList.Split(','))
                {
                    if (string.IsNullOrEmpty(tags.Find(delegate(string t) { return t.Equals(item.Trim(), StringComparison.OrdinalIgnoreCase); })))
                    {
                        tags.Add(item.Trim());
                    }
                }
            }
            temp.tags = tags;

            return temp;
        }