/// <summary> /// wp.newPage /// </summary> /// <param name="blogID">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <param name="mPage"></param> /// <param name="publish"></param> /// <returns></returns> internal string NewPage(string blogID, string userName, string password, MWAPage mPage, bool publish) { ValidateRequest(userName, password); Page page = new Page(); page.Title = mPage.title; page.Content = mPage.description; page.Description = ""; // Can not be set from WLW page.Keywords = mPage.mt_keywords; if (mPage.pageDate != new DateTime()) { page.DateCreated = mPage.pageDate; } page.ShowInList = publish; page.IsPublished = publish; if (mPage.pageParentID != "0") { page.Parent = new Guid(mPage.pageParentID); } page.Save(); 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 bool EditPage( string blogId, string pageId, string userName, string password, MWAPage mwaPage, bool publish) { var page = Page.GetPage(new Guid(pageId)); if (!page.CanUserEdit) { throw new MetaWeblogException("11", "User authentication failed"); } if (!page.IsPublished && publish) { if (!page.CanPublish()) { throw new MetaWeblogException("11", "Not authorized to publish this Page."); } } page.Title = mwaPage.title; page.Content = mwaPage.description; page.Keywords = mwaPage.mt_keywords; page.ShowInList = publish; page.IsPublished = publish; if (mwaPage.pageParentID != "0") { page.Parent = new Guid(mwaPage.pageParentID); } page.Save(); return(true); }
/// <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); }
/// <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 MWAPage GetPage(string blogId, string pageId, string userName, string password) { var sendPage = new MWAPage(); var page = Page.GetPage(new Guid(pageId)); if (!page.IsVisible) { throw new MetaWeblogException("11", "User authentication failed"); } sendPage.pageID = page.Id.ToString(); sendPage.title = page.Title; sendPage.description = page.Content; sendPage.mt_keywords = page.Keywords; sendPage.pageDate = page.DateCreated; sendPage.link = page.AbsoluteLink.AbsoluteUri; sendPage.mt_convert_breaks = "__default__"; sendPage.pageParentID = page.Parent.ToString(); return(sendPage); }
/// <summary> /// wp.getPage /// </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 MWAPage GetPage(string blogID, string pageID, string userName, string password) { ValidateRequest(userName, password); MWAPage sendPage = new MWAPage(); Page page = Page.GetPage(new Guid(pageID)); sendPage.pageID = page.Id.ToString(); sendPage.title = page.Title; sendPage.description = page.Content; sendPage.mt_keywords = page.Keywords; sendPage.pageDate = page.DateCreated; sendPage.link = page.AbsoluteLink.AbsoluteUri; sendPage.mt_convert_breaks = "__default__"; if (page.Parent != null) { sendPage.pageParentID = page.Parent.ToString(); } return(sendPage); }
/// <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 string NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish) { if (!Security.IsAuthorizedTo(Rights.CreateNewPages)) { throw new MetaWeblogException("11", "User authentication failed"); } var page = new Page { Title = mwaPage.title, Content = mwaPage.description, Description = string.Empty, Keywords = mwaPage.mt_keywords }; if (publish) { if (!page.CanPublish()) { throw new MetaWeblogException("11", "Not authorized to publish this Page."); } } if (mwaPage.pageDate != new DateTime()) { page.DateCreated = mwaPage.pageDate; } page.ShowInList = publish; page.IsPublished = publish; if (mwaPage.pageParentID != "0") { page.Parent = new Guid(mwaPage.pageParentID); } page.Save(); return(page.Id.ToString()); }
/// <summary> /// wp.getPages /// </summary> /// <param name="blogID">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <returns></returns> internal List <MWAPage> GetPages(string blogID, string userName, string password) { ValidateRequest(userName, password); List <MWAPage> pages = new List <MWAPage>(); foreach (Page page in Page.Pages) { MWAPage mPage = new MWAPage(); mPage.pageID = page.Id.ToString(); mPage.title = page.Title; mPage.description = page.Content; mPage.mt_keywords = page.Keywords; mPage.pageDate = page.DateCreated; mPage.link = page.AbsoluteLink.AbsoluteUri; mPage.mt_convert_breaks = "__default__"; mPage.pageParentID = page.Parent.ToString(); pages.Add(mPage); } return(pages); }
/// <summary> /// wp.newPage /// </summary> /// <param name="blogID">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <param name="mPage"></param> /// <param name="publish"></param> /// <returns></returns> internal string NewPage(string blogID, string userName, string password, MWAPage mPage, bool publish) { ValidateRequest(userName, password); Page page = new Page(); page.Title = mPage.title; page.Content = mPage.description; page.Description = ""; // Can not be set from WLW page.Keywords = mPage.mt_keywords; if (mPage.pageDate != new DateTime()) page.DateCreated = mPage.pageDate; page.ShowInList = publish; page.IsPublished = publish; if (mPage.pageParentID != "0") page.Parent = new Guid(mPage.pageParentID); page.Save(); return page.Id.ToString(); }
/// <summary> /// wp.getPages /// </summary> /// <param name="blogID">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <returns></returns> internal List<MWAPage> GetPages(string blogID, string userName, string password) { ValidateRequest(userName, password); List<MWAPage> pages = new List<MWAPage>(); foreach (Page page in Page.Pages) { MWAPage mPage = new MWAPage(); mPage.pageID = page.Id.ToString(); mPage.title = page.Title; mPage.description = page.Content; mPage.mt_keywords = page.Keywords; mPage.pageDate = page.DateCreated; mPage.link = page.AbsoluteLink.AbsoluteUri; mPage.mt_convert_breaks = "__default__"; mPage.pageParentID = page.Parent.ToString(); pages.Add(mPage); } return pages; }
/// <summary> /// wp.getPage /// </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 MWAPage GetPage(string blogID, string pageID, string userName, string password) { ValidateRequest(userName, password); MWAPage sendPage = new MWAPage(); Page page = Page.GetPage(new Guid(pageID)); sendPage.pageID = page.Id.ToString(); sendPage.title = page.Title; sendPage.description = page.Content; sendPage.mt_keywords = page.Keywords; sendPage.pageDate = page.DateCreated; sendPage.link = page.AbsoluteLink.AbsoluteUri; sendPage.mt_convert_breaks = "__default__"; if (page.Parent != null) sendPage.pageParentID = page.Parent.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", "Unknown Method. (" + _methodName + ")"); } }
/// <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 MWAPage GetPage(string blogId, string pageId, string userName, string password) { var sendPage = new MWAPage(); var page = Page.GetPage(new Guid(pageId)); if (!page.IsVisible) { throw new MetaWeblogException("11", "User authentication failed"); } sendPage.pageID = page.Id.ToString(); sendPage.title = page.Title; sendPage.description = page.Content; sendPage.mt_keywords = page.Keywords; sendPage.pageDate = page.DateCreated; sendPage.link = page.AbsoluteLink.AbsoluteUri; sendPage.mt_convert_breaks = "__default__"; sendPage.pageParentID = page.Parent.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", "Unknown Method. (" + _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 static MWAPage GetPage(XmlNode node) { var temp = new MWAPage(); // Require Title and Description var title = node.SelectSingleNode("value/struct/member[name='title']"); if (title == null) { throw new MetaWeblogException("06", "Page Struct Element, Title, not Sent."); } temp.title = title.LastChild.InnerText; var description = node.SelectSingleNode("value/struct/member[name='description']"); if (description == null) { throw new MetaWeblogException("06", "Page Struct Element, Description, not Sent."); } temp.description = description.LastChild.InnerText; var link = node.SelectSingleNode("value/struct/member[name='link']"); if (link != null) { temp.link = node.SelectSingleNode("value/struct/member[name='link']") == null ? null : link.LastChild.InnerText; } var dateCreated = node.SelectSingleNode("value/struct/member[name='dateCreated']"); if (dateCreated != null) { try { var tempDate = dateCreated.LastChild.InnerText; temp.pageDate = DateTime.ParseExact( tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } catch (Exception ex) { // Ignore PubDate Error Debug.WriteLine(ex.Message); } } // Keywords var keywords = node.SelectSingleNode("value/struct/member[name='mt_keywords']"); temp.mt_keywords = keywords == null ? string.Empty : keywords.LastChild.InnerText; var pageParentId = node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']"); temp.pageParentID = pageParentId == null ? null : pageParentId.LastChild.InnerText; return(temp); }
internal bool EditPage(string blogID, string pageID, string userName, string password, MWAPage mPage, bool publish) { ValidateRequest(userName, password); Page page = Page.GetPage(new Guid(pageID)); page.Title = mPage.title; page.Content = mPage.description; page.Keywords = mPage.mt_keywords; page.ShowInList = publish; page.IsPublished = publish; if (mPage.pageParentID != "0") { page.Parent = new Guid(mPage.pageParentID); } page.Save(); return(true); }
/// <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 static MWAPage GetPage(XmlNode node) { var temp = new MWAPage(); // Require Title and Description var title = node.SelectSingleNode("value/struct/member[name='title']"); if (title == null) { throw new MetaWeblogException("06", "Page Struct Element, Title, not Sent."); } temp.title = title.LastChild.InnerText; var description = node.SelectSingleNode("value/struct/member[name='description']"); if (description == null) { throw new MetaWeblogException("06", "Page Struct Element, Description, not Sent."); } temp.description = description.LastChild.InnerText; var link = node.SelectSingleNode("value/struct/member[name='link']"); if (link != null) { temp.link = node.SelectSingleNode("value/struct/member[name='link']") == null ? null : link.LastChild.InnerText; } var dateCreated = node.SelectSingleNode("value/struct/member[name='dateCreated']"); if (dateCreated != null) { try { var tempDate = dateCreated.LastChild.InnerText; temp.pageDate = DateTime.ParseExact( tempDate, "yyyyMMdd'T'HH':'mm':'ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } catch (Exception ex) { // Ignore PubDate Error Debug.WriteLine(ex.Message); } } // Keywords var keywords = node.SelectSingleNode("value/struct/member[name='mt_keywords']"); temp.mt_keywords = keywords == null ? string.Empty : keywords.LastChild.InnerText; var pageParentId = node.SelectSingleNode("value/struct/member[name='wp_page_parent_id']"); temp.pageParentID = pageParentId == null ? null : pageParentId.LastChild.InnerText; return temp; }
/// <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 bool EditPage( string blogId, string pageId, string userName, string password, MWAPage mwaPage, bool publish) { var page = Page.GetPage(new Guid(pageId)); if (!page.CanUserEdit) { throw new MetaWeblogException("11", "User authentication failed"); } if (!page.IsPublished && publish) { if (!page.CanPublish()) { throw new MetaWeblogException("11", "Not authorized to publish this Page."); } } page.Title = mwaPage.title; page.Content = mwaPage.description; page.Keywords = mwaPage.mt_keywords; page.ShowInList = publish; page.IsPublished = publish; if (mwaPage.pageParentID != "0") { page.Parent = new Guid(mwaPage.pageParentID); } page.Save(); return true; }
internal bool EditPage(string blogID, string pageID, string userName, string password, MWAPage mPage, bool publish) { ValidateRequest(userName, password); Page page = Page.GetPage(new Guid(pageID)); page.Title = mPage.title; page.Content = mPage.description; page.Keywords = mPage.mt_keywords; page.ShowInList = publish; page.IsPublished = publish; if (mPage.pageParentID != "0") page.Parent = new Guid(mPage.pageParentID); page.Save(); return true; }
/// <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 string NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish) { if (!Security.IsAuthorizedTo(Rights.CreateNewPages)) { throw new MetaWeblogException("11", "User authentication failed"); } var page = new Page { Title = mwaPage.title, Content = mwaPage.description, Description = string.Empty, Keywords = mwaPage.mt_keywords }; if (publish) { if (!page.CanPublish()) { throw new MetaWeblogException("11", "Not authorized to publish this Page."); } } if (mwaPage.pageDate != new DateTime()) { page.DateCreated = mwaPage.pageDate; } page.ShowInList = publish; page.IsPublished = publish; if (mwaPage.pageParentID != "0") { page.Parent = new Guid(mwaPage.pageParentID); } page.Save(); return page.Id.ToString(); }
/// <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; }