mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2024-11-10 07:54:20 +01:00
35 lines
933 B
C#
35 lines
933 B
C#
using System.Threading.Tasks;
|
|
using CodeHollow.FeedReader;
|
|
|
|
namespace SharpRss.Models
|
|
{
|
|
public class FeedModel
|
|
{
|
|
public FeedModel(string rssUrl)
|
|
{
|
|
_rssUrl = rssUrl;
|
|
_fetchTask = FetchAsync();
|
|
}
|
|
private readonly Task _fetchTask;
|
|
|
|
public async Task FetchAsync() => _feed = await FeedCache.GetFeed(_rssUrl);
|
|
|
|
private Feed? _feed;
|
|
public Feed Base {
|
|
get
|
|
{
|
|
if (_feed == null)
|
|
{
|
|
if (_fetchTask.IsFaulted)
|
|
{ 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;
|
|
}
|
|
}
|