/// <summary>
        /// Functions generates the User Subscription List
        /// </summary>
        /// <param name="userID">The user requesting their subscriptions</param>
        /// <param name="siteID">The site the user is getting their subscriptions from</param>
        /// <param name="skip">number of articles to skip</param>
        /// <param name="show">number of articles to show</param>
        /// <returns>Success</returns>
        public bool CreateArticleSubscriptionsList(int userID, int siteID, int skip, int show)
        {
            RootElement.RemoveAll();
            XmlElement articleSubscriptionsList = AddElementTag(RootElement, "ARTICLESUBSCRIPTIONLIST");
            AddAttribute(articleSubscriptionsList, "SKIP", skip);
            AddAttribute(articleSubscriptionsList, "SHOW", show);

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

            using (IDnaDataReader dataReader = GetArticleSubscriptionList(userID, siteID, skip + 1, show))	// Add 1 to skip because row number starts at 1.
            {
                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);
                            }

                        } 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);

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

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

                            //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));
                            }

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

                            AddTextTag(article, "NUMBEROFPOSTS", dataReader.GetInt32NullAsZero("ForumPostCount"));

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

                            if (!dataReader.IsDBNull("StartDate"))
                            {
                                AddDateXml(dataReader, article, "StartDate", "DATERANGESTART");
                                DateTime articlesDateRangeEnd = dataReader.GetDateTime("EndDate");
                                if (InputContext.GetSiteOptionValueBool(dataReader.GetInt32NullAsZero("SiteID"), "GuideEntries", "InclusiveDateRange"))
                                {
                                    // take a minute from the end date as stored in the database so to match user's expectations. 
                                    // I.e. If SiteOption InclusiveDateRange is true user will have submitted a date range like 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 but for display purposes expect the 
                                    // end date to be 02/09/1980. 02/09/1980 23:59 is therefore returned. 
                                    TimeSpan minute = new TimeSpan(0, 1, 0);
                                    AddDateXml(articlesDateRangeEnd.Subtract(minute), article, "DATERANGEEND");
                                }
                                else
                                {
                                    AddDateXml(articlesDateRangeEnd, article, "DATERANGEEND");
                                }

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

                            if (dataReader.DoesFieldExist("Latitude") && !dataReader.IsDBNull("Latitude"))
                            {
                                AddTextTag(article, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                            }
                            if (dataReader.DoesFieldExist("Longitude") && !dataReader.IsDBNull("Longitude"))
                            {
                                AddTextTag(article, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                            }
                            if (dataReader.DoesFieldExist("Distance") && !dataReader.IsDBNull("Distance"))
                            {
                                AddTextTag(article, "DISTANCE", dataReader.GetDoubleNullAsZero("Distance").ToString());
                            }

                            //***********************************************************************
                            // 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());
                    }
                }
                articleSubscriptionsList.AppendChild(articles);
            }
            AddAttribute(articleSubscriptionsList, "COUNT", count);
            AddAttribute(articleSubscriptionsList, "TOTAL", total);

            return true;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the article members node for a given ID
        /// </summary>
        /// <param name="nodeID">The hierarchy node</param>
        /// <param name="type">The hierarchy node type</param>
        /// <param name="show">The number of rows to show</param>
        /// <param name="skip">The number of rows to skip</param>
        /// <param name="rows">The number of rows so far which is updated</param>
        /// <returns>Element containing the article members XML</returns>
        public XmlElement GetArticleMembersForNodeID(int nodeID, int type, int show, int skip, ref int rows)
        {
            // Check the NodeID!
            if (nodeID == 0)
            {
                throw new DnaException("Category - NoNodeIDGiven - Illegal NodeID (0)");
            }

            XmlElement nodeAliasMemberList = CreateElement("NODEALIASMEMBERLIST");

            int userTaxonomyNodeID = 0;
            // Now get the node articles for the given list id
            bool needMediaAssetInfo = false;
            bool includeKeyPhraseData = false;

            needMediaAssetInfo = InputContext.GetSiteOptionValueBool("MediaAsset", "ReturnInCategoryList");

            includeKeyPhraseData = InputContext.GetSiteOptionValueBool("KeyPhrases", "ReturnInCategoryList");

            string storedProcedureName = String.Empty;
            if (includeKeyPhraseData)
            {
                storedProcedureName = "getarticlesinhierarchynodewithkeyphrases";
            }
            else
            {
                if (InputContext.CurrentSite.IncludeCrumbtrail == 1)
                {
                    if (needMediaAssetInfo)
                    {
                        storedProcedureName = "getarticlesinhierarchynodewithlocalwithmediaassets";
                    }
                    else
                    {
                        storedProcedureName = "getarticlesinhierarchynodewithlocal";
                    }
                }
                else
                {

                    if (needMediaAssetInfo)
                    {
                        storedProcedureName = "getarticlesinhierarchynodewithmediaassets";
                    }
                    else
                    {
                        storedProcedureName = "getarticlesinhierarchynode";
                    }
                }
            }  

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader(storedProcedureName))
            {
                dataReader.AddParameter("nodeid", nodeID);
                dataReader.AddParameter("type", type);
                dataReader.AddParameter("maxresults", skip + show);
                dataReader.AddParameter("currentsiteid", InputContext.CurrentSite.SiteID);

                if (includeKeyPhraseData)
                {
                    if (needMediaAssetInfo)
                    {
                        dataReader.AddParameter("showmediaassetdata", 1);
                    }
                    else
                    {
                        dataReader.AddParameter("showmediaassetdata", 0);
                    }
                }
                else
                {
                    dataReader.AddParameter("showcontentratingdata", 1);
                    if (InputContext.CurrentSite.IncludeCrumbtrail == 1)
                    {
                        userTaxonomyNodeID = 0;// InputContext.ViewingUser.TaxonomyNode;

                        dataReader.AddParameter("usernodeid", userTaxonomyNodeID);
                    }
                }  

                dataReader.Execute();

	            //Process the keyphrases DataSet first map of entry IDs to phrases
	            Dictionary<int, List<Phrase>> articleKeyPhrases = new Dictionary<int,List<Phrase>>(); 

	            if (includeKeyPhraseData)
	            {
		            List<Phrase> phraselist = new List<Phrase>();
		            int articleCount=0;
		            int prevEntryID=0;
		            int thisEntryID=prevEntryID;

		            if(dataReader.HasRows && dataReader.Read())
		            {
			            if (skip > 0)
			            {
				            //Skips the number of articles in the returned key phrases
				            do
				            {
					            thisEntryID = dataReader.GetInt32NullAsZero("EntryID");
					            if(prevEntryID == 0) //The first time
					            {
						            prevEntryID = thisEntryID;
					            }
					            if(thisEntryID != prevEntryID)
					            {
						            prevEntryID = thisEntryID;
						            articleCount++;
					            }
				            } while (dataReader.Read() && articleCount < skip);
			            }

			            prevEntryID = 0;
			            //Now generates the list of phrases matching the entry id of the article
			            do
			            {
				            thisEntryID = dataReader.GetInt32NullAsZero("EntryID");
				            if(prevEntryID == 0) //The first time
				            {
					            prevEntryID = thisEntryID;
				            }
				            if(thisEntryID != prevEntryID)
				            {
					            articleKeyPhrases.Add(prevEntryID, phraselist);
					            phraselist.Clear();
					            prevEntryID = thisEntryID;				
				            }

				            string phrase = "";
				            string phraseNamespace = "";
            				
				            if(dataReader.DoesFieldExist("Phrase") && !dataReader.IsDBNull("Phrase"))
				            {
					            phrase = dataReader.GetStringNullAsEmpty("Phrase");

					            if(dataReader.DoesFieldExist("Namespace") && !dataReader.IsDBNull("Namespace"))
					            {
                                    phraseNamespace = dataReader.GetStringNullAsEmpty("Namespace");
					            }
            					
					            Phrase phraseObject = new Phrase(phrase, phraseNamespace);

                                phraselist.Add(phraseObject);
				            }

			            } while (dataReader.Read());
		            }
                    //We have the keyphrases now move onto the next recordset with the actual articles
            		dataReader.NextResult();
	            }
            	
	            if (skip > 0)
	            {
                    //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++)
                    {
                        dataReader.Read();
                    }
	            }

	            int thisType = 0;
	            int prevType = -1;
	            Dictionary<int,int> typeCounts = new Dictionary<int,int>();
	            if(dataReader.HasRows)
	            {
                    while(dataReader.Read() && show > 0)
                    {
                        nodeAliasMemberList.AppendChild(AddArticleMemberXML(dataReader, articleKeyPhrases));
                		
		                //Record the count for each type.
                        thisType = dataReader.GetInt32NullAsZero("Type");
                        if (prevType != thisType)
		                {
                            typeCounts[thisType] = dataReader.GetInt32NullAsZero("TypeCount");
                            prevType = thisType;
		                }

		                if ( skip > 0  )
		                {
			                show--;
			                if ( show == 0 )
			                {
				                break;
			                }
		                }				
	                }
                }

	            //Add the count information.
	            foreach(KeyValuePair<int,int> articleMemberCount in typeCounts)
	            {
                    XmlElement articleMemberCountXML = (XmlElement) AddTextTag(nodeAliasMemberList, "ARTICLEMEMBERCOUNT", articleMemberCount.Value);
                    AddAttribute(articleMemberCountXML, "TYPE", articleMemberCount.Key);

                    rows += articleMemberCount.Value;
	            }
            }
            return nodeAliasMemberList;
        }
