/// <summary> /// Create the XML for the subscribedUsers list /// </summary> /// <param name="userID">ID of user whose list we want</param> /// <param name="skip">skip to this index in the list</param> /// <param name="show">show this many items in the list</param> /// <returns></returns> public bool CreateSubscribingUsersList(int userID, int skip, int show) { // check object is not already initialised if (userID <= 0 || show <= 0) { return false; } int count = show; XmlElement SubscribingUsersList = AddElementTag(RootElement, "SUBSCRIBINGUSERS-LIST"); AddAttribute(SubscribingUsersList, "SKIP", skip); AddAttribute(SubscribingUsersList, "SHOW", show); using (IDnaDataReader dataReader = GetSubscribingUsersList(userID, skip, show + 1)) // Get +1 so we know if there are more left { // Check to see if we found anything string userName = String.Empty; if (dataReader.HasRows && dataReader.Read()) { User subscribedTo = new User(InputContext); subscribedTo.AddPrefixedUserXMLBlock(dataReader, userID, "subscribedTo", SubscribingUsersList); _userAcceptsSubscriptions = dataReader.GetBoolean("SubscribedToAcceptSubscriptions"); //Get the list from the second recordset dataReader.NextResult(); if (dataReader.HasRows && dataReader.Read()) { XmlElement users = CreateElement("USERS"); do { User subscribingUser = new User(InputContext); int subscribingUserID = dataReader.GetInt32NullAsZero("UserID"); subscribingUser.AddUserXMLBlock(dataReader, subscribingUserID, users); count--; } while (count > 0 && dataReader.Read()); // dataReader.Read won't get called if count == 0 SubscribingUsersList.AppendChild(users); // See if there's an extra row waiting if (count == 0 && dataReader.Read()) { AddAttribute(SubscribingUsersList, "MORE", 1); } } } } //AddAttribute(UserSubscriptionsList, "COUNT", count); return true; }
/// <summary> /// Creates the XML block for a posting in a thread /// </summary> /// <param name="reader">The IDnaDataReader that contains the information about the posting</param> /// <param name="threadNode">The node to add the posting node to</param> /// <param name="usersPrefix">Pass in 'First' if the post is the first post in the thread, and 'last' if it's the last.</param> /// <returns>The new post node</returns> private XmlNode CreateThreadPostingXml(IDnaDataReader reader, XmlNode threadNode, string usersPrefix) { XmlNode postingNode = AddElementTag(threadNode, usersPrefix + "POST"); AddAttribute(postingNode, "POSTID", reader.GetInt32(usersPrefix + "PostEntryID")); AddAttribute(postingNode, "HIDDEN", reader.GetInt32NullAsZero(usersPrefix + "PostHidden")); User postingUser = new User(InputContext); postingUser.AddPrefixedUserXMLBlock(reader, reader.GetInt32(usersPrefix + "PostUserID"), usersPrefix + "Post", postingNode); if (!reader.IsDBNull(usersPrefix + "PostHidden") && reader.GetInt32(usersPrefix + "PostHidden") > 0) { AddTextElement((XmlElement)postingNode, "TEXT", "Hidden"); } else { string text = reader.GetString(usersPrefix + "PostText"); // Do the translate to plain text here! XmlNode textNode = AddTextElement((XmlElement)postingNode, "TEXT", text); } return postingNode; }
/* <FORUMSOURCE> <JOURNAL> <USER> <USERID>6</USERID> <USERNAME>Jim Lynn</USERNAME> </USER> </JOURNAL> </FORUMSOURCE> or <FORUMSOURCE> <ARTICLE> <H2G2ID>12345</H2G2ID> <SUBJECT>Hello there</SUBJECT> </ARTICLE> </FORUMSOURCE> or <FORUMSOURCE> <USERPAGE> <USER> <USERID>6</USERID> <USERNAME>Jim Lynn</USERNAME> </USER> </USERPAGE> </FORUMSOURCE> or <FORUMSOURCE> <CLUB ID= '1'> <NAME>Dharmesh Club</NAME> </CLUB> </FORUMSOURCE> */ /// <summary> /// Builds an XML representation of the forum source, vis: /// </summary> /// <param name="forumID">ID of forum</param> /// <param name="threadID">ID of forum thread</param> /// <param name="includeArticle">flag to include article data</param> /// <param name="type">Type of forum</param> /// <param name="ID">ID either H2G2ID or club ID</param> /// <param name="title">Title</param> /// <param name="siteID">Site ID</param> /// <param name="url">URL involved</param> public void GetTitle(int forumID, int threadID, bool includeArticle, ref int type, ref int ID, ref string title, ref int siteID, ref string url) { string subject = ""; // Subject based on type found int userID = 0; int reviewForumID = 0; int alertInstantly = 0; int hiddenStatus = 0; int articleStatus = 0; int realForumID = 0; using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("getforumsource")) { dataReader.AddParameter("ForumID", forumID); dataReader.AddParameter("ThreadID", threadID); dataReader.AddParameter("CurrentSiteID", InputContext.CurrentSite.SiteID); dataReader.Execute(); if (dataReader.HasRows && dataReader.Read()) { // Fill in return values ID = dataReader.GetInt32NullAsZero("h2g2ID"); type = dataReader.GetInt32NullAsZero("Type"); hiddenStatus = dataReader.GetInt32NullAsZero("HiddenStatus"); articleStatus = dataReader.GetInt32NullAsZero("ArticleStatus"); alertInstantly = dataReader.GetInt32NullAsZero("AlertInstantly"); siteID = dataReader.GetInt32NullAsZero("SiteID"); realForumID = dataReader.GetInt32NullAsZero("ForumID"); reviewForumID = 0; userID = 0; if (dataReader.GetInt32NullAsZero("JournalOwner") > 0) { title = dataReader.GetStringNullAsEmpty("JournalUserName"); userID = dataReader.GetInt32NullAsZero("JournalOwner"); } else if (dataReader.GetInt32NullAsZero("UserID") > 0) { title = dataReader.GetStringNullAsEmpty("UserName"); userID = dataReader.GetInt32NullAsZero("UserID"); } else if (!dataReader.IsDBNull("ReviewForumID")) { title = dataReader.GetStringNullAsEmpty("ReviewForumName"); reviewForumID = dataReader.GetInt32NullAsZero("ReviewForumID"); } else if (!dataReader.IsDBNull("URL")) { url = dataReader.GetStringNullAsEmpty("URL"); } else { title = dataReader.GetStringNullAsEmpty("Subject"); } XmlElement forumSource = AddElementTag(RootElement, "FORUMSOURCE"); if (type == 0) { AddAttribute(forumSource, "TYPE", "journal"); User journalOwner = new User(InputContext); journalOwner.AddPrefixedUserXMLBlock(dataReader, userID, "Journal", forumSource); } else if (type == 3) { // It's a review forum AddAttribute(forumSource, "TYPE", "reviewforum"); XmlElement reviewForum = AddElementTag(forumSource, "REVIEWFORUM"); AddAttribute(reviewForum, "ID", reviewForumID); AddTextTag(reviewForum, "REVIEWFORUMNAME", subject); AddTextTag(reviewForum, "URLFRIENDLYNAME", "RF" + reviewForumID.ToString()); } else if (type == 1) { AddAttribute(forumSource, "TYPE", "article"); } /*else if (type == 5) { AddAttribute(forumSource, "TYPE", "club"); XmlElement club = AddElementTag(forumSource, "CLUB"); AddAttribute(club, "ID", clubID); AddTextTag(club, "NAME", subject); } else if (type == 6) { AddAttribute(forumSource, "TYPE", "clubforum"); XmlElement club = AddElementTag(forumSource, "CLUB"); AddAttribute(club, "ID", clubID); AddTextTag(club, "NAME", subject); } else if (type == 7) { AddAttribute(forumSource, "TYPE", "clubjournal"); XmlElement club = AddElementTag(forumSource, "CLUB"); AddAttribute(club, "ID", clubID); AddTextTag(club, "NAME", subject); }*/ else if (type == 4) { AddAttribute(forumSource, "TYPE", "privateuser"); XmlElement userPage = AddElementTag(forumSource, "USERPAGE"); User user = new User(InputContext); user.AddUserXMLBlock(dataReader, userID, userPage); } else if (type == 8) { AddAttribute(forumSource, "TYPE", "noticeboard"); } else { AddAttribute(forumSource, "TYPE", "userpage"); XmlElement userPage = AddElementTag(forumSource, "USERPAGE"); User user = new User(InputContext); user.AddUserXMLBlock(dataReader, userID, userPage); } if (ID > 0) { if (includeArticle) { GuideEntrySetup guideEntrySetup = new GuideEntrySetup(ID); guideEntrySetup.ShowEntryData = true; guideEntrySetup.ShowPageAuthors = true; guideEntrySetup.ShowReferences = true; guideEntrySetup.SafeToCache = true; GuideEntry guideEntry = new GuideEntry(InputContext, guideEntrySetup); if (!guideEntry.Initialise()) { throw new DnaException("The article doesn't exist. " + ID.ToString()); } if (!guideEntry.IsDeleted) { AddInside(guideEntry, "FORUMSOURCE"); XmlElement article = (XmlElement)forumSource.SelectSingleNode("ARTICLE"); AddIntElement(article, "H2G2ID", ID); } else { XmlElement deletedArticle = AddElementTag(forumSource, "ARTICLE"); AddIntElement(deletedArticle, "H2G2ID", ID); AddTextTag(deletedArticle, "SUBJECT", "Deleted"); AddIntElement(deletedArticle, "HIDDEN", hiddenStatus); XmlNode statusNode = AddTextTag(deletedArticle, "STATUS", GuideEntry.GetDescriptionForStatusValue(articleStatus)); AddAttribute(statusNode, "TYPE", articleStatus); } } else { XmlElement defaultArticle = AddElementTag(forumSource, "ARTICLE"); AddIntElement(defaultArticle, "H2G2ID", ID); AddTextTag(defaultArticle, "SUBJECT", subject); AddIntElement(defaultArticle, "HIDDEN", hiddenStatus); XmlNode statusNode = AddTextTag(defaultArticle, "STATUS", GuideEntry.GetDescriptionForStatusValue(articleStatus)); AddAttribute(statusNode, "TYPE", articleStatus); } AddIntElement(forumSource, "ALERTINSTANTLY", alertInstantly); } } } }
private void CreateFormXml(IDnaDataReader dataReader, string comments, bool acceptButton, bool rejectButton, bool cancelButton, bool fetchButton, bool byRecommendationID) { RootElement.RemoveAll(); _processRecommendationForm = AddElementTag(RootElement, "PROCESS-RECOMMENDATION-FORM"); int recommendationID = dataReader.GetInt32NullAsZero("recommendationID"); int h2g2ID = dataReader.GetInt32NullAsZero("h2g2ID"); int entryID = dataReader.GetInt32NullAsZero("entryID"); string entrySubject = dataReader.GetStringNullAsEmpty("Subject"); int editorID = dataReader.GetInt32NullAsZero("EditorID"); string editorName = dataReader.GetStringNullAsEmpty("EditorName"); User editor = new User(InputContext); int scoutID = dataReader.GetInt32NullAsZero("ScoutID"); string scoutName = dataReader.GetStringNullAsEmpty("ScoutName"); User scout = new User(InputContext); DateTime dateRecommended = dataReader.GetDateTime("DateRecommended"); string retrievedComments = dataReader.GetStringNullAsEmpty("Comments"); AddIntElement(_processRecommendationForm, "RECOMMENDATION-ID", recommendationID); AddIntElement(_processRecommendationForm, "H2G2-ID", h2g2ID); AddTextTag(_processRecommendationForm, "SUBJECT", entrySubject); AddTextTag(_processRecommendationForm, "COMMENTS", retrievedComments); XmlElement editorElement = AddElementTag(_processRecommendationForm, "EDITOR"); editor.AddPrefixedUserXMLBlock(dataReader, editorID, "editor", editorElement); XmlElement scoutElement = AddElementTag(_processRecommendationForm, "SCOUT"); scout.AddPrefixedUserXMLBlock(dataReader, scoutID, "scout", scoutElement); AddDateXml(dateRecommended, _processRecommendationForm, "DATE-RECOMMENDED"); // if we know what the decision is going to be then create an appropriate // default email to send string scoutEmailSubject = String.Empty; string scoutEmailText = String.Empty; string authorEmailSubject = String.Empty; string authorEmailText = String.Empty; if (acceptButton && !rejectButton) { CreateScoutAcceptanceEmail(scoutName, entrySubject, h2g2ID, dateRecommended, ref scoutEmailSubject, ref scoutEmailText); if (byRecommendationID) { CreateAuthorAcceptanceEmail(editorName, entrySubject, h2g2ID, dateRecommended, ref authorEmailSubject, ref authorEmailText); } } else if (rejectButton && !acceptButton) { CreateScoutRejectionEmail(scoutName, entrySubject, h2g2ID, dateRecommended, ref scoutEmailSubject, ref scoutEmailText); } if (byRecommendationID) { XmlElement scoutEmail = AddElementTag(_processRecommendationForm, "SCOUT-EMAIL"); AddTextTag(scoutEmail, "SUBJECT", scoutEmailSubject); AddTextTag(scoutEmail, "TEXT", scoutEmailText); XmlElement authorEmail = AddElementTag(_processRecommendationForm, "AUTHOR-EMAIL"); AddTextTag(authorEmail, "SUBJECT", authorEmailSubject); AddTextTag(authorEmail, "TEXT", authorEmailText); } else { AddTextTag(_processRecommendationForm, "EMAIL-SUBJECT", scoutEmailSubject); AddTextTag(_processRecommendationForm, "EMAIL-TEXT", scoutEmailText); } XmlElement functions = AddElementTag(_processRecommendationForm, "FUNCTIONS"); if (acceptButton) { AddElementTag(functions, "ACCEPT"); } if (rejectButton) { AddElementTag(functions, "REJECT"); } if (cancelButton) { AddElementTag(functions, "CANCEL"); } if (fetchButton) { AddElementTag(functions, "FETCH"); } }
/// <summary> /// This method gets all the related articles for a given article h2g2ID /// </summary> /// <param name="h2g2ID">The id of the article you want to get the related articles for</param> public void GetRelatedArticles(int h2g2ID) { // Create the datareader to get the articles using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getrelatedarticles")) { reader.AddParameter("h2g2ID", h2g2ID); reader.AddParameter("CurrentSiteID", 0); reader.Execute(); XmlNode relatedArticlesNode = AddElementTag(RootElement, "RELATEDARTICLES"); // Add each article in turn while (reader.Read()) { XmlNode relatedArticleNode = AddElementTag(relatedArticlesNode, "ARTICLEMEMBER"); AddIntElement(relatedArticleNode, "H2G2ID", h2g2ID); string articleName = reader.GetString("Subject"); AddTextElement((XmlElement)relatedArticleNode, "NAME", articleName); if (_includeStrippedNames) { string strippedName = StringUtils.StrippedName(articleName); AddTextElement((XmlElement)relatedArticleNode, "STRIPPEDNAME", strippedName); } XmlNode userNode = AddElementTag(relatedArticleNode, "EDITOR"); User articleEditor = new User(InputContext); articleEditor.AddPrefixedUserXMLBlock(reader, reader.GetInt32("Editor"), "Editor", userNode); int status = reader.GetInt32("Status"); XmlNode statusNode = AddTextElement((XmlElement)relatedArticleNode, "STATUS", GuideEntry.GetDescriptionForStatusValue(status)); AddAttribute(statusNode, "TYPE", status); ExtraInfo articleExtraInfo = new ExtraInfo(); int articleType = reader.GetInt32("Type"); int articleHidden = 0; if (reader.Exists("Hidden") && !reader.IsDBNull("Hidden")) { articleHidden = reader.GetInt32("Hidden"); } // Create and add the article extra info articleExtraInfo.TryCreate(articleType, reader.GetString("ExtraInfo")); AddInside(relatedArticleNode, articleExtraInfo); if (reader.Exists("DateCreated")) { XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "DATECREATED"); dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true)); } if (reader.Exists("Lastupdated")) { XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "LASTUPDATE"); dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true)); } // NOW ADD KEYPHRASES, MEDIA ASSETS, POLLS } } }
/// <summary> /// CreateLinkXML from a dataReader. /// Allows standard Link XML to be generated from different resultsets. /// </summary> /// <param name="dataReader"></param> /// <param name="parent"></param> /// <param name="createAuthorXML"></param> /// <param name="createSubmitterXML"></param> /// <returns></returns> public void CreateLinkXML(IDnaDataReader dataReader, XmlNode parent, bool createSubmitterXML, bool createAuthorXML ) { RootElement.RemoveAll(); String type = dataReader.GetStringNullAsEmpty("destinationtype"); XmlNode link = CreateElementNode("LINK"); AddAttribute(link, "TYPE", type); AddAttribute(link, "LINKID", dataReader.GetInt32NullAsZero("linkid")); AddAttribute(link, "TEAMID", dataReader.GetInt32NullAsZero("teamid")); AddAttribute(link, "RELATIONSHIP", dataReader.GetStringNullAsEmpty("relationship")); AddAttribute(link, "PRIVATE", dataReader.GetTinyIntAsInt("private")); //Create appropriate URL from link type. int destinationId = dataReader.GetInt32NullAsZero("DestinationID"); switch (type) { case "article" : { AddAttribute(link, "DNAUID", "A" + destinationId ); break; } case "userpage" : { AddAttribute(link, "DNAUID", "U" + destinationId); break; } case "category" : { AddAttribute(link, "DNAUID", "C" + destinationId); break; } case "forum" : { AddAttribute(link, "DNAUID", "F" + destinationId); break; } case "thread" : { AddAttribute(link, "DNAUID", "T" + destinationId); break; } case "posting" : { AddAttribute(link, "DNAUID", "TP" + destinationId); break; } default : // "club" ) { AddAttribute(link, "DNAUID", "G" + destinationId); break; } } //AddTextTag(link, "TITLE", dataReader.GetStringNullAsEmpty("title")); AddTextTag(link, "DESCRIPTION", dataReader.GetStringNullAsEmpty("linkdescription")); //Create Submitter XML if required . if ( createSubmitterXML ) { int submitterId = dataReader.GetInt32NullAsZero("submitterid"); if (submitterId > 0) { XmlNode submitterXML = AddElementTag(link, "SUBMITTER"); User submitter = new User(InputContext); submitter.AddPrefixedUserXMLBlock(dataReader, submitterId, "submitter", submitterXML); } } //Create author XML if required. if (createAuthorXML) { int authorId = dataReader.GetInt32NullAsZero("authorid"); if (authorId > 0) { XmlNode authorXML = AddElementTag(link, "AUTHOR"); User author = new User(InputContext); author.AddPrefixedUserXMLBlock(dataReader, authorId, "author", authorXML); } } if (!dataReader.IsDBNull("datelinked")) AddDateXml(dataReader.GetDateTime("datelinked"),link,"DATELINKED"); if ( !dataReader.IsDBNull("lastupdated") ) AddDateXml(dataReader.GetDateTime("lastupdated"),link,"LASTUPDATED"); XmlNode importXml = parent.OwnerDocument.ImportNode(link, true); parent.AppendChild(importXml); }
/// <summary> /// Sets the editor XML from the given dataReader /// </summary> /// <param name="dataReader">DataReader contain the row with the editor user columns</param> public void SetEditor(IDnaDataReader dataReader) { string editor = dataReader.GetStringNullAsEmpty("editor"); int editorID = 0; Int32.TryParse(editor, out editorID); _editor.RemoveAll(); _editor = CreateElement("Editor"); User editorUser = new User(InputContext); editorUser.AddPrefixedUserXMLBlock(dataReader, editorID, "editor", _editor); }
private void GenerateXml(IDnaDataReader reader, int h2g2Id, int postId, string exLinkUrl) { XmlElement modHistory = AddElementTag(RootElement, "MODERATION-HISTORY"); reader.Read(); if (h2g2Id > 0) AddAttribute(modHistory, "H2G2ID", h2g2Id); else if (postId > 0) { AddAttribute(modHistory, "POSTID", postId); if ( reader.HasRows ) { AddAttribute(modHistory, "FORUMID", reader.GetInt32NullAsZero("forumid") ); AddAttribute(modHistory, "THREADID", reader.GetInt32NullAsZero("threadid") ); } } else if (exLinkUrl != String.Empty) AddAttribute(modHistory, "EXLINKURL", exLinkUrl ); if (reader.HasRows) { int rowCount = 0; do { if (rowCount == 0) { AddXmlTextTag(modHistory, "SUBJECT", reader.GetStringNullAsEmpty("subject")); if (reader.DoesFieldExist("authoruserid") && !reader.IsDBNull("authoruserid")) { XmlElement editorNode = AddElementTag(modHistory, "EDITOR"); User editor = new User(InputContext); editor.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("authoruserid"), "Author", editorNode); } } XmlElement moderation = AddElementTag(modHistory, "MODERATION"); AddAttribute(moderation, "MODID", reader.GetInt32NullAsZero("modid")); AddIntElement(moderation, "STATUS", reader.GetInt32NullAsZero("status")); AddTextElement(moderation, "URLNAME", InputContext.TheSiteList.GetSite(reader.GetInt32NullAsZero("siteid")).SiteName); if (reader.DoesFieldExist("reasonid") && reader.GetInt32NullAsZero("reasonid") > 0) { AddIntElement(moderation, "REASONID", reader.GetInt32NullAsZero("reasonid")); } User user = new User(InputContext); if ( !reader.IsDBNull("lockedbyuserid") ) { XmlElement locked = AddElementTag(moderation, "LOCKED-BY"); user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("LockedBy"), "lockedby", locked); } if (!reader.IsDBNull("referredbyuserid")) { XmlElement referred = AddElementTag(moderation, "REFERRED-BY"); user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("referredbyuserid"), "referredby", referred); } XmlElement complaint = AddElementTag(moderation, "COMPLAINT"); AddTextElement(complaint, "COMPLAINT-TEXT", reader.GetStringNullAsEmpty("complainttext")); if (reader.DoesFieldExist("complainantuserid") && !reader.IsDBNull("complainantuserid")) { user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("complainantuserid"), "complainant", complaint); } AddTextElement(complaint, "IPADDRESS", reader.GetStringNullAsEmpty("ipaddress")); AddTextElement(complaint, "BBCUID", reader.GetGuidAsStringOrEmpty("bbcuid").ToString()); AddTextElement(complaint, "EMAIL-ADDRESS", reader.GetStringNullAsEmpty("correspondenceemail")); AddTextElement(moderation, "NOTES", HtmlUtils.ReplaceCRsWithBRs(reader.GetStringNullAsEmpty("notes"))); AddDateXml(reader.GetDateTime("datequeued"), moderation, "DATE-QUEUED"); if (!reader.IsDBNull("datelocked")) { AddDateXml(reader.GetDateTime("datelocked"), moderation, "DATE-LOCKED"); } if (!reader.IsDBNull("datereferred")) { AddDateXml(reader.GetDateTime("datereferred"), moderation, "DATE-REFERRED"); } if (!reader.IsDBNull("datecompleted")) { AddDateXml(reader.GetDateTime("datecompleted"), moderation, "DATE-COMPLETED"); } ++rowCount; } while (reader.Read()); } }