SharpRSS/SharpRss/RssService.cs

73 lines
2.0 KiB
C#
Raw Normal View History

2023-05-07 02:42:37 +02:00
using System.Collections.Generic;
2023-04-27 17:23:01 +02:00
using System.Linq;
2023-05-07 02:42:37 +02:00
using System.Threading.Tasks;
2023-04-27 17:23:01 +02:00
using CodeHollow.FeedReader;
2023-05-07 02:42:37 +02:00
using SharpRss.Models;
2023-04-27 17:23:01 +02:00
namespace SharpRss
{
2023-05-12 15:48:14 +02:00
/// <summary>
/// Managing RSS feeds and categories.
/// </summary>
2023-04-27 17:23:01 +02:00
public class RssService
{
2023-04-28 21:58:36 +02:00
public RssService()
{
2023-05-12 15:48:14 +02:00
/// Storage options:
/// - Database
/// - File
/// - Memory
2023-04-28 21:58:36 +02:00
}
2023-05-07 02:42:37 +02:00
2023-05-12 23:58:49 +02:00
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"),
2023-05-12 23:58:49 +02:00
};
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)
};
2023-05-12 15:48:14 +02:00
public async Task<HashSet<CategoryModel>> GetCategories()
2023-05-07 02:42:37 +02:00
{
2023-05-12 23:58:49 +02:00
return set;
2023-05-07 02:42:37 +02:00
}
2023-05-12 15:48:14 +02:00
public async Task<HashSet<FeedModel>> GetAllFeeds()
2023-04-27 17:23:01 +02:00
{
HashSet<FeedModel> fSet = new HashSet<FeedModel>();
fSet.UnionWith(feedSet);
fSet.UnionWith(feedSet2);
return fSet;
2023-05-12 15:48:14 +02:00
}
/// Old
2023-04-27 17:23:01 +02:00
2023-05-12 15:48:14 +02:00
public async Task<Feed> GetFeed(string feedUrl)
{
var urls = await FeedReader.GetFeedUrlsFromUrlAsync(feedUrl);
2023-04-27 17:23:01 +02:00
string url;
if (urls.Count() < 1)
url = _feeds[0];
else
url = urls.First().Url;
2023-05-12 15:48:14 +02:00
return await FeedReader.ReadAsync(url);
2023-04-27 17:23:01 +02:00
}
2023-05-12 15:48:14 +02:00
public async Task<HashSet<Feed>> GetFeedsFromCatAsync(CategoryModel category)
2023-04-28 21:58:36 +02:00
{
2023-05-12 15:48:14 +02:00
return new HashSet<Feed>();
2023-04-28 21:58:36 +02:00
}
2023-05-12 15:48:14 +02:00
private readonly string[] _feeds = { "https://www.reddit.com/r/freshrss/.rss", "http://fedoramagazine.org/" };
2023-04-27 17:23:01 +02:00
}
}