示例#1
0
        private Topic GetTopic(DBContext db, entity.Topic topic, entity.db.Source sourceModel, IEnumerable <Category> categories)
        {
            var existTopic = db.Topics.Find(topic.Guid);

            if (existTopic != null)
            {
                return(existTopic);
            }

            var topicCategories = categories.Select(category => new TopicCategory {
                Category = category
            }).ToList();

            var dbSources = db.Sources.Find(sourceModel.Id);

            existTopic = new Topic
            {
                Guid            = topic.Guid,
                Creator         = topic.Creator,
                Description     = topic.Description,
                Link            = topic.Link,
                PublisDate      = topic.PublisDate,
                Title           = topic.Title,
                Source          = dbSources,
                TopicCategories = topicCategories
            };
            db.Topics.Add(existTopic);
            db.SaveChanges();
            return(existTopic);
        }
示例#2
0
        public IEnumerable <Topic> GetTopics(entity.db.Source souce)
        {
            var browserOpearation = new BrowserOperation();
            var xmlDocument       = browserOpearation.DawloadXML(souce.Url);
            var rawTopics         = ParseItems(xmlDocument, souce);
            var topics            = rawTopics.Select(rawTopic => CastToTopic(rawTopic));

            return(topics);
        }
示例#3
0
 private IEnumerable <System.Xml.XmlNode> ParseItems(System.Xml.XmlDocument xmlDocument, entity.db.Source source)
 {
     try
     {
         return(xmlDocument.SelectNodes(source.ItemParsePath).Cast <System.Xml.XmlNode>());
     }
     catch (System.Xml.XmlException e)
     {
         System.Console.WriteLine(e);
         return(null);
     }
 }