Example #1
0
        public static string GetSyndicationFeed(this IEnumerable <Notification> notifications, string contentType)
        {
            var feed = new SyndicationFeed("System notification", "Publishes system notifications", new Uri("http://localhost"));

            feed.Authors.Add(new SyndicationPerson("*****@*****.**", "Testor Testorsson", "http://localhost"));
            feed.Links.Add(SyndicationLink.CreateSelfLink(new Uri(HttpContext.Current.Request.Url.AbsoluteUri), "application/atom+xml"));
            feed.Items = notifications.ASyndicationItems(feed);

            var stringWriter = new StringWriter();

            XmlWriter feedWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings
            {
                OmitXmlDeclaration = true
            });

            feed.Copyright = SyndicationContent.CreatePlaintextContent("Copyright hygia");
            feed.Language  = "en-us";

            if (contentType == ContentTypes.Atom)
            {
                feed.SaveAsAtom10(feedWriter);
            }
            else
            {
                feed.SaveAsRss20(feedWriter);
            }

            feedWriter.Close();

            return(stringWriter.ToString());
        }