private static async Task <string> BuildAtomFeed( DateTimeOffset lastFeedUpdate, 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"); var atomFeedConfig = AtomFeedConfigurationBuilder.CreateFrom(syndicationConfiguration, lastFeedUpdate); await writer.WriteDefaultMetadata(atomFeedConfig); var postalInfos = pagedPostalInfoItems.Items.ToList(); var nextFrom = postalInfos.Any() ? postalInfos.Max(x => x.Position) + 1 : (long?)null; var nextUri = BuildNextSyncUri(pagedPostalInfoItems.PaginationInfo.Limit, nextFrom, syndicationConfiguration["NextUri"]); if (nextUri != null) { await writer.Write(new SyndicationLink(nextUri, GrArAtomLinkTypes.Next)); } foreach (var postalInfo in postalInfos) { await writer.WritePostalInfo(responseOptions, formatter, syndicationConfiguration["Category"], postalInfo); } 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()); }