private async Task <Link> GetLink(string address) { Link link = null; if (!string.IsNullOrWhiteSpace(address)) { using var cancellationTokenSource = new CancellationTokenSource(timeout); try { await Task.Run(() => { try { using var reader = XmlReader.Create(address); var feed = SyndicationFeed.Load(reader); link = new Link() { Name = RegexUtilities.GetText(feed.Title?.Text), XmlUrl = address, HtmlUrl = address }; } catch (Exception) { } }, cancellationTokenSource.Token); } catch (OperationCanceledException) { } } return(link); }
private Reco GetRecoFromSyndication(SyndicationFeed feed, SyndicationItem item) { var imageUri = feed.ImageUrl ?? RegexUtilities.GetImage(item.Summary?.Text); var itemUri = item.Links == null || item.Links.Count == 0 ? null : item.Links[0]?.Uri.ToString(); var reco = new Reco() { ImageUri = imageUri, Uri = itemUri, FeedTitle = RegexUtilities.GetText(feed.Title?.Text), ItemTitle = RegexUtilities.GetText(item.Title?.Text), SummaryHtml = item.Summary?.Text, PublishDate = item.PublishDate }; return(reco); }