Esempio n. 1
0
        /// <summary>
        /// Creates and adds the returned User Xml block to a given parent post node from the passed user parameters with a prefix
        /// ie the field name of OwnerUserName, OwnerFirstNames
        /// </summary>
        /// <param name="dataReader">Data reader object</param>
        /// <param name="userID">The users id</param>
        /// <param name="prefix">The prefix of the field names for a different user in the same result set</param>
        /// <param name="parent">The parent Node to add the user xml to</param>
        /// <returns>XmlNode Containing user XML from the stored procedure</returns>
        public void AddPrefixedUserXMLBlock(IDnaDataReader dataReader, int userID, string prefix, XmlNode parent)
        {
            string userName = "";
            if (dataReader.Exists(prefix + "UserName"))
            {
                userName = dataReader.GetStringNullAsEmpty(prefix + "UserName");
            }
            else if (dataReader.Exists(prefix + "Name"))
            {
                userName = dataReader.GetStringNullAsEmpty(prefix + "Name");
            }

            if (userName == String.Empty)
            {
                userName = "******" + userID.ToString();
            }

            string identityUserId = "";
            if (dataReader.Exists(prefix + "identityUserId"))
            {
                identityUserId = dataReader.GetStringNullAsEmpty(prefix + "identityUserId");
            }

            string emailAddress = "";
            if (dataReader.Exists(prefix + "Email"))
            {
                emailAddress = dataReader.GetStringNullAsEmpty(prefix + "Email");
            }

            double zeigeistScore = 0.0;
            if (dataReader.DoesFieldExist(prefix + "ZeitgeistScore"))
            {
                zeigeistScore = dataReader.GetDoubleNullAsZero(prefix + "ZeitgeistScore");
            }

            string siteSuffix = "";
            if (dataReader.Exists(prefix + "SiteSuffix"))
            {
                siteSuffix = dataReader.GetStringNullAsEmpty(prefix + "SiteSuffix");
            }

            string area = "";
            if (dataReader.Exists(prefix + "Area"))
            {
                area = dataReader.GetStringNullAsEmpty(prefix + "Area");
            }

            string title = "";
            if (dataReader.Exists(prefix + "Title"))
            {
                title = dataReader.GetStringNullAsEmpty(prefix + "Title");
            }

            int subQuota = 0;
            if (dataReader.Exists(prefix + "SubQuota"))
            {
                subQuota = dataReader.GetInt32NullAsZero(prefix + "SubQuota");
            }

            int allocations = 0;
            if (dataReader.Exists(prefix + "Allocations"))
            {
                allocations = dataReader.GetInt32NullAsZero(prefix + "Allocations");
            }
            

            int journal = 0;
            if (dataReader.Exists(prefix + "Journal"))
            {
                journal = dataReader.GetInt32NullAsZero(prefix + "Journal");
            }

            bool isActive = false;
            if (dataReader.Exists(prefix + "Active") && !dataReader.IsDBNull(prefix + "Active"))
            {
                isActive = dataReader.GetBoolean(prefix + "Active");
            }

            DateTime dateLastNotified = DateTime.MinValue;
            if (dataReader.Exists(prefix + "DateLastNotified") && dataReader.GetValue(prefix + "DateLastNotified") != DBNull.Value)
            {
                dateLastNotified = dataReader.GetDateTime(prefix + "DateLastNotified");
            }

            DateTime dateJoined = DateTime.MinValue;
            if (dataReader.Exists(prefix + "DateJoined") && dataReader.GetValue(prefix + "DateJoined") != DBNull.Value)
            {
                dateJoined = dataReader.GetDateTime(prefix + "DateJoined");
            }
            int forumPostedTo = -1;
            if (dataReader.Exists(prefix + "ForumPostedTo"))
            {
                forumPostedTo = dataReader.GetInt32NullAsZero(prefix + "ForumPostedTo");
            }
            int masthead = -1;
            if (dataReader.Exists(prefix + "Masthead"))
            {
                masthead = dataReader.GetInt32NullAsZero(prefix + "Masthead");
            }
            int sinbin = -1;
            if (dataReader.Exists(prefix + "SinBin"))
            {
                sinbin = dataReader.GetInt32NullAsZero(prefix + "SinBin");
            }
            int forumID = -1;
            if (dataReader.Exists(prefix + "ForumID"))
            {
                forumID = dataReader.GetInt32NullAsZero(prefix + "ForumID");
            }

            XmlNode userXML = GenerateUserXml(userID,
                                                userName,
                                                emailAddress,
                                                dataReader.GetStringNullAsEmpty(prefix + "FirstNames"),
                                                dataReader.GetStringNullAsEmpty(prefix + "LastName"),
                                                dataReader.GetInt32NullAsZero(prefix + "Status"),
                                                dataReader.GetInt32NullAsZero(prefix + "TaxonomyNode"),
                                                isActive,
                                                zeigeistScore,
                                                siteSuffix,
                                                area,
                                                title,
                                                journal,
                                                dateLastNotified,
                                                subQuota, 
                                                allocations,
                                                dateJoined,
                                                forumID,
                                                forumPostedTo,
                                                masthead,
                                                sinbin,
                                                identityUserId);


            if (userXML != null)
            {
                XmlNode importxml = parent.OwnerDocument.ImportNode(userXML, true);
                parent.AppendChild(importxml);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// AddPollXml - Delegates responsibility of producing standard Poll Xml to the Poll Class.
        /// Only produces Poll Xml where a valid Poll exists in the resultset.
        /// </summary>
        /// <param name="dataReader">Record set containing the data</param>
        /// <param name="parent">Parent node to add the xml to</param>
        private void AddPollXml(IDnaDataReader dataReader, XmlNode parent)
        {
            if (dataReader.DoesFieldExist("CRPollID"))
            {
                int pollId = dataReader.GetInt32NullAsZero("CRPollID");
                if (pollId > 0)
                {
                    PollContentRating poll = new PollContentRating(this.InputContext, this.InputContext.ViewingUser);

                    poll.PollID = dataReader.GetInt32NullAsZero("CRPollID");
                    poll.Hidden = dataReader.GetInt32NullAsZero("Hidden") != 0;
                    int voteCount = dataReader.GetInt32NullAsZero("CRVoteCount");
                    double avgRating = dataReader.GetDoubleNullAsZero("CRAverageRating");
                    poll.SetContentRatingStatistics(voteCount, avgRating);
                    XmlNode node = poll.MakePollXML(false);
                    if (node != null)
                    {
                        parent.AppendChild(ImportNode(node));
                    }
                }
            }
        }
        private void AddPollXml(IDnaDataReader dataReader, XmlNode article)
        {
            //<POLL POLLID="2311" POLLTYPE="3" HIDDEN="0">
            //    <STATISTICS AVERAGERATING="0.000000" VOTECOUNT="0" /> 
            //</POLL>

            int pollID = dataReader.GetInt32NullAsZero("CRPollID");
            if (pollID != 0)
            {
                XmlNode poll = CreateElementNode("POLL");
                AddAttribute(poll, "POLLID", pollID);
                AddAttribute(poll, "POLLTYPE", 3);
                AddAttribute(poll, "HIDDEN", 0);
                XmlNode statistics = CreateElementNode("STATISTICS");
                AddAttribute(statistics, "AVERAGERATING", dataReader.GetDoubleNullAsZero("CRAverageRating").ToString());
                AddAttribute(statistics, "VOTECOUNT", dataReader.GetInt32NullAsZero("CRVoteCount").ToString());
                poll.AppendChild(statistics);
                article.AppendChild(poll);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Builds ARTICLEMEMBER xml based on current row in dataReader
        /// </summary>
        /// <param name="dataReader">The data reader with the data</param>
        /// <param name="articleKeyPhraseMap">The map of article key phrases</param>
        /// <returns>XML Element contain the articlemember data</returns>
        XmlElement AddArticleMemberXML(IDnaDataReader dataReader, Dictionary<int, List<Phrase>> articleKeyPhraseMap)
        {
	        ArticleMember articleMember = new ArticleMember(InputContext);

            int H2G2ID = dataReader.GetInt32NullAsZero("h2g2id");
            string name = dataReader.GetStringNullAsEmpty("subject");
            string extraInfo = dataReader.GetStringNullAsEmpty("extrainfo");

            articleMember.H2G2ID = H2G2ID;
	        articleMember.Name = name;
	        articleMember.IncludeStrippedName = true;

	        // Get and Set editor data
            articleMember.SetEditor(dataReader);

            articleMember.Status = dataReader.GetInt32NullAsZero("status");
            if (dataReader.DoesFieldExist("type"))
	        {
                articleMember.SetExtraInfo(extraInfo, dataReader.GetInt32NullAsZero("type"));
	        }
	        else
	        {
                articleMember.SetExtraInfo(extraInfo);
	        }

            articleMember.DateCreated = dataReader.GetDateTime("datecreated");
            articleMember.LastUpdated = dataReader.GetDateTime("lastupdated");
        		

	        if (InputContext.CurrentSite.IncludeCrumbtrail == 1)
	        {
                if (dataReader.DoesFieldExist("type") && dataReader.GetInt32NullAsZero("type") > 0)
                {
			        articleMember.Local = true;
		        }
	        }

            if (dataReader.DoesFieldExist("CRPollID"))
	        {
                articleMember.SetContentRatingStatistics(dataReader.GetInt32NullAsZero("CRPollID"),
                    dataReader.GetInt32NullAsZero("CRVoteCount"),
                    dataReader.GetDoubleNullAsZero("CRAverageRating"));
	        }

            if (dataReader.DoesFieldExist("MediaAssetID"))
	        {
                string caption = dataReader.GetStringNullAsEmpty("Caption");
                string extraElementXML = dataReader.GetStringNullAsEmpty("ExtraElementXML");
                string externalLinkURL = dataReader.GetStringNullAsEmpty("ExternalLinkURL");

                articleMember.SetMediaAssetInfo(dataReader.GetInt32NullAsZero("MediaAssetID"),
                                                dataReader.GetInt32NullAsZero("ContentType"),
										        caption,
                                                dataReader.GetInt32NullAsZero("MimeType"),
                                                dataReader.GetInt32NullAsZero("OwnerID"),
										        extraElementXML,
                                                dataReader.GetInt32NullAsZero("Hidden"),
										        externalLinkURL);
	        }
        	
	        bool includeKeyPhraseData = InputContext.GetSiteOptionValueBool("KeyPhrases", "ReturnInCategoryList");
	        if (includeKeyPhraseData)
	        {
                int entryId = dataReader.GetInt32NullAsZero("entryid");
		        articleMember.SetPhraseList(articleKeyPhraseMap[entryId]);
	        }
            articleMember.TryCreateXML();

            return articleMember.RootElement;
        }
Esempio n. 5
0
        /// <summary>
        /// With the returned data set generate the XML for the Article Search page
        /// </summary>
        /// <param name="dataReader">The returned search resultset</param>
        /// <param name="asp">The Article Search Params</param>
        private void GenerateArticleSearchXml(IDnaDataReader dataReader, ArticleSearchParams asp)
        {
            RootElement.RemoveAll();
            XmlNode articleSearch = AddElementTag(RootElement, "ARTICLESEARCH");

            AddAttribute(articleSearch, "CONTENTTYPE", asp.ContentType);
            AddAttribute(articleSearch, "SORTBY", asp.SortBy);
            AddAttribute(articleSearch, "SKIPTO", asp.Skip);
            AddAttribute(articleSearch, "SHOW", asp.Show);
            AddAttribute(articleSearch, "DATESEARCHTYPE", asp.DateSearchType);
            AddAttribute(articleSearch, "TIMEINTERVAL", asp.TimeInterval);
            AddAttribute(articleSearch, "ARTICLESTATUS", asp.ArticleStatus);
            AddAttribute(articleSearch, "ARTICLETYPE", asp.ArticleType);
            AddAttribute(articleSearch, "LATITUDE", asp.Latitude);
            AddAttribute(articleSearch, "LONGITUDE", asp.Longitude);
            AddAttribute(articleSearch, "RANGE", asp.Range);
            AddAttribute(articleSearch, "POSTCODE", asp.PostCode);
            AddAttribute(articleSearch, "PLACENAME", asp.Placename);
            AddAttribute(articleSearch, "LOCATIONSEARCHTYPE", asp.LocationSearchType);

            //Add the new descending order attribute
            if (asp.DescendingOrder)
            {
                AddAttribute(articleSearch, "DESCENDINGORDER", 1);
            }
            else
            {
                AddAttribute(articleSearch, "DESCENDINGORDER", 0);
            }

            //Add the requested searchphraselist
            GeneratePhraseXml(asp.SearchPhraseList, (XmlElement)articleSearch);

            //Add Date Search Params if we are doing a date search
            if (asp.DateSearchType != 0)
            {
                AddDateXml(asp.StartDate, articleSearch, "DATERANGESTART");
                // Take a day from the end date as used in the database for UI purposes. 
                // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                // This gets used in the database but for display purposes we subtract a day from the database end date to return the 
                // original dates submitted by the user inorder to match their expectations.
                AddDateXml(asp.EndDate.AddDays(-1), articleSearch, "DATERANGEEND");
            }

            AddTextTag(articleSearch, "FREETEXTSEARCH", asp.FreeTextSearchCondition);

            XmlNode articles = AddElementTag(articleSearch, "ARTICLES");
            int total = 0;
            int count = 0;

            //Generate Hot-List from Search Results.
            PopularPhrases popularPhrases = null;
            if (InputContext.GetSiteOptionValueBool("articlesearch", "generatepopularphrases"))
            {
                popularPhrases = new PopularPhrases();
            }

            if (dataReader.HasRows)
            {
                // process first results set: the Article Key phrase results set
                Dictionary<int, ArrayList> articleKeyPhrases = new Dictionary<int, ArrayList>();
                ArrayList phraselist = new ArrayList();
                int h2g2ID = 0;

                if (dataReader.Read())
                {
                    int previousH2G2ID = 0;

                    do
                    {
                        h2g2ID = dataReader.GetInt32NullAsZero("H2G2ID");

                        if (h2g2ID != previousH2G2ID)
                        {
                            //New now have a new article so clean up the last one
                            if (previousH2G2ID != 0)
                            {
                                articleKeyPhrases.Add(previousH2G2ID, phraselist);
                                phraselist = new ArrayList();
                            }
                        }

                        //set the previous h2g2id to this one
                        previousH2G2ID = h2g2ID;

                        //Create fill an new Phrase object
                        Phrase nameSpacedPhrase = new Phrase();

                        String nameSpace = String.Empty;
                        String phraseName = dataReader.GetStringNullAsEmpty("phrase");

                        if (phraseName != String.Empty)
                        {
                            if (dataReader.Exists("namespace"))
                            {
                                nameSpace = dataReader.GetStringNullAsEmpty("namespace");
                            }
                            nameSpacedPhrase.NameSpace = nameSpace;
                            nameSpacedPhrase.PhraseName = phraseName;

                            //add it to the list
                            phraselist.Add(nameSpacedPhrase);

                            //Record Popular Phrases.
                            if (popularPhrases != null)
                            {
                                popularPhrases.AddPhrase(phraseName, nameSpace);
                            }
                        }

                    } while (dataReader.Read());
                }

                articleKeyPhrases.Add(h2g2ID, phraselist);

                dataReader.NextResult();

                if (dataReader.Read())
                {
                    total = dataReader.GetInt32NullAsZero("TOTAL");

                    //The stored procedure returns one row for each article. The article's keyphrases have been stored in articleKeyPhrases.
                    XmlNode article = CreateElementNode("ARTICLE");
                    do
                    {
                        count++;
                        h2g2ID = dataReader.GetInt32NullAsZero("H2G2ID");

                        //Start filling new article xml
                        AddAttribute(article, "H2G2ID", h2g2ID);

                        int editorID = dataReader.GetInt32NullAsZero("editor");
                        XmlNode editor = CreateElementNode("EDITOR");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, editorID, editor);
                        article.AppendChild(editor);

                        AddTextTag(article, "STATUS", dataReader.GetInt32NullAsZero("status"));
                        AddXmlTextTag(article, "SUBJECT", dataReader.GetStringNullAsEmpty("SUBJECT"));
                        AddTextTag(article, "TYPE", dataReader.GetInt32NullAsZero("type"));

                        AddDateXml(dataReader, article, "DateCreated", "DATECREATED");
                        AddDateXml(dataReader, article, "LastUpdated", "LASTUPDATED");

                        //Add Extra Info XML where it exists.
                        string extraInfo = dataReader.GetAmpersandEscapedStringNullAsEmpty("EXTRAINFO");
                        if (extraInfo != string.Empty)
                        {

                            XmlDocument extraInfoXml = new XmlDocument();
                            extraInfoXml.LoadXml(extraInfo);
                            article.AppendChild(ImportNode(extraInfoXml.FirstChild));

                        }

                        AddTextTag(article, "NUMBEROFPOSTS", dataReader.GetInt32NullAsZero("ForumPostCount"));
                        AddDateXml(dataReader, article, "LASTPOSTED", "FORUMLASTPOSTED");
                        if (!dataReader.IsDBNull("StartDate"))
                        {
                            AddDateXml(dataReader, article, "StartDate", "DATERANGESTART");
                            // Take a day from the end date as stored in the database for UI purposes. 
                            // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                            // This gets stored in the database but for display purposes we subtract a day from the database end date to return the 
                            // original dates submitted by the user inorder to match their expectations.
                            AddDateXml(dataReader.GetDateTime("EndDate").AddDays(-1), article, "DATERANGEEND");

                            AddTextTag(article, "TIMEINTERVAL", dataReader.GetInt32NullAsZero("TimeInterval"));
                        }


                        if (dataReader.DoesFieldExist("BookmarkCount"))
                        {
                            AddTextTag(article, "BOOKMARKCOUNT", dataReader.GetInt32NullAsZero("BookmarkCount"));
                        }

                        if (dataReader.DoesFieldExist("ZeitgeistScore"))
                        {
                            AddElement(article, "ZEITGEIST", "<SCORE>" + dataReader.GetDoubleNullAsZero("ZeitgeistScore") + "</SCORE>");
                        }

                        

                        #region LocationXML
                        //***********************************************************************
                        // Location Info
                        //***********************************************************************
                        if (dataReader.DoesFieldExist("Latitude") && !dataReader.IsDBNull("Latitude"))
                        {
                            AddTextTag(article, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                            AddTextTag(article, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                            if (dataReader.DoesFieldExist("Distance"))
                            {
                                if (dataReader.GetDoubleNullAsZero("Distance") < 0.0001)
                                {
                                    AddTextTag(article, "DISTANCE", "0");
                                }
                                else
                                {
                                    AddTextTag(article, "DISTANCE", dataReader.GetDoubleNullAsZero("Distance").ToString());
                                }
                            }
                            AddTextTag(article, "LOCATIONTITLE", dataReader.GetString("LocationTitle"));
                            AddTextTag(article, "LOCATIONDESCRIPTION", dataReader.GetString("LocationDescription"));
                            AddTextTag(article, "LOCATIONZOOMLEVEL", dataReader.GetInt32NullAsZero("LocationZoomLevel").ToString());
                            AddTextTag(article, "LOCATIONUSERID", dataReader.GetInt32NullAsZero("LocationUserID").ToString());
                            AddDateXml(dataReader.GetDateTime("LocationDateCreated"), article, "LOCATIONDATECREATED");
                        }
                        //***********************************************************************
                        #endregion
                        //***********************************************************************
                        // Media Asset Info
                        //***********************************************************************
                        int mediaAssetID = dataReader.GetInt32NullAsZero("MediaAssetID");

                        if (mediaAssetID != 0)
                        {
                            AddMediaAssetXml(dataReader, article, mediaAssetID);
                        }
                        //***********************************************************************

                        AddPollXml(dataReader, article);

                        if (articleKeyPhrases.ContainsKey(h2g2ID))
                        {
                            GeneratePhraseXml(articleKeyPhrases[h2g2ID], (XmlElement)article);
                        }

                        XmlNode previousarticle = article.CloneNode(true);
                        articles.AppendChild(previousarticle);
                        article.RemoveAll();

                    } while (dataReader.Read());
                }
            }
            articleSearch.AppendChild(articles);
            AddAttribute(articleSearch, "COUNT", count);
            AddAttribute(articleSearch, "TOTAL", total);

            if (popularPhrases != null)
            {
                //Include popularPhrase statistics.
                XmlElement popularPhrasesXml = popularPhrases.GenerateXml();
                articleSearch.AppendChild(ImportNode(popularPhrasesXml));
            }

            FileCache.PutItem(AppContext.TheAppContext.Config.CachePath, "articlesearch", _cacheName, articleSearch.OuterXml);

            //articleSearch.OwnerDocument.Save(@"c:\TEMP\Articlesearch.xml");
        }
Esempio n. 6
0
        /// <summary>
        /// Adds in the key phrase hotlist 
        /// </summary>
        /// <param name="dataReader">Data set to turn into XML</param>
        /// <param name="skip">Number of articles to skip</param>
        /// <param name="show">Number of articles to show</param>
        /// <param name="contentType">Type of articles to articles to search for </param>
        /// <param name="sortBy">sortby option for the search</param>
        private void GenerateArticleSearchHotlistXml(IDnaDataReader dataReader,
            int skip,
            int show,
            int contentType,
            string sortBy)
        {
            int count = 0;
            XmlElement articleSearchHotlist = AddElementTag(RootElement, "ARTICLEHOT-PHRASES");

            AddAttribute(articleSearchHotlist, "CONTENTTYPE", contentType);
            AddAttribute(articleSearchHotlist, "SORTBY", sortBy);
            AddAttribute(articleSearchHotlist, "SKIP", skip);
            AddAttribute(articleSearchHotlist, "SHOW", show);

            if (dataReader.HasRows)
            {
                if (dataReader.Read())
                {
                    count = dataReader.GetInt32NullAsZero("Count");
                    do
                    {
                        XmlElement phrase = AddElementTag(articleSearchHotlist, "ARTICLEHOT-PHRASE");

                        string rawPhrase = dataReader.GetStringNullAsEmpty("phrase");

                        //If phrase contains token then quote.
                        string URLPhrase = rawPhrase;
                        if (rawPhrase.Contains(_token))
                        {
                            URLPhrase = "" + rawPhrase + "";
                        }

                        AddTextElement(phrase, "NAME", StringUtils.EscapeAllXml(rawPhrase));
                        AddTextElement(phrase, "TERM", Uri.EscapeDataString(URLPhrase));
                        AddTextElement(phrase, "RANK", (dataReader.GetDoubleNullAsZero("Rank")).ToString());

                    } while (dataReader.Read());
                }
            }
            AddAttribute(articleSearchHotlist, "COUNT", count.ToString());
            if (count > skip + show)
            {
                AddAttribute(articleSearchHotlist, "MORE", 1);
            }
            else
            {
                AddAttribute(articleSearchHotlist, "MORE", 0);
            }

            FileCache.PutItem(AppContext.TheAppContext.Config.CachePath, "articlekeyphrase", _cacheName, articleSearchHotlist.OuterXml);
        }
Esempio n. 7
0
        /// <summary>
        /// Helper method to create the list after a specific stored procedure
		///		has been called to return an appropriate results set.
        /// </summary>
        /// <param name="articleList"></param>
        /// <param name="dataReader"></param>
        /// <param name="skip">Number of Articles to skip</param>
        /// <param name="show">Number of Articles to show</param>
        /// <returns></returns>
        public int CreateList(XmlElement articleList, IDnaDataReader dataReader, int skip, int show)
        {
            int count = show;
            bool records = true;

            //Read/skip over the skip number of rows so that the row that the first row that in the do below is 
            //the one required
            for (int i = 0; i < skip; i++)
            {
                records = dataReader.Read();
                if (!records)
                {
                    break;
                }
            }

            if (records)
            {
                do
                {
                    // Setup the article
                    XmlElement article = AddElementTag(articleList, "ARTICLE");

                    if (dataReader.DoesFieldExist("EntryID"))
                    {
                        AddIntElement(article, "ENTRY-ID", dataReader.GetInt32NullAsZero("EntryID"));
                    }
                    if (dataReader.DoesFieldExist("h2g2ID"))
                    {
                        AddAttribute(article, "H2G2ID", dataReader.GetInt32NullAsZero("h2g2ID"));
                        //TODO: remove the H2G2-ID from all schemas and skins...
                        AddIntElement(article, "H2G2-ID", dataReader.GetInt32NullAsZero("h2g2ID"));
                    }
                    if (dataReader.DoesFieldExist("SiteID"))
                    {
                        AddIntElement(article, "SITEID", dataReader.GetInt32NullAsZero("SiteID"));
                    }
                    if (dataReader.DoesFieldExist("RecommendationID"))
                    {
                        AddIntElement(article, "RECOMMENDATION-ID", dataReader.GetInt32NullAsZero("RecommendationID"));
                    }
                    if (dataReader.DoesFieldExist("NotificationSent"))
                    {
                        AddIntElement(article, "NOTIFIED", dataReader.GetBoolean("NotificationSent") ? 1 : 0);
                    }

                    User user = new User(InputContext);
                    if (dataReader.DoesFieldExist("Editor"))
                    {
                        // place all user details within a USER tag and structure them appropriately
                        // editor info
                        int editorID = dataReader.GetInt32NullAsZero("Editor");
                        XmlElement editorTag = AddElementTag(article, "EDITOR");
                        user.AddPrefixedUserXMLBlock(dataReader, editorID, "Editor", editorTag);
                    }

                    if (dataReader.DoesFieldExist("AuthorID"))
                    {
                        // author info
                        int authorID = dataReader.GetInt32NullAsZero("AuthorID");
                        XmlElement authorTag = AddElementTag(article, "AUTHOR");
                        user.AddPrefixedUserXMLBlock(dataReader, authorID, "Author", authorTag);
                    }

                    if (dataReader.DoesFieldExist("AcceptorID"))
                    {
                        // acceptor info (user that accepted a recommendation)
                        int acceptorID = dataReader.GetInt32NullAsZero("AcceptorID");
                        XmlElement acceptorTag = AddElementTag(article, "ACCEPTOR");
                        user.AddPrefixedUserXMLBlock(dataReader, acceptorID, "Acceptor", acceptorTag);
                    }

                    if (dataReader.DoesFieldExist("AllocatorID"))
                    {
                        // allocator info (user that allocated a recommendation to a sub)
                        int allocatorID = dataReader.GetInt32NullAsZero("AllocatorID");
                        XmlElement allocatorTag = AddElementTag(article, "ALLOCATOR");
                        user.AddPrefixedUserXMLBlock(dataReader, allocatorID, "Allocator", allocatorTag);
                    }

                    if (dataReader.DoesFieldExist("ScoutID"))
                    {
                        // scout info
                        int scoutID = dataReader.GetInt32NullAsZero("ScoutID");
                        XmlElement scoutTag = AddElementTag(article, "SCOUT");
                        user.AddPrefixedUserXMLBlock(dataReader, scoutID, "Scout", scoutTag);
                    }

                    if (dataReader.DoesFieldExist("SubEditorID"))
                    {
                        // sub editor info
                        int subEditorID = dataReader.GetInt32NullAsZero("SubEditorID");
                        XmlElement subEditorTag = AddElementTag(article, "SUBEDITOR");
                        user.AddPrefixedUserXMLBlock(dataReader, subEditorID, "SubEditor", subEditorTag);
                    }

                    if (dataReader.DoesFieldExist("Status"))
                    {
                        AddIntElement(article, "STATUS", dataReader.GetInt32NullAsZero("Status"));
                    }
                    if (dataReader.DoesFieldExist("RecommendationStatus"))
                    {
                        AddIntElement(article, "RECOMMENDATION-STATUS", dataReader.GetInt32NullAsZero("RecommendationStatus"));
                    }
                    if (dataReader.DoesFieldExist("SubbingStatus"))
                    {
                        AddIntElement(article, "SUBBING-STATUS", dataReader.GetInt32NullAsZero("SubbingStatus"));
                    }
                    if (dataReader.DoesFieldExist("Style"))
                    {
                        AddIntElement(article, "STYLE", dataReader.GetInt32NullAsZero("Style"));
                    }

                    if (dataReader.DoesFieldExist("Subject"))
                    {
                        AddTextTag(article, "SUBJECT", dataReader.GetStringNullAsEmpty("Subject"));
                    }

                    if (dataReader.DoesFieldExist("DateCreated"))
                    {
                        AddDateXml(dataReader, article, "DateCreated", "DATE-CREATED");
                    }
                    if (dataReader.DoesFieldExist("LastUpdated"))
                    {
                        AddDateXml(dataReader, article, "LastUpdated", "LASTUPDATED");
                    }
                    if (dataReader.DoesFieldExist("DateRecommended"))
                    {
                        AddDateXml(dataReader, article, "DateRecommended", "DATE-RECOMMENDED");
                    }
                    if (dataReader.DoesFieldExist("DecisionDate"))
                    {
                        AddDateXml(dataReader, article, "DecisionDate", "RECOMMENDATION-DECISION-DATE");
                    }
                    if (dataReader.DoesFieldExist("DateAllocated"))
                    {
                        AddDateXml(dataReader, article, "DateAllocated", "DATE-ALLOCATED");
                    }
                    if (dataReader.DoesFieldExist("DateReturned"))
                    {
                        AddDateXml(dataReader, article, "DateReturned", "DATE-RETURNED");
                    }

                    //TODO add Extra Info correctly
                    if (dataReader.DoesFieldExist("ExtraInfo"))
                    {
                        //Add Extra Info XML where it exists.
                        string extraInfo = dataReader.GetAmpersandEscapedStringNullAsEmpty("ExtraInfo");
                        if (extraInfo != string.Empty)
                        {
                            XmlDocument extraInfoXml = new XmlDocument();
                            extraInfoXml.LoadXml(extraInfo);
                            article.AppendChild(ImportNode(extraInfoXml.FirstChild));
                        }

                        //TODO Use Extra Info Class will need to change SP to get out the guide entry Type
                        //ExtraInfo extraInfo = new ExtraInfo();
                        //extraInfo.TryCreate(dataReader.GetInt32NullAsZero("Type"), dataReader.GetStringNullAsEmpty("ExtraInfo"));
                        //AddInside(article, extraInfo);
                    }

                    if (dataReader.DoesFieldExist("ForumPostCount"))
                    {
                        AddIntElement(article, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("ForumPostCount"));
                        AddIntElement(article, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit"));
                    }

                    if (dataReader.DoesFieldExist("StartDate") && !dataReader.IsDBNull("StartDate"))
                    {
                        AddDateXml(dataReader, article, "StartDate", "DATERANGESTART");
                    }
                    // Take a day from the end date as stored in the database for UI purposes. 
                    // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                    // This gets stored in the database but for display purposes we subtract a day from the database end date to return the 
                    // original dates submitted by the user inorder to match their expectations.
                    if (dataReader.DoesFieldExist("EndDate") && !dataReader.IsDBNull("EndDate"))
                    {
                        AddDateXml(dataReader.GetDateTime("EndDate").AddDays(-1), article, "DATERANGEEND");
                    }

                    if (dataReader.DoesFieldExist("TimeInterval"))
                    {
                        AddIntElement(article, "TIMEINTERVAL", dataReader.GetInt32NullAsZero("TimeInterval"));
                    }

                    if (dataReader.DoesFieldExist("LASTPOSTED"))
                    {
                        AddDateXml(dataReader, article, "LASTPOSTED", "FORUMLASTPOSTED");
                    }
                    //////////


                    if (dataReader.DoesFieldExist("BookmarkCount"))
                    {
                        AddTextTag(article, "BOOKMARKCOUNT", dataReader.GetInt32NullAsZero("BookmarkCount"));
                    }

                    if (dataReader.DoesFieldExist("ZeitgeistScore"))
                    {
                        AddElement(article, "ZEITGEIST", "<SCORE>" + dataReader.GetDoubleNullAsZero("ZeitgeistScore") + "</SCORE>");
                    }

                    #region LocationXML
                    //***********************************************************************
                    // Location Info
                    //***********************************************************************
                    if (dataReader.DoesFieldExist("Latitude") && !dataReader.IsDBNull("Latitude"))
                    {
                        AddTextTag(article, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                        AddTextTag(article, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                        if (dataReader.DoesFieldExist("Distance"))
                        {
                            if (dataReader.GetDoubleNullAsZero("Distance") < 0.0001)
                            {
                                AddTextTag(article, "DISTANCE", "0");
                            }
                            else
                            {
                                AddTextTag(article, "DISTANCE", dataReader.GetDoubleNullAsZero("Distance").ToString());
                            }
                        }
                        AddTextTag(article, "LOCATIONTITLE", dataReader.GetString("LocationTitle"));
                        AddTextTag(article, "LOCATIONDESCRIPTION", dataReader.GetString("LocationDescription"));
                        AddTextTag(article, "LOCATIONZOOMLEVEL", dataReader.GetInt32NullAsZero("LocationZoomLevel").ToString());
                        AddTextTag(article, "LOCATIONUSERID", dataReader.GetInt32NullAsZero("LocationUserID").ToString());
                        AddDateXml(dataReader.GetDateTime("LocationDateCreated"), article, "LOCATIONDATECREATED");
                    }
                    //***********************************************************************
                    #endregion

                    if (dataReader.DoesFieldExist("MediaAssetID"))
                    {
                        AddMediaAssetXml(dataReader, article, dataReader.GetInt32NullAsZero("MediaAssetID"));
                    }

                    if (dataReader.DoesFieldExist("CRPollID"))
                    {
                        AddPollXml(dataReader, article);
                    }



                    count--;

                } while (count > 0 && dataReader.Read());	// dataReader.Read won't get called if count == 0

                // See if there's an extra row waiting
                if (count == 0 && dataReader.Read())
                {
                    AddAttribute(articleList, "MORE", 1);
                }
            }
            return count;
        }
Esempio n. 8
0
        /// <summary>
        /// CreateRouteXML from a dataReader.
        /// Allows standard Route XML to be generated from different resultsets.
        /// </summary>
        /// <param name="dataReader"></param>
        /// <param name="includeLocations">Whether the locations need to be included or just route info</param>
        public void CreateRouteXML(IDnaDataReader dataReader, bool includeLocations)
        {
            int count = 0;
            XmlElement routeXML = (XmlElement) AddElementTag(RootElement, "ROUTE");

            if (dataReader.HasRows && dataReader.DoesFieldExist("RouteID"))
            {
                AddAttribute(routeXML, "ROUTEID", dataReader.GetInt32NullAsZero("RouteID").ToString());

                AddTextTag(routeXML, "ROUTETITLE", dataReader.GetStringNullAsEmpty("RouteTitle"));
                AddTextTag(routeXML, "ROUTEDESCRIPTION", dataReader.GetStringNullAsEmpty("RouteDescription"));
                AddTextTag(routeXML, "DESCRIBINGARTICLEID", dataReader.GetInt32NullAsZero("H2G2ID").ToString());
                AddTextTag(routeXML, "SUBJECT", dataReader.GetStringNullAsEmpty("Subject"));
                //AddTextTag(routeXML, "GPSTRACKDATALOCATION", dataReader.GetStringNullAsEmpty("GPSTRACKDATALOCATION"));

                if (includeLocations)
                {
                    XmlElement locations = AddElementTag(routeXML, "LOCATIONS");
                    if (dataReader.NextResult() && dataReader.Read())
                    {
                        do
                        {
                            count++;
                            XmlElement location = AddElementTag(locations, "LOCATION");
                            location.SetAttribute("LOCATIONID", dataReader.GetInt32NullAsZero("LocationID").ToString());
                            location.SetAttribute("ORDER", dataReader.GetInt32NullAsZero("Order").ToString());

                            AddTextTag(location, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                            AddTextTag(location, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                            AddTextTag(location, "LOCATIONTITLE", dataReader.GetStringNullAsEmpty("LocationTitle"));
                            AddTextTag(location, "LOCATIONDESCRIPTION", dataReader.GetStringNullAsEmpty("LocationDescription"));
                            AddTextTag(location, "LOCATIONZOOMLEVEL", dataReader.GetInt32NullAsZero("LocationZoomLevel").ToString());
                            AddTextTag(location, "LOCATIONUSERID", dataReader.GetInt32NullAsZero("LocationUserID").ToString());
                            AddDateXml(dataReader.GetDateTime("LocationDateCreated"), location, "LOCATIONDATECREATED");
                        } while (dataReader.Read());
                    }
                    AddAttribute(locations, "COUNT", count.ToString());
                }
            }
        }