public static async Task WriteAddress(
            this ISyndicationFeedWriter writer,
            IOptions <ResponseOptions> responseOptions,
            AtomFormatter formatter,
            string category,
            AddressSyndicationQueryResult address)
        {
            var item = new SyndicationItem
            {
                Id          = address.Position.ToString(CultureInfo.InvariantCulture),
                Title       = $"{address.ChangeType}-{address.Position}",
                Published   = address.RecordCreatedAt.ToBelgianDateTimeOffset(),
                LastUpdated = address.LastChangedOn.ToBelgianDateTimeOffset(),
                Description = BuildDescription(address, responseOptions.Value.Naamruimte)
            };

            if (address.PersistentLocalId.HasValue)
            {
                // TODO: Hier moet prolly version nog ergens in
                item.AddLink(
                    new SyndicationLink(
                        new Uri($"{responseOptions.Value.Naamruimte}/{address.PersistentLocalId}"),
                        AtomLinkTypes.Related));

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format(responseOptions.Value.DetailUrl, address.PersistentLocalId)),
                        AtomLinkTypes.Self));

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format($"{responseOptions.Value.DetailUrl}.xml", address.PersistentLocalId)), AtomLinkTypes.Alternate)
                {
                    MediaType = MediaTypeNames.Application.Xml
                });

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format($"{responseOptions.Value.DetailUrl}.json",
                                              address.PersistentLocalId)),
                        AtomLinkTypes.Alternate)
                {
                    MediaType = MediaTypeNames.Application.Json
                });
            }

            item.AddCategory(
                new SyndicationCategory(category));

            item.AddContributor(
                new SyndicationPerson(
                    "agentschap Informatie Vlaanderen",
                    "*****@*****.**",
                    AtomContributorTypes.Author));

            await writer.Write(item);
        }
