示例#1
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");
        }
示例#2
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;
        }