public async Task WriteAtom10FileAsync(string absolutePath) { var feed = GetSyndicationItemCollection(FeedItemCollection); var settings = new XmlWriterSettings { Async = true, Encoding = Encoding.UTF8, Indent = true }; using var xmlWriter = XmlWriter.Create(absolutePath, settings); var writer = new AtomFeedWriter(xmlWriter); await writer.WriteTitle(HeadTitle); await writer.WriteSubtitle(HeadDescription); await writer.WriteRights(Copyright); await writer.WriteUpdated(DateTime.UtcNow); await writer.WriteGenerator(Generator, HostUrl, GeneratorVersion); foreach (var item in feed) { await writer.Write(item); } await xmlWriter.FlushAsync(); xmlWriter.Close(); }
/// <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)); } }
/// <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 async Task <string> WriteAtomAsync() { var feed = GetItemCollection(FeedItemCollection); var sw = new StringWriterWithEncoding(Encoding.UTF8); await using (var xmlWriter = XmlWriter.Create(sw, new() { Async = true })) { var writer = new AtomFeedWriter(xmlWriter); await writer.WriteTitle(HeadTitle); await writer.WriteSubtitle(HeadDescription); await writer.WriteRights(Copyright); await writer.WriteUpdated(DateTime.UtcNow); await writer.WriteGenerator(Generator, HostUrl, GeneratorVersion); foreach (var item in feed) { await writer.Write(item); } await xmlWriter.FlushAsync(); xmlWriter.Close(); } var xml = sw.ToString(); return(xml); }
private XmlFeedWriter InitializeAtomFeedWriter(XmlWriter xmlWriter) { var result = new AtomFeedWriter(xmlWriter); result.WriteTitle(_siteSettings.SiteName); result.WriteSubtitle(_siteSettings.Description); result.WriteRights(_siteSettings.Copyright); result.WriteUpdated(_blogPostsConfig.Blogs.Where(x => x.Published).First().CreateDate.Date); result.WriteGenerator(_siteSettings.Nickname, _siteSettings.PersonalSiteURL, _siteSettings.Version); return(result); }
public async Task <string> WriteAtomAsync() { var feed = GetItemCollection(FeedItemCollection); var settings = new XmlWriterSettings { Async = true }; var sb = new StringBuilder(); await using (var xmlWriter = XmlWriter.Create(sb, settings)) { var writer = new AtomFeedWriter(xmlWriter); await writer.WriteTitle(HeadTitle); await writer.WriteSubtitle(HeadDescription); await writer.WriteRights(Copyright); await writer.WriteUpdated(DateTime.UtcNow); await writer.WriteGenerator(Generator, HostUrl, GeneratorVersion); foreach (var item in feed) { await writer.Write(item); } await xmlWriter.FlushAsync(); xmlWriter.Close(); } var xml = sb.ToString(); return(xml); }