示例#2
0
        public static async Task WritePostalInfo(
            this ISyndicationFeedWriter writer,
            IOptions <ResponseOptions> responseOptions,
            AtomFormatter formatter,
            string category,
            PostalInformationSyndicationQueryResult postalInformation)
        {
            var item = new SyndicationItem
            {
                Id          = postalInformation.Position.ToString(CultureInfo.InvariantCulture),
                Title       = $"{postalInformation.ChangeType}-{postalInformation.Position}",
                Published   = postalInformation.RecordCreatedAt.ToBelgianDateTimeOffset(),
                LastUpdated = postalInformation.LastChangedOn.ToBelgianDateTimeOffset(),
                Description = BuildDescription(postalInformation, responseOptions.Value.Naamruimte)
            };

            if (!string.IsNullOrWhiteSpace(postalInformation.PostalCode))
            {
                item.AddLink(
                    new SyndicationLink(
                        new Uri($"{responseOptions.Value.Naamruimte}/{postalInformation.PostalCode}"),
                        AtomLinkTypes.Related));

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format(responseOptions.Value.DetailUrl, postalInformation.PostalCode)),
                        AtomLinkTypes.Self));

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format($"{responseOptions.Value.DetailUrl}.xml", postalInformation.PostalCode)),
                        AtomLinkTypes.Alternate)
                {
                    MediaType = MediaTypeNames.Application.Xml
                });

                item.AddLink(
                    new SyndicationLink(
                        new Uri(string.Format($"{responseOptions.Value.DetailUrl}.json", postalInformation.PostalCode)),
                        AtomLinkTypes.Alternate)
                {
                    MediaType = MediaTypeNames.Application.Json
                });
            }

            item.AddCategory(
                new SyndicationCategory(category));

            item.AddContributor(
                new SyndicationPerson(
                    "agentschap Informatie Vlaanderen",
                    "*****@*****.**",
                    AtomContributorTypes.Author));

            await writer.Write(item);
        }
        public static async Task WriteMunicipality(
            this ISyndicationFeedWriter writer,
            IOptions <ResponseOptions> responseOptions,
            AtomFormatter formatter,
            string category,
            MunicipalitySyndicationQueryResult municipality)
        {
            var item = new SyndicationItem
            {
                Id          = municipality.Position.ToString(CultureInfo.InvariantCulture),
                Title       = $"{municipality.ChangeType}-{municipality.Position}",
                Published   = municipality.RecordCreatedAt.ToBelgianDateTimeOffset(),
                LastUpdated = municipality.LastChangedOn.ToBelgianDateTimeOffset(),
                Description = BuildDescription(municipality, responseOptions.Value.Naamruimte)
            };

            if (!string.IsNullOrWhiteSpace(municipality.NisCode))
            {
                item.AddLink(
                    new SyndicationLink(
                        new Uri($"{responseOptions.Value.Naamruimte}/{municipality.NisCode}"),
                        AtomLinkTypes.Related));

                //item.AddLink(
                //    new SyndicationLink(
                //        new Uri(string.Format(responseOptions.Value.DetailUrl, municipality.NisCode)),
                //        AtomLinkTypes.Self));

                //item.AddLink(
                //    new SyndicationLink(
                //        new Uri(string.Format($"{responseOptions.Value.DetailUrl}.xml", municipality.NisCode)),
                //        AtomLinkTypes.Alternate)
                //    { MediaType = MediaTypeNames.Application.Xml });

                //item.AddLink(
                //    new SyndicationLink(
                //            new Uri(string.Format($"{responseOptions.Value.DetailUrl}.json", municipality.NisCode)),
                //        AtomLinkTypes.Alternate)
                //    { MediaType = MediaTypeNames.Application.Json });
            }

            item.AddCategory(
                new SyndicationCategory(category));

            item.AddContributor(
                new SyndicationPerson(
                    municipality.Organisation == null ? Organisation.Unknown.ToName() : municipality.Organisation.Value.ToName(),
                    string.Empty,
                    AtomContributorTypes.Author));

            await writer.Write(item);
        }
        public static async Task WriteAddress(
            this ISyndicationFeedWriter writer,
            IOptions <ResponseOptions> responseOptions,
            AtomFormatter formatter,
            string category,
            AddressSyndicationQueryResult address)
        {
            var item = new SyndicationItem
            {
                Id          = address.Position.ToString(CultureInfo.InvariantCulture),
                Title       = $"{address.ChangeType}-{address.Position}",
                Published   = address.RecordCreatedAt.ToBelgianDateTimeOffset(),
                LastUpdated = address.LastChangedOn.ToBelgianDateTimeOffset(),
                Description = BuildDescription(address, responseOptions.Value.Naamruimte)
            };

            if (address.PersistentLocalId.HasValue)
            {
                item.AddLink(
                    new SyndicationLink(
                        new Uri($"{responseOptions.Value.Naamruimte}/{address.PersistentLocalId}"),
                        AtomLinkTypes.Related));

                //item.AddLink(
                //    new SyndicationLink(
                //        new Uri(string.Format(responseOptions.Value.DetailUrl, address.PersistentLocalId)),
                //        AtomLinkTypes.Self));

                //item.AddLink(
                //    new SyndicationLink(
                //            new Uri(string.Format($"{responseOptions.Value.DetailUrl}.xml", address.PersistentLocalId)), AtomLinkTypes.Alternate)
                //    { MediaType = MediaTypeNames.Application.Xml });

                //item.AddLink(
                //    new SyndicationLink(
                //            new Uri(string.Format($"{responseOptions.Value.DetailUrl}.json",
                //                address.PersistentLocalId)),
                //            AtomLinkTypes.Alternate)
                //    { MediaType = MediaTypeNames.Application.Json });
            }

            item.AddCategory(
                new SyndicationCategory(category));

            item.AddContributor(
                new SyndicationPerson(
                    address.Organisation == null ? Organisation.Unknown.ToName() : address.Organisation.Value.ToName(),
                    string.Empty,
                    AtomContributorTypes.Author));

            await writer.Write(item);
        }
        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());
        }
        public async Task EmbededAtomInRssFeed()
        {
            var author = new SyndicationPerson("john doe", "*****@*****.**");
            var entry  = new AtomEntry()
            {
                Id          = "https://contoso.com/28af09b3",
                Title       = "Atom Entry",
                Description = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit...",
                LastUpdated = DateTimeOffset.UtcNow
            };

            entry.AddContributor(author);

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var attributes = new ISyndicationAttribute[] { new SyndicationAttribute("xmlns:atom", "http://www.w3.org/2005/Atom") };
                var writer     = new SyndicationFeed.Rss.RssFeedWriter(xmlWriter, attributes);
                var formatter  = new AtomFormatter(attributes, xmlWriter.Settings);

                //
                // Write Rss elements
                await writer.WriteValue(SyndicationFeed.Rss.RssElementNames.Title, "Rss Title");

                await writer.Write(author);

                await writer.Write(new SyndicationItem()
                {
                    Title       = "Rss Item",
                    Id          = "https://contoso.com/rss/28af09b3",
                    Description = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium",
                    LastUpdated = DateTimeOffset.UtcNow
                });

                //
                // Write atom entry
                await writer.WriteRaw(formatter.Format(entry));

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res.Contains($"<atom:entry><atom:id>{entry.Id}</atom:id><atom:title>{entry.Title}</atom:title><atom:updated>{entry.LastUpdated.ToString("r")}</atom:updated><atom:author><atom:name>{author.Name}</atom:name><atom:email>{author.Email}</atom:email></atom:author><atom:content>{entry.Description}</atom:content></atom:entry>"));
        }
示例#7
0
        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());
        }