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
|
|
|
|
|
{
|
2023-05-15 15:53:08 +02:00
|
|
|
|
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;
|
2023-05-15 15:53:08 +02:00
|
|
|
|
_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);
|
2023-05-15 15:53:08 +02:00
|
|
|
|
|
|
|
|
|
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))
|
2023-05-15 15:53:08 +02:00
|
|
|
|
_fetchTask.Start();
|
|
|
|
|
_fetchTask.Wait();
|
|
|
|
|
}
|
|
|
|
|
return _feed ?? new Feed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private readonly string _rssUrl;
|
2023-05-12 15:48:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|