private void UpdateFromAtom(WebEntry entry, XElement element, Action <Exception> error) { entry.URI = GetLinkAtom(element); entry.Title = (string)element.Element(Atom + "title"); // TODO the title might be HTML. string updated = (string)GetMandatoryElement(element, Atom + "updated"); try { entry.Date = Tools.RFC3339Date(updated); } catch (Exception e) { error(new SubscriptionParsingException(string.Format("Invalid date string “{0}”", updated), e) { Subscription = this }); } XElement content = element.Element(Atom + "content"); if (content != null) { XAttribute src = content.Attribute("src"); if (src != null) { if (entry.Description == null) { entry.Description = "(awaiting remote content)"; // TODO fetch content from somewhere else on demand } } else { // TODO content might not be HTML entry.Description = (string)content; } } else { XElement summary = element.Element(Atom + "summary"); if (summary != null) { entry.Description = (string)summary; } else { entry.Description = null; } } }
private void UpdateFromRss(WebEntry entry, XElement item, Action <Exception> error) { XElement title = item.Element("title") ?? item.Element(RSS + "title"); XElement description = item.Element(RSSContent + "encoded") ?? item.Element("description") ?? item.Element(RSS + "description"); XElement pubDate = item.Element("pubDate"); XElement dcDate = item.Element(DcmiMetadata + "date"); entry.Title = (title != null ? (string)title : ""); entry.Description = description != null ? (string)description : ""; entry.URI = GetRssItemUri(item); if (pubDate != null) { try { entry.Date = Tools.RFC822Date((string)pubDate); } catch (Exception e) { error(new SubscriptionParsingException(string.Format("Invalid date string “{0}”", (string)pubDate), e) { Subscription = this }); } } else if (dcDate != null) { try { entry.Date = Tools.RFC3339Date((string)dcDate); } catch (Exception e) { error(new SubscriptionParsingException(string.Format("Invalid date string “{0}”", (string)dcDate), e) { Subscription = this }); } } // TODO author, category, comments, enclosure, source }
private void UpdateEntry(XElement item, string id, Action <WebEntry, XElement, Action <Exception> > update, Action <Exception> error) { WebEntry entry = null; bool newEntry = false; // Find out what we know entry = (WebEntry)_Entries.Entries.GetValueOrDefault(id, null); if (entry == null) { // A new entry. entry = new WebEntry() { Identity = id, Serial = this.NextSerial++, ParentSubscription = this, ParentEntryList = _Entries, }; newEntry = true; } // Update the item try { update(entry, item, error); } catch (SubscriptionParsingException spe) { // If individual errors fail, we just log them and move on spe.Subscription = this; error(spe); } // If anything new was created, record it if (newEntry) { Add(entry); } }