Beispiel #1
0
        /// <summary>
        /// Functions generates an Article List of the given type
        /// </summary>
        /// <param name="userID">The user of the Articles to get</param>
        /// <param name="siteID">Site of the Articles</param>
        /// <param name="skip">Number of Articles to skip</param>
        /// <param name="show">Number of Articles to show</param>
        /// <param name="whichType">Type of Articles to show</param>
        /// <param name="guideType">Type of Guide Article to show</param>
        /// <returns>Whether created ok</returns>
        private bool CreateArticleList(int userID, int siteID, int skip, int show, ArticleListType whichType, int guideType)
        {
            // check object is not already initialised
            if (userID <= 0 || show <= 0)
            {
                return false;
            }

            // Get the cache article list date
            DateTime expiryDate = CacheGetArticleListDate(userID, siteID);

            // Check to see if the article list is cached
            _cachedFileName = "AL" + userID.ToString() + "-" + Convert.ToString(skip + show - 1) + "-" + skip.ToString() + "-" + whichType.ToString() + "-" + siteID.ToString();
            // If we have a guidetype then add this as well. Leave it out when 0 will reuse older existing cached files.
            if (guideType > 0)
            {
                _cachedFileName += "-" + guideType.ToString();
            }
            _cachedFileName += ".xml";

            string cachedArticleList = "";
            if (InputContext.FileCacheGetItem("articlelist", _cachedFileName, ref expiryDate, ref cachedArticleList) && cachedArticleList.Length > 0)
            {
                // Create the journal from the cache
                CreateAndInsertCachedXML(cachedArticleList, "ARTICLE-LIST", true);

                // Finally update the relative dates and return
                UpdateRelativeDates();
                return true;
            }
            
            int count = show;

            XmlElement articleList = AddElementTag(RootElement, "ARTICLE-LIST");
            AddAttribute(articleList, "COUNT", show);
            AddAttribute(articleList, "SKIPTO", skip);

            // now set the list type attribute
            switch (whichType)
            {
                case ArticleListType.ARTICLELISTTYPE_APPROVED :
                {
                    AddAttribute(articleList, "TYPE", "USER-RECENT-APPROVED");
                    break;
                }
                case ArticleListType.ARTICLELISTTYPE_NORMAL : 
                {
                    AddAttribute(articleList, "TYPE", "USER-RECENT-ENTRIES"); 
                    break;
                }
                case ArticleListType.ARTICLELISTTYPE_CANCELLED : 
                {
                    AddAttribute(articleList, "TYPE", "USER-RECENT-CANCELLED"); 
                    break;
                }
                case ArticleListType.ARTICLELISTTYPE_NORMALANDAPPROVED : 
                {
                    AddAttribute(articleList, "TYPE", "USER-RECENT-NORMALANDAPPROVED"); 
                    break;
                }
                default: 
                {
                    AddAttribute(articleList, "TYPE", "USER-RECENT-ENTRIES"); 
                    break;
                }
            }

            using (IDnaDataReader dataReader = GetUsersMostRecentEntries(userID, siteID, skip, show, whichType, guideType))	// Get +1 so we know if there are more left
            {
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    count = CreateList(articleList, dataReader, skip, show);
                }
            }
            //AddAttribute(commentsList, "COUNT", count);

            return true;
        }