public async Task<List<Article>> ReadArticlesAsync()
        {
            List<Article> articles = new List<Article>();

            await Task.Run(() => {
                var assembly = typeof (XmlArticlesService).GetTypeInfo().Assembly;
                using (Stream stream = assembly.GetManifestResourceStream("LokalReporter.Client.Dummy.lokalreporter.xml")) {
                    XElement channel = XDocument.Load(stream).Root?.Descendants().FirstOrDefault();

                    foreach (XElement item in channel.Descendants("item")) {
                        var article = new Article();
                        foreach (XElement propertyElement in item.Elements()) {
                            Action<XElement, Article> setter;
                            var name = $"{propertyElement.Name.Namespace}:{propertyElement.Name.LocalName}";

                            if (this.setterActions.TryGetValue(name, out setter)) {
                                setter(propertyElement, article);
                            }
                        }
                        articles.Add(article);
                    }
                }
            });

            return articles;
        }
 private void SetCategoryOrTags(XElement element, Article article)
 {
     var domain = element.Attribute(XName.Get("domain"))?.Value;
     if (domain == null) {
         return;
     }
     //if (domain == "category") {
     //    article.Categories.Add(Entities.From<Category>(element.Attribute("nicename").Value, element.Value));
     //}
     //else 
     if (domain == "post_tag") {
         article.Tags.Add(Entities.From<Tag>(element.Attribute("nicename").Value, element.Value));
     }
 }
        public void Apply(Article article)
        {
            HtmlDocument htmlDocument = new HtmlDocument();
            htmlDocument.LoadHtml(this.value);

            article.HtmlContent = htmlDocument.DocumentNode.InnerHtml;

            var htmlNodes = htmlDocument.DocumentNode.Descendants("img").ToList();

            var contains = article.HtmlContent.Contains("<img");
            if (contains && htmlNodes.Count == 0) {
                Debug.WriteLine($"ContainsImages BUT NO IMG TAGS FOUND");
            }

            foreach (HtmlNode node in htmlNodes) {
                Image image;
                if (this.TryParseImage(node, out image)) {
                    article.Images.Add(image);
                }
            }
        }
Esempio n. 4
0
 protected bool Equals(Article other)
 {
     return string.Equals(this.Id, other.Id);
 }