private async Task <ISyndicationFeedWriter> GetWriter(string?type, XmlWriter xmlWriter, DateTime updated) { var host = $"{this.Request.Scheme}://{this.Request.Host}/"; if (type?.Equals("rss", StringComparison.OrdinalIgnoreCase) ?? false) { var rss = new RssFeedWriter(xmlWriter); await rss.WriteTitle(this.manifest.Name).ConfigureAwait(false); await rss.WriteDescription(this.manifest.Description).ConfigureAwait(false); await rss.WriteGenerator("Miniblog.Core").ConfigureAwait(false); await rss.WriteValue("link", host).ConfigureAwait(false); return(rss); } var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(this.manifest.Name).ConfigureAwait(false); await atom.WriteId(host).ConfigureAwait(false); await atom.WriteSubtitle(this.manifest.Description).ConfigureAwait(false); await atom.WriteGenerator("Miniblog.Core", "https://github.com/madskristensen/Miniblog.Core", "1.0").ConfigureAwait(false); await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)).ConfigureAwait(false); return(atom); }
/// <summary> /// Write default meta data for an atom feed /// </summary> /// <param name="atomFeedWriter">the AtomFeedWriter</param> /// <param name="id">the id of the feed</param> /// <param name="title">the title of the feed</param> /// <param name="version">the version of the feed</param> /// <param name="selfUri">the self referencing uri of the feed</param> /// <param name="relatedUrls">optional related urls</param> /// <returns></returns> public static async Task WriteDefaultMetadata( this AtomFeedWriter atomFeedWriter, string id, string title, string version, Uri selfUri, params string[] relatedUrls) { await atomFeedWriter.WriteId(id); await atomFeedWriter.WriteTitle(title); await atomFeedWriter.WriteSubtitle("Basisregisters Vlaanderen stelt u in staat om alles te weten te komen rond: de Belgische gemeenten; de Belgische postcodes; de Vlaamse straatnamen; de Vlaamse adressen; de Vlaamse gebouwen en gebouweenheden; de Vlaamse percelen; de Vlaamse organisaties en organen; de Vlaamse dienstverlening."); await atomFeedWriter.WriteGenerator("Basisregisters Vlaanderen", "https://basisregisters.vlaanderen.be", version); await atomFeedWriter.WriteRights($"Copyright (c) 2017-{DateTime.Now.Year}, Informatie Vlaanderen"); await atomFeedWriter.WriteUpdated(DateTimeOffset.UtcNow); await atomFeedWriter.Write(new SyndicationPerson("agentschap Informatie Vlaanderen", "*****@*****.**", AtomContributorTypes.Author)); await atomFeedWriter.Write(new SyndicationLink(selfUri, AtomLinkTypes.Self)); foreach (var relatedUrl in relatedUrls) { await atomFeedWriter.Write(new SyndicationLink(new Uri(relatedUrl), AtomLinkTypes.Related)); } }
private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated) { string host = Request.Scheme + "://" + Request.Host + "/"; if (type.Equals("rss", StringComparison.OrdinalIgnoreCase)) { var rss = new RssFeedWriter(xmlWriter); await rss.WriteTitle(_settings.Value.Name); await rss.WriteDescription(_settings.Value.Description); await rss.WriteGenerator("Miniblog.Core"); await rss.WriteValue("link", host); return(rss); } var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(_settings.Value.Name); await atom.WriteId(host); await atom.WriteSubtitle(_settings.Value.Description); await atom.WriteGenerator("Miniblog.Core", "https://github.com/madskristensen/Miniblog.Core", "1.0"); await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ")); return(atom); }
private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated) { string host = Request.Scheme + "://" + Request.Host + "/"; if (type.Equals("rss", StringComparison.OrdinalIgnoreCase)) { var rss = new RssFeedWriter(xmlWriter); await rss.WriteTitle(_manifest.Name); await rss.WriteDescription(_manifest.Description); await rss.WriteGenerator("BrickApp"); await rss.WriteValue("link", host); return(rss); } var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(_manifest.Name); await atom.WriteId(host); await atom.WriteSubtitle(_manifest.Description); await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ")); return(atom); }
/// <summary> /// Write default meta data for an atom feed /// </summary> /// <param name="atomFeedWriter">the AtomFeedWriter</param> /// <param name="atomFeedConfiguration">the configuration of the atom feed</param> /// <returns></returns> public static async Task WriteDefaultMetadata( this AtomFeedWriter atomFeedWriter, AtomFeedConfiguration atomFeedConfiguration) { await atomFeedWriter.WriteId(atomFeedConfiguration.Id); await atomFeedWriter.WriteTitle(atomFeedConfiguration.Title); await atomFeedWriter.WriteSubtitle(atomFeedConfiguration.Subtitle); await atomFeedWriter.WriteGenerator(atomFeedConfiguration.GeneratorTitle, atomFeedConfiguration.GeneratorUri, atomFeedConfiguration.GeneratorVersion); await atomFeedWriter.WriteRights(atomFeedConfiguration.Rights); await atomFeedWriter.WriteUpdated(atomFeedConfiguration.Updated); await atomFeedWriter.Write(atomFeedConfiguration.Author); await atomFeedWriter.Write(atomFeedConfiguration.SelfUri); foreach (var alternateUri in atomFeedConfiguration.AlternateUris) { await atomFeedWriter.Write(alternateUri); } foreach (var relatedUri in atomFeedConfiguration.RelatedUris) { await atomFeedWriter.Write(relatedUri); } }
public static async Task <string> ToAtom(this IList <Page> pages) { using (var stringWriter = new StringWriter()) { using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Async = true, Indent = true, Encoding = Encoding.UTF8, WriteEndDocumentOnClose = true })) { var atomWriter = new AtomFeedWriter(xmlWriter); var tasks = new List <Task> { atomWriter.WriteTitle(Settings.Title), atomWriter.WriteSubtitle(Settings.Description), atomWriter.WriteId(Settings.Domain), atomWriter.Write(new SyndicationLink(new Uri(Settings.Domain))), atomWriter.WriteUpdated(pages.First().Timestamp.ToLocalTime()) }; tasks.AddRange(pages.Select(p => atomWriter.Write(p.ToSyndicationItem()))); Task.WaitAll(tasks.ToArray()); await atomWriter.Flush(); } return(stringWriter.ToString()); } }
public override async Task ExecuteResultAsync(ActionContext context) { using (XmlWriter xmlWriter = XmlWriter.Create(context.HttpContext.Response.Body, new XmlWriterSettings { Async = true, Indent = true })) { var writer = new AtomFeedWriter(xmlWriter); var uniqueFeedIdBuilder = new UriBuilder(m_feedRequestUrl) { Scheme = Uri.UriSchemeHttp, Query = string.Empty }; var uniqueFeedId = uniqueFeedIdBuilder.ToString(); await writer.WriteId(uniqueFeedId); await writer.WriteTitle(m_feedTitle); //await writer.WriteDescription(m_feedTitle); await writer.Write(new SyndicationLink(m_feedRequestUrl)); //await writer.WriteUpdated(DateTimeOffset.UtcNow); foreach (var syndicationItem in m_feedItems) { syndicationItem.Id = $"{uniqueFeedId}?itemId={syndicationItem.Id}"; await writer.Write(syndicationItem); } xmlWriter.Flush(); } }
public async Task WriteValue() { const string title = "Example Feed"; Guid id = Guid.NewGuid(); DateTimeOffset updated = DateTimeOffset.UtcNow.AddDays(-21); var sw = new StringWriterWithEncoding(Encoding.UTF8); using (var xmlWriter = XmlWriter.Create(sw)) { var writer = new AtomFeedWriter(xmlWriter); await writer.WriteTitle(title); await writer.WriteId(id.ToString()); await writer.WriteUpdated(updated); await writer.Flush(); } string res = sw.ToString(); Assert.True(CheckResult(res, $"<title>{title}</title><id>{id}</id><updated>{updated.ToString("r")}</updated>")); }
private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated) { var host = Request.Scheme + "://" + Request.Host + "/"; if (type.Equals("rss", StringComparison.OrdinalIgnoreCase)) { var rss = new RssFeedWriter(xmlWriter); await rss.WriteTitle(_settings.Brand); await rss.WriteDescription(_settings.Description); await rss.WriteGenerator("Bagombo Blog Engine"); await rss.WriteValue("link", host); return(rss); } var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(_settings.Brand); await atom.WriteId(host); await atom.WriteSubtitle(_settings.Description); await atom.WriteGenerator("Bagombo Blog Engine", "https://github.com/tylerlrhodes/bagobo", "0.2.5a"); await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ")); return(atom); }
public async Task ExecuteResultAsync(ActionContext context) { var response = context.HttpContext.Response; var request = context.HttpContext.Request; response.ContentType = "application/atom+xml"; var host = request.Scheme + "://" + request.Host + "/"; using (var xmlWriter = XmlWriter.Create(response.Body, new XmlWriterSettings() { Async = true, Indent = true, Encoding = new UTF8Encoding(true) })) { var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(_options.Value.Title); await atom.WriteId(host); await atom.WriteSubtitle(_options.Value.Description); await atom.WriteRaw($"\n <link rel=\"self\" type=\"application/atom+xml\" href=\"{host}feed/atom\"/>"); await atom.WriteGenerator(_options.Value.GeneratorDescription, _options.Value.SourceCodeLink, "1.0"); var lastPost = _page.Items.FirstOrDefault(); if (lastPost != null) { await atom.WriteValue("updated", lastPost.PublishedDate.Value.ToString("yyyy-MM-ddTHH:mm:ssZ")); } foreach (var post in _page.Items) { var item = new AtomEntry { Title = post.Title, Description = post.GetContentWithoutDataSrc(), Id = $"{host}/{post.Alias}", Published = post.PublishedDate.Value, LastUpdated = post.ModifiedDate, ContentType = "html", }; foreach (var tag in post.BlogStoryTags) { item.AddCategory(new SyndicationCategory(tag.Tag.Name)); } item.AddContributor(new SyndicationPerson(_options.Value.AuthorName, _options.Value.Email, "author")); // item.AddLink(new SyndicationLink(new Uri($"{host}/{post.Alias}"))); await atom.Write(item); } } }
public async Task <string> GenerateFeed(IEnumerable <ReleaseViewModel> releases) { const string title = "Changelog Feed"; var id = new UniqueId(); var updated = DateTimeOffset.UtcNow; var sw = new StringWriterWithEncoding(Encoding.UTF8); using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings() { Async = true, Indent = true })) { var writer = new AtomFeedWriter(xmlWriter); await writer.WriteTitle(title); await writer.WriteId(id.ToString()); await writer.WriteUpdated(updated); foreach (var release in releases) { var item = new SyndicationItem() { Title = release.ReleaseVersion, Id = new UniqueId(release.ReleaseId).ToString(), LastUpdated = release.ReleaseDate }; release.Authors.ForEach(x => item.AddContributor(new SyndicationPerson(x, $"{x}@test.com")) ); var sb = new StringBuilder(); foreach (var workItemViewModel in release.WorkItems) { sb.Append(workItemViewModel.WorkItemTypeString) .Append(": ") .AppendLine(workItemViewModel.Description) ; } item.Description = sb.ToString(); await writer.Write(item); } xmlWriter.Flush(); } return(sw.GetStringBuilder().ToString()); }
public async Task AddSource(FeedSource source) { await Console.Error.WriteLineAsync("[Builder] Downloading content"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(source.Feed.Url); request.UserAgent = UserAgentHelper.UserAgent; WebResponse response = await request.GetResponseAsync(); await Console.Error.WriteLineAsync("[Builder] Generating feed header"); // Write the header await feed.WriteGenerator("Polyfeed", "https://github.com/sbrl/PolyFeed.git", Program.GetProgramVersion()); await feed.WriteId(source.Feed.Url); await feed.Write(new SyndicationLink(new Uri(source.Feed.Url), AtomLinkTypes.Self)); string lastModified = response.Headers.Get("last-modified"); if (string.IsNullOrWhiteSpace(lastModified)) { await feed.WriteUpdated(DateTimeOffset.Now); } else { await feed.WriteUpdated(DateTimeOffset.Parse(lastModified)); } string contentType = response.Headers.Get("content-type"); IParserProvider provider = GetProvider(source.Feed.SourceType); if (provider == null) { throw new ApplicationException($"Error: A provider for the source type {source.Feed.SourceType} wasn't found."); } provider.SetOutputFeed(feed, xml); await provider.ParseWebResponse(source, response); await Console.Error.WriteLineAsync("[Builder] Done!"); }
/// <summary> /// Creates the feed writer and writes the initial headers. /// </summary> /// <param name="writer">The current xml writer</param> /// <param name="blog">The blog service</param> /// <param name="url">The currently requested url</param> /// <param name="host">The host name</param> /// <returns>The feed writer</returns> private async Task <ISyndicationFeedWriter> GetWriter(XmlWriter writer, IBlogService blog, string url, string host, DateTime?latest) { var segments = url.Substring(1).Split('/'); if (latest.HasValue && segments.Length == 2) { if (segments[1] == "rss") { var rss = new RssFeedWriter(writer); // Write feed headers await rss.WriteTitle(blog.Settings.Title); await rss.WriteDescription(blog.Settings.Description); await rss.WriteGenerator("RazorBlog"); await rss.WriteValue("link", host); return(rss); } else if (segments[1] == "atom") { var atom = new AtomFeedWriter(writer); // Write feed headers await atom.WriteTitle(blog.Settings.Title); await atom.WriteId(host); await atom.WriteSubtitle(blog.Settings.Description); await atom.WriteGenerator("RazorBlog", "https://github.com/tidyui/razorblog", "0.1"); await atom.WriteValue("updated", latest.Value.ToString("yyyy-MM-ddTHH:mm:ssZ")); return(atom); } } return(null); }
public async Task <ISyndicationFeedWriter> GetWriter(string type, string host, XmlWriter xmlWriter) { var lastPost = _db.BlogPosts.All().OrderByDescending(p => p.Published).FirstOrDefault(); var blog = await _db.CustomFields.GetBlogSettings(); if (lastPost == null) { return(null); } if (type.Equals("rss", StringComparison.OrdinalIgnoreCase)) { var rss = new RssFeedWriter(xmlWriter); await rss.WriteTitle(blog.Title); await rss.WriteDescription(blog.Description); await rss.WriteGenerator("Blogifier"); await rss.WriteValue("link", host); return(rss); } var atom = new AtomFeedWriter(xmlWriter); await atom.WriteTitle(blog.Title); await atom.WriteId(host); await atom.WriteSubtitle(blog.Description); await atom.WriteGenerator("Blogifier", "https://github.com/blogifierdotnet/Blogifier", "1.0"); await atom.WriteValue("updated", lastPost.Published.ToString("yyyy-MM-ddTHH:mm:ssZ")); return(atom); }