private MWAPage GetPage(XmlNode node) { var temp = new MWAPage(); // 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("06", "Page 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='dateCreated']") != null) { try { string tempDate = node.SelectSingleNode("value/struct/member[name='dateCreated']").LastChild.InnerText; temp.pageDate = DateTime.ParseExact(tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } catch { // Ignore PubDate Error } } //Keywords if (node.SelectSingleNode("value/struct/member[name='mt_keywords']") == null) { temp.mt_keywords = ""; } else { temp.mt_keywords = node.SelectSingleNode("value/struct/member[name='mt_keywords']").LastChild.InnerText; } if (node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']") != null) { temp.pageParentID = node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']").LastChild.InnerText; } return(temp); }
/// <summary> /// wp.getPage method /// </summary> /// <param name="blogId"> /// blogID in string format /// </param> /// <param name="pageId"> /// page guid in string format /// </param> /// <param name="userName"> /// login username /// </param> /// <param name="password"> /// login password /// </param> /// <returns> /// struct with post details /// </returns> internal async Task <MWAPage> GetPage(string blogId, string pageId, string userName, string password) { var currentUser = await GetVerifyUserAsync(userName, password); //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.Pages)) //{ // throw new MetaWeblogException("11", "User authentication failed"); //} var sendPage = new MWAPage(); var page = await _pageManager.FindByIdAsync(pageId); sendPage.pageID = page.Id.ToString(); sendPage.title = page.Title; sendPage.description = page.Content; sendPage.mt_keywords = page.Keywords; sendPage.pageDate = page.CreationTime; sendPage.link = Url.RouteUrl(RouteNames.Page, new { id = page.Id }, Request.Scheme); sendPage.mt_convert_breaks = "__default__"; sendPage.pageParentID = page.ParentId.ToString(); return(sendPage); }
/// <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 + ")"); } }
/// <summary> /// wp.newPage method /// </summary> /// <param name="blogId">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <param name="mwaPage">The mwa page.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns>The new page.</returns> internal async Task <string> NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish) { var currentUser = await GetVerifyUserAsync(userName, password); //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.PageCreate)) //{ // throw new MetaWeblogException("11", "User authentication failed"); //} var page = new Page { Title = mwaPage.title, Content = mwaPage.description, Keywords = mwaPage.mt_keywords, Published = publish, }; if (mwaPage.pageDate != new DateTime()) { page.CreationTime = mwaPage.pageDate; } page.ParentId = mwaPage.pageParentID; await _pageManager.CreateAsync(page); return(page.Id.ToString()); }
/// <summary> /// Edits the page. /// </summary> /// <param name="blogId"> /// The blog id. /// </param> /// <param name="pageId"> /// The page id. /// </param> /// <param name="userName"> /// The user name. /// </param> /// <param name="password"> /// The password. /// </param> /// <param name="mwaPage"> /// The m page. /// </param> /// <param name="publish"> /// The publish. /// </param> /// <returns> /// The edit page. /// </returns> internal async Task <bool> EditPage(string blogId, string pageId, string userName, string password, MWAPage mwaPage, bool publish) { var user = GetVerifyUserAsync(userName, password); //if (!_permissionChecker.IsValid(user, PermissionKeys.PageEdit)) //{ // throw new MetaWeblogException("11", "User authentication failed"); //} var page = await _pageManager.FindByIdAsync(pageId); page.Title = mwaPage.title; page.Content = mwaPage.description; page.Keywords = mwaPage.mt_keywords; page.Published = publish; page.ParentId = mwaPage.pageParentID; await _pageManager.UpdateAsync(page); return(true); }
/// <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 + ")"); } }
/// <summary> /// Creates a Metaweblog Page object from the XML struct /// </summary> /// <param name="node">XML contains a Metaweblog Page Struct</param> /// <returns>Metaweblog Page Struct Obejct</returns> private MWAPage GetPage(XmlNode node) { MWAPage temp = new MWAPage(); // 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("06", "Page 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='dateCreated']") != null) { try { string tempDate = node.SelectSingleNode("value/struct/member[name='dateCreated']").LastChild.InnerText; temp.pageDate = DateTime.ParseExact(tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } catch { // Ignore PubDate Error } } //Keywords if (node.SelectSingleNode("value/struct/member[name='mt_keywords']") == null) temp.mt_keywords = ""; else temp.mt_keywords = node.SelectSingleNode("value/struct/member[name='mt_keywords']").LastChild.InnerText; if (node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']") != null) temp.pageParentID = node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']").LastChild.InnerText; return temp; }