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); }
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); }
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); } }