コード例 #1
0
ファイル: Recommendations.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Gets Recommendations from cache or db if not found in cache
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="readerCreator"></param>
        /// <param name="ignoreCache"></param>
        /// <returns></returns>
        public static Recommendations CreateRecommendations(ICacheManager cache, IDnaDataReaderCreator readerCreator, bool ignoreCache)
        {
            var recommendations = new Recommendations();

            //string key = recommendations.GetCacheKey();
            //check for item in the cache first
            /*
            if (!ignoreCache)
            {
                //not ignoring cache
                recommendations = (Recommendations)cache.GetData(key);
                if (recommendations != null)
                {
                    //check if still valid with db...
                    if (recommendations.IsUpToDate(readerCreator))
                    {
                        return recommendations;
                    }
                }
            }
            */
            //create from db
            recommendations = CreateRecommendationsFromDatabase(readerCreator);
            //add to cache
            //cache.Add(key, recommendations);

            return recommendations;
        }
コード例 #2
0
        public void RecommendationsXmlTest()
        {
            Recommendations recommendations = new Recommendations();
            XmlDocument xml = Serializer.SerializeToXml(recommendations);

            Assert.IsNotNull(xml.SelectSingleNode("RECOMMENDATIONS"));

        }
コード例 #3
0
ファイル: Recommendations.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Creates the recommendations from db
        /// </summary>
        /// <param name="readerCreator"></param>
        /// <returns></returns>
        public static Recommendations CreateRecommendationsFromDatabase(IDnaDataReaderCreator readerCreator)
        {
            Recommendations recommendations = null;
            // fetch all the lovely intellectual property from the database
            using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("getacceptedentries"))
            {
                reader.Execute();

                // Make sure we got something back
                if (!reader.HasRows || !reader.Read())
                {
                    throw new Exception("Recommendations not found");
                }
                else
                {
                    recommendations = new Recommendations();
                    recommendations.RecommendationsList = new List<Recommendation>();
                    int count = 0;
                    do
                    {
                        Recommendation recommendation = new Recommendation();
                        recommendation.Subject = reader.GetStringNullAsEmpty("Subject");

                        recommendation.GuideStatus = reader.GetInt32NullAsZero("GuideStatus");
                        recommendation.AcceptedStatus = reader.GetByteNullAsZero("AcceptedStatus");

                        recommendation.Original = new ArticleIDs();

                        recommendation.Original.EntryId = reader.GetInt32NullAsZero("OriginalEntryID");
                        recommendation.Original.H2G2Id = reader.GetInt32NullAsZero("Originalh2g2ID");

                        recommendation.Edited = new ArticleIDs();

                        recommendation.Edited.EntryId = reader.GetInt32NullAsZero("EntryID");
                        recommendation.Edited.H2G2Id = reader.GetInt32NullAsZero("h2g2ID");

                        recommendation.Users = new List<UserElement>();

                        UserElement subEditor= new UserElement() { user = User.CreateUserFromReader(reader, "SubEditor") };
                        //User subEditor = User.CreateUserFromReader(reader, "SubEditor");
                        recommendation.Users.Add(subEditor);

                        UserElement scout = new UserElement() { user = User.CreateUserFromReader(reader, "Scout") };
                        //User scout = User.CreateUserFromReader(reader, "Scout");
                        recommendation.Users.Add(scout);

                        DateTime dateAllocated = DateTime.MinValue;
                        DateTime dateReturned = DateTime.MinValue;
                        bool existsDateAllocated = !reader.IsDBNull("DateAllocated");
                        bool existsDateReturned = !reader.IsDBNull("DateReturned");
                        if (existsDateAllocated)
                        {
                            //dateAllocated = reader.GetDateTime("DateAllocated");
                            recommendation.DateAllocated = new DateElement(reader.GetDateTime("DateAllocated"));
                        }
                        //recommendation.DateAllocated = new DateElement(dateAllocated);

                        if (existsDateReturned)
                        {
                            //dateReturned = reader.GetDateTime("DateReturned");
                            recommendation.DateReturned = new DateElement(reader.GetDateTime("DateReturned"));
                        }
                        //recommendation.DateReturned = new DateElement(dateReturned);

                        recommendations.RecommendationsList.Add(recommendation);
                        count++;

                    } while (reader.Read());

                    recommendations.Count = count;
                }
            }
            return recommendations;
        }