示例#1
0
        public async Task <IActionResult> Rss(string routeName = null)
        {
            var rssDataFile = string.IsNullOrWhiteSpace(routeName) ?
                              Path.Join($"{SiteDataDirectory}", "feed", "posts.xml") :
                              Path.Join($"{SiteDataDirectory}", "feed", $"posts-category-{routeName}.xml");

            if (!System.IO.File.Exists(rssDataFile))
            {
                Logger.LogInformation($"RSS file not found, writing new file on {rssDataFile}");

                if (string.IsNullOrWhiteSpace(routeName))
                {
                    await _syndicationFeedService.RefreshFeedFileAsync(false);
                }
                else
                {
                    await _syndicationFeedService.RefreshRssFilesForCategoryAsync(routeName.ToLower());
                }

                if (!System.IO.File.Exists(rssDataFile))
                {
                    return(NotFound());
                }
            }

            if (System.IO.File.Exists(rssDataFile))
            {
                return(PhysicalFile(rssDataFile, "text/xml"));
            }

            return(NotFound());
        }
        public async Task <IActionResult> Rss(string categoryName = null)
        {
            var rssDataFile = string.IsNullOrWhiteSpace(categoryName) ?
                              $@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed\posts.xml" :
                              $@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed\posts-category-{categoryName}.xml";

            if (!System.IO.File.Exists(rssDataFile))
            {
                Logger.LogInformation($"RSS file not found, writing new file on {rssDataFile}");

                if (string.IsNullOrWhiteSpace(categoryName))
                {
                    await _syndicationFeedService.RefreshFeedFileForPostAsync(false);
                }
                else
                {
                    await _syndicationFeedService.RefreshRssFilesForCategoryAsync(categoryName.ToLower());
                }

                if (!System.IO.File.Exists(rssDataFile))
                {
                    return(NotFound());
                }
            }

            string rssContent = await System.IO.File.ReadAllTextAsync(rssDataFile, Encoding.UTF8);

            if (rssContent.Length > 0)
            {
                return(Content(rssContent, "text/xml"));
            }

            return(NotFound());
        }