Esempio n. 3
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. 4
0
        /// <summary>
        /// Gets the params for the page
        /// </summary>
        /// <param name="asp">Class containing all the search parameters.</param>
        private bool TryGetPageParams(ref ArticleSearchParams asp)
        {
            int startDay = 0;
            int startMonth = 0;
            int startYear = 0;
            int endDay = 0;
            int endMonth = 0;
            int endYear = 0;

            string startDateText = String.Empty;
            string endDateText = String.Empty;

            //siteID = InputContext.GetParamIntOrZero("siteid", _docDnaSiteID);
            asp.SiteID = InputContext.CurrentSite.SiteID;

            int defaultShow = InputContext.GetSiteOptionValueInt("ArticleSearch", "DefaultShow");

            asp.Skip = InputContext.GetParamIntOrZero("skip", _docDnaSkip);
            asp.Show = InputContext.GetParamIntOrZero("show", _docDnaShow);
            if (asp.Show > 200)
            {
                asp.Show = 200;
            }
            else if (asp.Show < 1)
            {
                asp.Show = defaultShow;
            }

            asp.SkipPhrases = InputContext.GetParamIntOrZero("skipphrases", _docDnaSkipPhrases);
            asp.ShowPhrases = InputContext.GetParamIntOrZero("showphrases", _docDnaShowPhrases);
            if (asp.ShowPhrases > 200)
            {
                asp.ShowPhrases = 200;
            }
            else if (asp.ShowPhrases < 1)
            {
                asp.ShowPhrases = defaultShow;
            }
            if (asp.SkipPhrases < 1)
            {
                asp.SkipPhrases = 0;
            }

            asp.ContentType = InputContext.GetParamIntOrZero("contenttype", _docDnaContentType);
            asp.SortBy = InputContext.GetParamStringOrEmpty("articlesortby", _docDnaArticleSortBy);
            asp.DateSearchType = InputContext.GetParamIntOrZero("datesearchtype", _docDnaDateSearchType);

            asp.TimeInterval = InputContext.GetParamIntOrZero("timeinterval", _docDnaTimeInterval);

            startDay = InputContext.GetParamIntOrZero("startDay", _docDnaStartDay);
            startMonth = InputContext.GetParamIntOrZero("startMonth", _docDnaStartMonth);
            startYear = InputContext.GetParamIntOrZero("startYear", _docDnaStartYear);

            endDay = InputContext.GetParamIntOrZero("endDay", _docDnaEndDay);
            endMonth = InputContext.GetParamIntOrZero("endMonth", _docDnaEndMonth);
            endYear = InputContext.GetParamIntOrZero("endYear", _docDnaEndYear);

            startDateText = InputContext.GetParamStringOrEmpty("startDate", _docDnaStartDate);
            endDateText = InputContext.GetParamStringOrEmpty("endDate", _docDnaEndDate);

            asp.ArticleStatus = InputContext.GetParamIntOrZero("articlestatus", _docDnaArticleStatus);
            asp.ArticleType = InputContext.GetParamIntOrZero("articletype", _docDnaArticleType);

            int descendingOrderNum = InputContext.GetParamIntOrZero("descendingorder", _docDnaDescendingOrder);
            if (descendingOrderNum == 1)
            {
                asp.DescendingOrder = true;
            }
            else
            {
                asp.DescendingOrder = false;
            }

            DateTime startDate;
            DateTime endDate;

            if (asp.DateSearchType != 0)
            {
                DateRangeValidation dateValidation = new DateRangeValidation();
                DateRangeValidation.ValidationResult isValid;
                if (startDay == 0 && endDay == 0)
                {
                    isValid = ParseDateParams(startDateText, endDateText, out startDate, out endDate);
                }
                else
                {
                    isValid = ParseDateParams(startYear, startMonth, startDay, endYear, endMonth, endDay, out startDate, out endDate);
                }

                isValid = dateValidation.ValidateDateRange(startDate, endDate, asp.TimeInterval, false, false);

                if (isValid == DateRangeValidation.ValidationResult.VALID)
                {
                    asp.StartDate = dateValidation.LastStartDate;
                    asp.EndDate = dateValidation.LastEndDate;
                }
                else
                {
                    return AddErrorXml("invalidparameters", "Illegal date parameters (" + isValid.ToString() + ")", null);
                }
            }

            //Get Search phrases.
            if (InputContext.DoesParamExist("phrase", _docDnaPhrase))
            {
                asp.SearchPhraseList.Clear();

                string rawPhrases = String.Empty;
                for (int i = 0; i < InputContext.GetParamCountOrZero("phrase", _docDnaPhrase); i++)
                {
                    string phrase = InputContext.GetParamStringOrEmpty("phrase", i, _docDnaPhrase);
                    if (phrase.Contains(_token))
                    {
                        DnaStringParser paramParser = new DnaStringParser(phrase, _token.ToCharArray(), false, false, false);
                        ArrayList paramPhraseList = paramParser.ParseToArrayList();
                        foreach (string paramPhrase in paramPhraseList)
                        {
                            rawPhrases = rawPhrases + paramPhrase + "|";
                        }
                    }
                    else
                    {
                        rawPhrases = rawPhrases + phrase + "|";
                    }
                }

                string rawNameSpaces = String.Empty;
                for (int i = 0; i < InputContext.GetParamCountOrZero("namespace", _docDnaNameSpace); i++)
                {
                    string nameSpace = InputContext.GetParamStringOrEmpty("namespace", i, _docDnaNameSpace);
                    if (nameSpace.Contains(_token))
                    {
                        DnaStringParser paramParser = new DnaStringParser(nameSpace, _token.ToCharArray(), false, false, false);
                        ArrayList paramNameList = paramParser.ParseToArrayList();
                        foreach (string paramNameSpace in paramNameList)
                        {
                            rawNameSpaces = rawNameSpaces + paramNameSpace + "|";
                        }
                    }
                    else
                    {
                        rawNameSpaces = rawNameSpaces + nameSpace + "|";
                    }
                }

                char[] charsToTrim = new char[] { '|' };

                string parsedPhrases = String.Empty;
                //Now feed it into the DnaString Parser
                DnaStringParser phrasesParser = new DnaStringParser(rawPhrases, charsToTrim, true, true, false);
                parsedPhrases = phrasesParser.GetParsedString('|');
                ArrayList searchPhraseList = phrasesParser.ParseToArrayList();

                string parsedNameSpaces = String.Empty;
                //Now feed it into the DnaString Parser
                DnaStringParser nameSpaceParser = new DnaStringParser(rawNameSpaces, charsToTrim, true, true, false);
                parsedNameSpaces = nameSpaceParser.GetParsedString('|');
                ArrayList searchNameSpaceList = nameSpaceParser.ParseToArrayList();

                int phraseNumber = 0;
                foreach (string phraseText in searchPhraseList)
                {
                    Phrase phrase = new Phrase();
                    phrase.PhraseName = phraseText;
                    try
                    {
                        phrase.NameSpace = searchNameSpaceList[phraseNumber].ToString();
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        phrase.NameSpace = "";
                    }

                    asp.SearchPhraseList.Add(phrase);
                    phraseNumber++;
                }

                asp.Phrases = parsedPhrases.TrimEnd(charsToTrim);
                asp.NameSpaces = parsedNameSpaces.TrimEnd(charsToTrim);
            }

            //Get (Postcode or Placename or Latitude and Longitude) and Range for Search if they are there.
            if (InputContext.DoesParamExist("postcode", _docDnaPostcode) ||
                InputContext.DoesParamExist("placename", _docDnaPlacename) ||
                (InputContext.DoesParamExist("latitude", _docDnaLatitude) &&
                InputContext.DoesParamExist("longitude", _docDnaLongitude)) &&
                InputContext.DoesParamExist("range", _docDnaRange))
            {
                asp.Range = InputContext.GetParamDoubleOrZero("range", _docDnaRange);

                asp.LocationSearchType = InputContext.GetParamStringOrEmpty("locationsearchtype", _docDnaLocationSearchType);
                asp.PostCode = InputContext.GetParamStringOrEmpty("postcode", _docDnaPostcode);
                asp.Placename = InputContext.GetParamStringOrEmpty("placename", _docDnaPlacename);

                double latitude = InputContext.GetParamDoubleOrZero("latitude", _docDnaLatitude); 
                double longitude = InputContext.GetParamDoubleOrZero("longitude", _docDnaLongitude);
                if (asp.LocationSearchType == "postcode")
                {
                    GetLatLongFromPostCode(asp.PostCode, ref latitude, ref longitude);
                }
                else if (asp.LocationSearchType == "placename")
                {
                    GetLatLongFromPlacename(asp.Placename, ref latitude, ref longitude);
                }
                asp.Latitude = latitude;
                asp.Longitude = longitude;
            }

            //Get free text search condition for Search if it is there.
            if (InputContext.DoesParamExist("freetextsearch", _docDnaFreeTextSearchCondition))
            {
                asp.FreeTextSearchCondition = InputContext.GetParamStringOrEmpty("freetextsearch", _docDnaFreeTextSearchCondition);
            }

            return true;
        }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
		public ListDefinition(string SiteURLName, string sXML )
		{
			this.SiteURLName = SiteURLName;

			// Load list definition from xml
			XmlDocument xmldoc = new XmlDocument();
			xmldoc.LoadXml(sXML);
			XmlNode xmlNde;
			
			// name
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/NAME")) != null)
				xmlListName = xmlNde.InnerText;
			

			// LISTLENGTH
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/LISTLENGTH")) != null)
				xmlLength = xmlNde.InnerText;
			else
				xmlLength = "50";

			// TYPE
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/TYPE")) != null)
				xmlType = xmlNde.InnerText;

			// ARTICLETYPE
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/ARTICLETYPE")) != null)
				xmlArticleType = xmlNde.InnerText;

            //Article Date Range Start
            if ((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/ARTICLESTARTDATE")) != null)
                xmlArticleStartDate = xmlNde.InnerText;

            //Article Date Range End
            if ((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/ARTICLEENDDATE")) != null)
                xmlArticleEndDate = xmlNde.InnerText;

			// STATUS
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/STATUS")) != null)
				xmlStatus = xmlNde.InnerText;
			 
			// RATING
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/RATING")) != null)
				xmlRating = xmlNde.InnerText;

            // BookMarks
            if ((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/BOOKMARKCOUNT")) != null)
                xmlBookmarkCount = xmlNde.InnerText;

			// SIGNIFICANCE
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/SIGNIFICANCE")) != null)
				xmlScore = xmlNde.InnerText;

			// DATECREATED
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/DATECREATED")) != null)
				xmlDateCreated = xmlNde.InnerText;
			
			// LASTUPDATED
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/LASTUPDATED")) != null)
				xmlLastUpdated = xmlNde.InnerText;

			// SORTBY
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/SORTBY")) != null)
				xmlOrderBy = xmlNde.InnerText;

            // Comment Forum UID Prefix
            if ((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/COMMENTFORUMUIDPREFIX")) != null)
                xmlUIDPrefix = xmlNde.InnerText;

			// CATEGORIES/CATEGORY/ID
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/CATEGORIES")) != null)
			{
				XmlNodeList xmlNdeLst = xmlNde.SelectNodes("CATEGORY/ID");
				if(xmlNdeLst != null && xmlNdeLst.Count > 0)
				{
					xmlCategories = new string[xmlNdeLst.Count];
					int i=0;
					foreach(XmlNode xmlCatNde in xmlNdeLst)
					{
						xmlCategories[i++] = xmlCatNde.InnerText;
					}
				}
			}

            //Get Array of Key Phrases from XML
            if ( (xmlNde = xmldoc.SelectSingleNode(@"LISTDEFINITION/KEYPHRASES")) != null )
            {
                
                XmlNodeList xmlNdeLst = xmlNde.SelectNodes(@"PHRASE");
                if ( xmlNdeLst != null && xmlNdeLst.Count > 0 )
                {
                    xmlKeyPhrases = new List<Phrase>(xmlNdeLst.Count);
					foreach(XmlNode xmlPhraseNde in xmlNdeLst)
					{
                            
                        XmlNode nameNode = xmlPhraseNde.SelectSingleNode("NAME");
                        XmlNode nspaceNode = xmlPhraseNde.SelectSingleNode("NAMESPACE");

                        Phrase phrase = new Phrase();
                        if (nspaceNode != null)
                        {
                            phrase.NameSpace = nspaceNode.InnerText;
                        }

                        if (nameNode != null)
                        {
                            phrase.PhraseName = nameNode.InnerText;
                        }
                        else
                        {
                            //Legacy XML schema support.
                            phrase.PhraseName = xmlPhraseNde.InnerText;
                        }
                        
						xmlKeyPhrases.Add(phrase);
					}
                }
            }

			// VOTECOUNT
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/VOTECOUNT")) != null)
				xmlVoteCount = xmlNde.InnerText;

			// THREADTYPE
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/THREADTYPE")) != null)
				xmlThreadType = xmlNde.InnerText;

			// EVENTDATE
			if((xmlNde = xmldoc.SelectSingleNode("LISTDEFINITION/EVENTDATE")) != null)
				xmlEventDate = xmlNde.InnerText;
		}
Esempio n. 6
0
        /// <summary>
        /// Implements an Article Search.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="showApproved"></param>
        /// <param name="showNormal"></param>
        /// <param name="showSubmitted"></param>
        /// <param name="showContentRating"></param>
        /// <param name="showPhrases"></param>
        /// <param name="userGroups"></param>
        /// <param name="skip"></param>
        /// <param name="show"></param>
        /// <param name="nodeId"></param>
        /// <param name="articleType"></param>
        /// <param name="useFreeTextSearch"></param>
        /// <returns></returns>
        public bool ArticleSearch(string query, bool showApproved, bool showNormal, bool showSubmitted, bool showContentRating, bool showPhrases, string userGroups, int skip, int show, int nodeId, int articleType, bool useFreeTextSearch )
        {
            XmlElement searchResults = AddElementTag(_searchElement, "SEARCHRESULTS");
            AddAttribute(searchResults, "TYPE", "ARTICLE");
            AddTextElement(searchResults, "SEARCHTERM", query);

            AddIntElement(searchResults, "SHOWAPPROVED", Convert.ToInt32(showApproved));
            AddIntElement(searchResults, "SHOWNORMAL", Convert.ToInt32(showNormal));
            AddIntElement(searchResults, "SHOWSUBMITTED", Convert.ToInt32(showSubmitted));
            AddIntElement(searchResults, "SHOWCONTENTRATING", Convert.ToInt32(showContentRating));
            AddIntElement(searchResults, "SHOWPHRASES", Convert.ToInt32(showPhrases));
            AddIntElement(searchResults, "USEFREETEXTSEARCH", Convert.ToInt32(useFreeTextSearch));

            bool bUseFastSearch = UseFastSearch();

            //if (bUseFastSearch)
            //{
            query = GenerateANDSearchQuery(query);
            //}
            //else
            //{
            //    query = GenerateSearchQuery(query);
            //}
            
            string SP = "searcharticlesadvanced";
            if (useFreeTextSearch)
            {
                SP = "searcharticlesadvancedfreetext";
            }
            else if (bUseFastSearch)
            {
                SP = "searcharticlesfast";
            }

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader( SP ))
            {
                if (bUseFastSearch)
                {
                    dataReader.AddParameter("@condition", query);
                    dataReader.AddParameter("@top", skip + show);
                }
                else
                {
                    dataReader.AddParameter("@subjectcondition", query);
                    dataReader.AddParameter("@bodycondition", query);
                }

                dataReader.AddParameter("@shownormal", Convert.ToInt32(showNormal));
                dataReader.AddParameter("showsubmitted", Convert.ToInt32(showSubmitted));
                dataReader.AddParameter("showapproved", Convert.ToInt32(showApproved));
                if (userGroups != string.Empty)
                {
                    dataReader.AddParameter("@usergroups", userGroups);
                }
                dataReader.AddParameter("@primarysite", InputContext.CurrentSite.SiteID);
                if (nodeId > 0)
                {
                    dataReader.AddParameter("@withincategory", nodeId);
                }
                dataReader.AddParameter("@showcontentratingdata", Convert.ToInt32(showContentRating));
                if (articleType > 0)
                {
                    dataReader.AddParameter("@articletype", articleType);
                }
                dataReader.AddParameter("@showkeyphrases", Convert.ToInt32(showPhrases));

                dataReader.Execute();

                //Skip desired items.
                for (int i = 0; i < skip; ++i)
                {
                    dataReader.Read();
                }

                int entryId = 0;
                int results = 0;
                XmlElement result = null;
                XmlElement phrases = null;
                while (dataReader.Read() )
                {
                    if (entryId != dataReader.GetInt32NullAsZero("entryid"))
                    {
                        if (results >= show)
                        {
                            break;
                        }

                        entryId = dataReader.GetInt32NullAsZero("entryid");
                        result = AddElementTag(searchResults, "ARTICLERESULT");
                        AddIntElement(result, "STATUS", dataReader.GetInt32NullAsZero("status"));
                        AddIntElement(result, "TYPE", dataReader.GetInt32NullAsZero("type"));
                        AddIntElement(result, "ENTRYID", entryId );
                        AddTextElement(result, "SUBJECT", dataReader.GetStringNullAsEmpty("subject"));
                        AddIntElement(result, "H2G2ID", dataReader.GetInt32NullAsZero("h2g2id"));
                        AddDateXml(dataReader.GetDateTime("datecreated"), result, "DATECREATED");
                        AddDateXml(dataReader.GetDateTime("lastupdated"), result, "LASTUPDATED");

                        if (!dataReader.IsDBNull("startdate"))
                        {
                            AddDateXml(dataReader.GetDateTime("startdate"), result, "DATERANGESTART");
                        }

                        if (!dataReader.IsDBNull("enddate"))
                        {
                            DateTime articlesDateRangeEnd = dataReader.GetDateTime("enddate");
				            // 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), result, "DATERANGEEND");
                        }

                        if (!dataReader.IsDBNull("timeinterval"))
                        {
                            AddIntElement(result, "TIMEINTERVAL", dataReader.GetInt32NullAsZero("timeinterval"));
                        }

                        int scorePercent = Convert.ToInt32(dataReader.GetDouble(dataReader.GetOrdinal("score")) * 100.0);
                        AddIntElement(result, "SCORE", scorePercent);
                        AddIntElement(result, "SITEID", dataReader.GetInt32NullAsZero("siteid"));
                        AddIntElement(result, "PRIMARYSITE", InputContext.CurrentSite.SiteID == dataReader.GetInt32NullAsZero("siteid") ? 1 : 0);

                        ++results;

                        //Add Extra Info XML where it exists.
                        string extraInfo = dataReader.GetAmpersandEscapedStringNullAsEmpty("extrainfo");
                        if (extraInfo != string.Empty)
                        {
                            XmlDocument extraInfoXml = new XmlDocument();
                            extraInfoXml.LoadXml(extraInfo);
                            result.AppendChild(ImportNode(extraInfoXml.FirstChild));
                        }

                        //Add Content Rating.
                        if (showContentRating)
                        {
                        }

                        if (showPhrases)
                        {
                            phrases = AddElementTag(result, "PHRASES");
                        }
                    }

                    //Add phrases XML.
                    if ( phrases != null && !dataReader.IsDBNull("phrase") )
                    {
                        Phrase phrase = new Phrase();
                        phrase.NameSpace = dataReader.GetStringNullAsEmpty("namespace");
                        phrase.PhraseName = dataReader.GetStringNullAsEmpty("phrase");
                        phrase.AddPhraseXml(phrases);
                    }
                }

                AddIntElement(searchResults,"SKIP",skip);
                AddIntElement(searchResults,"SHOW",show);
                AddIntElement(searchResults,"MORE", Convert.ToInt32(!dataReader.IsClosed) );
            }
            return true;
        }