public async Task <IActionResult> Index() { var feedDirectoryPath = $@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed"; if (!Directory.Exists(feedDirectoryPath)) { Directory.CreateDirectory(feedDirectoryPath); } var opmlDataFile = $@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\{Constants.OpmlFileName}"; if (!System.IO.File.Exists(opmlDataFile)) { Logger.LogInformation($"OPML file not found, writing new file on {opmlDataFile}"); var catResponse = await _categoryService.GetAllCategoriesAsync(); if (!catResponse.IsSuccess) { return(ServerError("Unsuccessful response from _categoryService.GetAllCategoriesAsync().")); } var catInfos = catResponse.Item.Select(c => new OpmlCategoryInfo { DisplayName = c.DisplayName, Title = c.Title }); var oi = new OpmlInfo { SiteTitle = $"{_blogConfig.SiteTitle} - OPML", CategoryInfo = catInfos, HtmlUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/post", XmlUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/rss", CategoryXmlUrlTemplate = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/rss/category/[catTitle]", CategoryHtmlUrlTemplate = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/category/list/[catTitle]" }; await FileSystemOpmlWriter.WriteOpmlFileAsync( $@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\{Constants.OpmlFileName}", oi); Logger.LogInformation("OPML file write completed."); if (!System.IO.File.Exists(opmlDataFile)) { Logger.LogInformation("OPML file still not found, something just went very very wrong..."); return(NotFound()); } } string opmlContent = await System.IO.File.ReadAllTextAsync(opmlDataFile, Encoding.UTF8); if (opmlContent.Length > 0) { return(Content(opmlContent, "text/xml")); } return(NotFound()); }
public async Task <IActionResult> Index() { var feedDirectoryPath = Path.Join($"{SiteDataDirectory}", "feed"); if (!Directory.Exists(feedDirectoryPath)) { Directory.CreateDirectory(feedDirectoryPath); Logger.LogInformation($"Created directory '{feedDirectoryPath}'"); } var opmlDataFile = Path.Join($"{SiteDataDirectory}", $"{Constants.OpmlFileName}"); if (!System.IO.File.Exists(opmlDataFile)) { Logger.LogInformation($"OPML file not found, writing new file on {opmlDataFile}"); var catResponse = await _categoryService.GetAllAsync(); if (!catResponse.IsSuccess) { return(ServerError("Unsuccessful response from _categoryService.GetAllAsync().")); } var catInfos = catResponse.Item.Select(c => new OpmlCategoryInfo { DisplayName = c.DisplayName, Title = c.RouteName }); var oi = new OpmlInfo { SiteTitle = $"{_blogConfig.GeneralSettings.SiteTitle} - OPML", CategoryInfo = catInfos, HtmlUrl = $"{SiteRootUrl}/post", XmlUrl = $"{SiteRootUrl}/rss", CategoryXmlUrlTemplate = $"{SiteRootUrl}/rss/category/[catTitle]", CategoryHtmlUrlTemplate = $"{SiteRootUrl}/category/list/[catTitle]" }; var path = Path.Join($"{SiteDataDirectory}", $"{Constants.OpmlFileName}"); await _fileSystemOpmlWriter.WriteOpmlFileAsync(path, oi); Logger.LogInformation("OPML file write completed."); if (!System.IO.File.Exists(opmlDataFile)) { Logger.LogInformation("OPML file still not found, something just went very very wrong..."); return(NotFound()); } } if (System.IO.File.Exists(opmlDataFile)) { return(PhysicalFile(opmlDataFile, "text/xml")); } return(NotFound()); }