SharpRSS/SharpRss/Models/FeedModel.cs

35 lines
933 B
C#
Raw Normal View History

2023-05-15 20:42:42 +02:00
using System.Threading.Tasks;
using CodeHollow.FeedReader;
2023-05-12 15:48:14 +02:00
namespace SharpRss.Models
{
public class FeedModel
2023-05-12 15:48:14 +02:00
{
2023-05-12 23:58:49 +02:00
public FeedModel(string rssUrl)
{
_rssUrl = rssUrl;
_fetchTask = FetchAsync();
2023-05-12 23:58:49 +02:00
}
2023-05-15 20:42:42 +02:00
private readonly Task _fetchTask;
2023-05-12 23:58:49 +02:00
2023-05-15 20:42:42 +02:00
public async Task FetchAsync() => _feed = await FeedCache.GetFeed(_rssUrl);
private Feed? _feed;
public Feed Base {
get
{
if (_feed == null)
{
if (_fetchTask.IsFaulted)
2023-05-15 20:42:42 +02:00
{ return new Feed(); }
if (_fetchTask.Status is not (TaskStatus.Running or TaskStatus.WaitingForActivation))
_fetchTask.Start();
_fetchTask.Wait();
}
return _feed ?? new Feed();
}
}
private readonly string _rssUrl;
2023-05-12 15:48:14 +02:00
}
}