private static async Task <string> BuildAtomFeed( DateTimeOffset lastUpdate, PagedQueryable <MunicipalitySyndicationQueryResult> pagedMunicipalities, IOptions <ResponseOptions> responseOptions, IConfiguration configuration) { var sw = new StringWriterWithEncoding(Encoding.UTF8); using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { Async = true, Indent = true, Encoding = sw.Encoding })) { var formatter = new AtomFormatter(null, xmlWriter.Settings) { UseCDATA = true }; var writer = new AtomFeedWriter(xmlWriter, null, formatter); var syndicationConfiguration = configuration.GetSection("Syndication"); var atomConfiguration = AtomFeedConfigurationBuilder.CreateFrom(syndicationConfiguration, lastUpdate); await writer.WriteDefaultMetadata(atomConfiguration); var municipalities = await pagedMunicipalities.Items.ToListAsync(); var highestPosition = municipalities.Any() ? municipalities.Max(x => x.Position) : (long?)null; var nextUri = BuildNextSyncUri( pagedMunicipalities.PaginationInfo.Limit, highestPosition + 1, syndicationConfiguration["NextUri"]); if (nextUri != null) { await writer.Write(new SyndicationLink(nextUri, GrArAtomLinkTypes.Next)); } foreach (var municipality in municipalities) { await writer.WriteMunicipality(responseOptions, formatter, syndicationConfiguration["Category"], municipality); } xmlWriter.Flush(); } return(sw.ToString()); }
private static async Task <string> BuildAtomFeed( DateTimeOffset lastFeedUpdate, PagedQueryable <AddressSyndicationQueryResult> pagedAddresses, IOptions <ResponseOptions> responseOptions, IConfiguration configuration) { var sw = new StringWriterWithEncoding(Encoding.UTF8); using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { Async = true, Indent = true, Encoding = sw.Encoding })) { var formatter = new AtomFormatter(null, xmlWriter.Settings) { UseCDATA = true }; var writer = new AtomFeedWriter(xmlWriter, null, formatter); var syndicationConfiguration = configuration.GetSection("Syndication"); var atomFeedConfig = AtomFeedConfigurationBuilder.CreateFrom(syndicationConfiguration, lastFeedUpdate); await writer.WriteDefaultMetadata(atomFeedConfig); var addresses = pagedAddresses.Items.ToList(); var nextFrom = addresses.Any() ? addresses.Max(x => x.Position) + 1 : (long?)null; var nextUri = BuildNextSyncUri(pagedAddresses.PaginationInfo.Limit, nextFrom, syndicationConfiguration["NextUri"]); if (nextUri != null) { await writer.Write(new SyndicationLink(nextUri, "next")); } foreach (var address in addresses) { await writer.WriteAddress(responseOptions, formatter, syndicationConfiguration["Category"], address); } xmlWriter.Flush(); } return(sw.ToString()); }
private static async Task <string> BuildAtomFeed( PagedQueryable <PostalInformationSyndicationQueryResult> pagedPostalInfoItems, IOptions <ResponseOptions> responseOptions, IConfiguration configuration) { var sw = new StringWriterWithEncoding(Encoding.UTF8); using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { Async = true, Indent = true, Encoding = sw.Encoding })) { var formatter = new AtomFormatter(null, xmlWriter.Settings) { UseCDATA = true }; var writer = new AtomFeedWriter(xmlWriter, null, formatter); var syndicationConfiguration = configuration.GetSection("Syndication"); await writer.WriteDefaultMetadata( syndicationConfiguration["Id"], syndicationConfiguration["Title"], Assembly.GetEntryAssembly().GetName().Version.ToString(), new Uri(syndicationConfiguration["Self"]), syndicationConfiguration.GetSection("Related").GetChildren().Select(c => c.Value).ToArray()); var nextUri = BuildVolgendeUri(pagedPostalInfoItems.PaginationInfo, syndicationConfiguration["NextUri"]); if (nextUri != null) { await writer.Write(new SyndicationLink(nextUri, GrArAtomLinkTypes.Next)); } foreach (var postalInfo in pagedPostalInfoItems.Items) { await writer.WritePostalInfo(responseOptions, formatter, syndicationConfiguration["Category"], postalInfo); } xmlWriter.Flush(); } return(sw.ToString()); }