Exemple #1
0
        public string GenerateRss(string baseurl)
        {
            RssDocument r = new RssDocument();
            RssChannel  c = new RssChannel();

            c.Items = new List <RssItem>();

            foreach (WritaPost p in _dbhelper.GetPosts())
            {
                c.Items.Add(new RssItem()
                {
                    Link = baseurl + "/" + p.PostSlug, Title = p.PostTitle, Description = p.PostSummary
                });
            }

            r.Channel = c;
            r.Version = "2.0";

            string      doc      = r.ToXml(DocumentType.Atom);
            XmlDocument document = new XmlDocument();

            document.LoadXml(doc);
            //context.Response.ContentType = "text/xml";
            document.Save(HttpContext.Current.Server.MapPath("~/atom.rss"));
            return(doc);
        }
Exemple #2
0
        public async Task <IActionResult> GetRssFeed()
        {
            var key = "rss";
            var xml = _cache.Get(key)?.ToString();

            if (string.IsNullOrEmpty(xml))
            {
                int?categoryId  = null;
                var pagedResult = await _publicationManager.GetPublications(categoryId, 1, 50);

                var lastUpdateDate = pagedResult.Select(o => o.DateTime).DefaultIfEmpty().Max();

                var rss = new RssDocument
                {
                    Channel =
                        new RssChannel
                    {
                        Copyright   = _settings.WebSiteTitle,
                        Description = _settings.DefaultDescription,
                        SkipDays    = new List <Day>(),
                        SkipHours   = new List <Hour>(),
                        AtomLink    = new RssLink(_settings.RssFeedUrl),
                        Image       = new RssImage
                        {
                            Description = _settings.WebSiteTitle,
                            Height      = 100,
                            Width       = 100,
                            Link        = new RssUrl(_settings.FacebookImage),
                            Title       = _settings.WebSiteTitle,
                            Url         = new RssUrl(_settings.FacebookImage)
                        },
                        Language       = new CultureInfo("ru"),
                        LastBuildDate  = lastUpdateDate,
                        Link           = new RssUrl(_settings.RssFeedUrl),
                        ManagingEditor = new RssPerson("Andrew G.", _settings.SupportEmail),
                        PubDate        = lastUpdateDate,
                        Title          = _settings.WebSiteTitle,
                        TTL            = 10,
                        WebMaster      = new RssPerson("Andrew G.", _settings.SupportEmail),
                        Items          = new List <RssItem> {
                        }
                    }
                };

                foreach (var p in pagedResult)
                {
                    rss.Channel.Items.Add(CreateRssItem(p));
                }

                xml = rss.ToXml();

                _cache.Set(key, xml, TimeSpan.FromMinutes(10));
            }

            return(Content(xml, RssDocument.MimeType));
        }
Exemple #3
0
        public void RssDocumentToXmlTest()
        {
            RssDocument rss = RssUtility.GetRssDocumentFromUrl();
            string      xml = rss.ToXml(DocumentType.Rss);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            Assert.IsTrue(doc.SelectNodes("/rss/channel/item").Count > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/rss/channel/title").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/rss/channel/item/title").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");

            xml = rss.ToXml(DocumentType.Atom);
            doc.LoadXml(xml);
            Assert.IsTrue(doc.SelectNodes("/feed/entry").Count > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/feed/title").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/feed/entry/summary").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");

            xml = rss.ToXml(DocumentType.Rdf);
            doc.LoadXml(xml);
            Assert.IsTrue(doc.SelectNodes("/rdf/item").Count > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/rdf/channel/title").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
            Assert.IsTrue(doc.SelectSingleNode("/rdf/item/title").InnerText.Length > 0, "RssToolkit.Rss.RssDocument.ToXml did not return the expected value.");
        }
Exemple #4
0
        /// <summary>
        /// Generates the specified param.
        /// </summary>
        /// <returns></returns>
        public string Generate()
        {
            ResolveListViewProfile();

            RssDocument rssDocument = new RssDocument();

            rssDocument.Version = "2.0";

            rssDocument.Channel       = new RssChannel();
            rssDocument.Channel.Image = new RssImage();

            GenerateChannelInformation(rssDocument.Channel);

            rssDocument.Channel.Copyright = IbnConst.AssemblyCopyright;
            rssDocument.Channel.Generator = IbnConst.AssemblyCompany + "RSS Generator";
            rssDocument.Channel.WebMaster = "";

            rssDocument.Channel.Image.Link  = MakeFullLink(this.Page.ResolveUrl("~/"));
            rssDocument.Channel.Image.Title = IbnConst.ProductName;
            rssDocument.Channel.TimeToLive  = "30";

            rssDocument.Channel.Items         = new List <RssItem>();
            rssDocument.Channel.LastBuildDate = GenerateChannelItems(rssDocument.Channel);

            //dvs[2009-05-28]: fix bug with ie (set encoding to utf-8)
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(rssDocument.ToXml(DocumentType.Rss));
            if (xmlDoc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
            {
                XmlDeclaration xmlDeclaration = (XmlDeclaration)xmlDoc.FirstChild;
                xmlDeclaration.Encoding = "utf-8";
            }

            StringWriter  sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            xmlDoc.WriteTo(xw);
            return(sw.ToString());
        }