Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #3
0
        /// <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);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        /// <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));
            }
        }
Пример #6
0
    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);
    }
Пример #7
0
        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);
        }
Пример #8
0
        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);
                }
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
        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!");
        }
Пример #11
0
        /// <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 WriteContent()
        {
            const string uri       = "https://contoso.com/generator";
            const string version   = "1.0";
            const string generator = "Example Toolkit";

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new AtomFeedWriter(xmlWriter);

                await writer.WriteGenerator(generator, uri, version);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<generator uri=\"{uri}\" version=\"{version}\">{generator}</generator>"));
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
        public async Task WritePrefixedAtomNs()
        {
            const string title     = "Example Feed";
            const string uri       = "https://contoso.com/generator";
            const string generator = "Example Toolkit";

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new AtomFeedWriter(xmlWriter,
                                                new ISyndicationAttribute[] { new SyndicationAttribute("xmlns:atom", "http://www.w3.org/2005/Atom") });

                await writer.WriteTitle(title);

                await writer.WriteGenerator(generator, uri, null);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<atom:title>{title}</atom:title><atom:generator uri=\"{uri}\">{generator}</atom:generator>", "atom"));
        }