Ejemplo n.º 1
0
        public virtual async Task <IActionResult> IndexAsync()
        {
            var channel = new RssChannel
            {
                Title           = Site.Title,
                Description     = "Последние публикации",
                Link            = new Uri(Site.Url),
                Language        = CultureInfo.CurrentCulture,
                TimeToLive      = 60,
                LastBuildDate   = DateTime.Now,
                Copyright       = $"(c) {Site.Title}",
                PublicationDate = DateTime.Now
            };

            var items = new List <RssItem>();

            if (_itemsProviders != null)
            {
                foreach (var itemsProvider in _itemsProviders)
                {
                    var providerItems = await itemsProvider.GetItemsAsync(Site, RssFeedSize);

                    items.AddRange(providerItems);
                }
            }

            channel.Items = items.OrderByDescending(i => i.PublicationDate);

            var syncIoFeature = HttpContext.Features.Get <IHttpBodyControlFeature>();

            if (syncIoFeature != null)
            {
                syncIoFeature.AllowSynchronousIO = true;
            }

            var xml = XmlFormatter.BuildXml(channel);

            return(new XmlResult(xml));
        }