Example #1
0
        public void InsertArticle(Article article)
        {
            WriteConcernResult writeConsernResult = _collection.Insert(article);

            if (!writeConsernResult.Ok)
            {
                throw new ApplicationException(string.Format("Cannot insert article because {0}", writeConsernResult.Response));
            }
        }
Example #2
0
        public Dictionary<string, Article> Fetch(string uri)
        {
            var xmlReader = XmlReader.Create(uri);
            SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
            xmlReader.Close();

            if (feed == null)
            {
                return null;
            }

            var articles = new Dictionary<string, Article>();

            foreach (var item in feed.Items)
            {
                string subject = item.Title.Text;
                string summary = item.Summary.Text;
                List<Author> authors = new List<Author>(item.Authors.Count);
                authors.AddRange(item.Authors.Select(author => new Author(author.Name, author.Email)));

                string articleContent = "";
                foreach (SyndicationElementExtension ext in item.ElementExtensions)
                {
                    if (ext.GetObject<XElement>().Name.LocalName == "encoded")
                    {
                        articleContent = ext.GetObject<XElement>().Value;
                    }
                }

                var content = new Content(articleContent, "Html");
                DateTime lastUpdateTime = item.LastUpdatedTime.DateTime;
                DateTime publishDate = item.PublishDate.DateTime;

                var article = new Article(item.Id, uri, subject, item.Title.Text, summary, authors, lastUpdateTime, publishDate, content);
                string key = string.Format("{0}.{1}", uri, item.Id);
                articles.Add(key, article);
            }
            return articles;
        }
Example #3
0
        private bool Equals(Article other)
        {
            bool authorsEquals = Authors.Count == other.Authors.Count;
            if (!authorsEquals) return false;

            for(int i=0; i<Authors.Count; i++)
            {
                authorsEquals = Authors[i].Equals(other.Authors[i]);
                if (!authorsEquals) return false;
            }

            return string.Equals(Id, other.Id) && string.Equals(Source, other.Source) && string.Equals(Subject, other.Subject)
                && string.Equals(Title, other.Title) && PublishDate.Equals(other.PublishDate) && LastUpdateTime.Equals(other.LastUpdateTime)
                && Content.Equals(other.Content) && authorsEquals && string.Equals(Summary, other.Summary);
        }