public ICollection <FeedCache> GetContent(int collectionId)
        {
            ICollection <FeedCache> contentCache      = new List <FeedCache>();
            DBContentCollection     contentCollection = uow.ContentCollections.GetWithInclude(c => c.ContentCollectionId == collectionId, c => c.Feeds).FirstOrDefault();

            if (contentCollection != null)
            {
                foreach (DBFeed feed in contentCollection.Feeds)
                {
                    ObjectCache cache = MemoryCache.Default;
                    var         key   = feed.FeedId.ToString();
                    FeedCache   fc    = cache[key] as FeedCache;

                    if (fc == null)
                    {
                        bool readed = fReader.getFeedsContent(feed.URL, out fc);
                        if (readed)
                        {
                            CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                            cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(10.00);
                            cache.Set(key, fc, cacheItemPolicy);
                            contentCache.Add(fc);
                        }
                    }
                    else
                    {
                        contentCache.Add(fc);
                    }
                }
            }

            return(contentCache);
        }
        public bool CheckContentCollection(string title)
        {
            DBContentCollection c = uow.ContentCollections.Get(coll => coll.Title == title).FirstOrDefault();

            if (c != null)
            {
                return(false);
            }
            return(true);
        }
 public bool RemoveContentCollection(int id)
 {
     try
     {
         DBContentCollection contentCollection = uow.ContentCollections.FindById(id);
         uow.ContentCollections.Remove(contentCollection);
         uow.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #4
0
        public void GetCollections()
        {
            ResetData();
            List <DBContentCollection> collections = new List <DBContentCollection>();
            DBContentCollection        collection1 = new DBContentCollection();
            DBContentCollection        collection2 = new DBContentCollection();

            collections.Add(collection1);
            collections.Add(collection2);

            mockContentCollections.Setup(a => a.Get()).Returns(collections);

            List <ContentCollection> result = (List <ContentCollection>)ContO.GetCollections();

            Assert.AreEqual(collections.Count, result.Count);
        }
Exemple #5
0
        public void AddFeedToCollection()
        {
            ResetData();
            DBContentCollection contentCollection = new DBContentCollection();
            Feed feed = new Feed();

            var id = 1;

            contentCollection.ContentCollectionId = id;
            feed.URL = "http";

            mockContentCollections.Setup(a => a.FindById(id)).Returns(contentCollection);

            bool result = ContO.AddFeedToCollection(id, feed);

            Assert.AreEqual(true, result);
        }
 public bool AddFeedToCollection(int collectionId, Feed feed)
 {
     try
     {
         DBContentCollection contentCollection = uow.ContentCollections.FindById(collectionId);
         DBFeed newFeed = new DBFeed {
             URL = feed.URL, ContentCollection = contentCollection
         };
         uow.Feeds.Create(newFeed);
         uow.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public int CreateContentCollection(string newTitle)
 {
     try
     {
         DBContentCollection dbcc = new DBContentCollection {
             Title = newTitle
         };
         uow.ContentCollections.Create(dbcc);
         uow.Save();
         DBContentCollection dbCollection = uow.ContentCollections.Get(c => c.Title == newTitle).First();
         return(dbCollection.ContentCollectionId);
     }
     catch (Exception)
     {
         return(0);
     }
 }