SharpRSS/SharpRss/RssService.cs
2023-05-16 14:12:36 +02:00

73 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CodeHollow.FeedReader;
using SharpRss.Models;
namespace SharpRss
{
/// <summary>
/// Managing RSS feeds and categories.
/// </summary>
public class RssService
{
public RssService()
{
/// Storage options:
/// - Database
/// - File
/// - Memory
}
private static HashSet<FeedModel> feedSet = new HashSet<FeedModel>()
{
new FeedModel("http://fedoramagazine.org/feed/"),
new FeedModel("https://www.nasa.gov/rss/dyn/breaking_news.rss"),
};
private static HashSet<FeedModel> feedSet2 = new HashSet<FeedModel>()
{
new FeedModel("https://journals.plos.org/plosone/feed/atom"),
new FeedModel("https://itsfoss.com/feed")
};
HashSet<CategoryModel> set = new HashSet<CategoryModel>()
{
new CategoryModel("RSS", feedSet),
new CategoryModel("Tech", feedSet2)
};
public async Task<HashSet<CategoryModel>> GetCategories()
{
return set;
}
public async Task<HashSet<FeedModel>> GetAllFeeds()
{
HashSet<FeedModel> fSet = new HashSet<FeedModel>();
fSet.UnionWith(feedSet);
fSet.UnionWith(feedSet2);
return fSet;
}
/// Old
public async Task<Feed> GetFeed(string feedUrl)
{
var urls = await FeedReader.GetFeedUrlsFromUrlAsync(feedUrl);
string url;
if (urls.Count() < 1)
url = _feeds[0];
else
url = urls.First().Url;
return await FeedReader.ReadAsync(url);
}
public async Task<HashSet<Feed>> GetFeedsFromCatAsync(CategoryModel category)
{
return new HashSet<Feed>();
}
private readonly string[] _feeds = { "https://www.reddit.com/r/freshrss/.rss", "http://fedoramagazine.org/" };
}
}