Ejemplo n.º 1
0
        public Entities.Feed ParseFeed(IEnumerable <XElement> xml, Entities.Feed feed)
        {
            if (xml.ElementAt(0) == null || xml.ElementAt(0).Element("title") == null)
            {
                throw new BadFeed();
            }

            feed.Name = xml.ElementAt(0).Element("title").Value;
            return(feed);
        }
Ejemplo n.º 2
0
        public Entities.Feed CreateFeed(string url)
        {
            var feed = new Entities.Feed();

            var xml = xmlService.Load(url);

            feed     = xmlService.ParseFeed(xml, feed);
            feed.Url = url;

            unitOfWork.RepositoryFeed.Add(feed);
            unitOfWork.Save();

            return(feed);
        }
Ejemplo n.º 3
0
        public Entities.Feed UpdateFeed(Entities.Feed feed)
        {
            var xml = xmlService.Load(feed.Url);

            var items = xmlService.ParseItems(xml, feed);

            feed.LastUpdate = DateTime.Now;
            unitOfWork.RepositoryFeed.Update(feed);

            foreach (var item in items)
            {
                unitOfWork.RepositoryItem.Add(item);
            }

            unitOfWork.Save();

            return(feed);
        }
Ejemplo n.º 4
0
        public List <Item> ParseItems(IEnumerable <XElement> xml, Entities.Feed feed)
        {
            var items = new List <Item>();

            var xmlItems = xml.First().Elements()
                           .Where(i => i.Name.LocalName.Equals("item") && (!feed.LastUpdate.HasValue || i.Element("pubDate") == null || (i.Element("pubDate") != null && DateTime.Parse(i.Element("pubDate").Value) > feed.LastUpdate.Value)))
                           .ToList();

            foreach (var xmlItem in xmlItems)
            {
                if (xmlItem.Element("link") == null ||
                    xmlItem.Element("title") == null)
                {
                    throw new BadFeed();
                }

                var item = new Item
                {
                    Feed    = feed,
                    Url     = xmlItem.Element("link").Value,
                    Title   = xmlItem.Element("title").Value,
                    Created = DateTime.Now,
                };

                if (xmlItem.Element("pubDate") != null)
                {
                    DateTime created;
                    if (DateTime.TryParse(xmlItem.Element("pubDate").Value, out created))
                    {
                        item.Created = created;
                    }
                }

                items.Add(item);
            }

            return(items);
        }