mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2024-09-20 01:54:20 +02:00
97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using CodeHollow.FeedReader;
|
|
using SharpRss.Models;
|
|
using ToolQit.Extensions;
|
|
|
|
namespace SharpRss.Services
|
|
{
|
|
/// <summary>
|
|
/// Managing RSS feeds and categories.
|
|
/// </summary>
|
|
public class RssService : IDisposable
|
|
{
|
|
public RssService()
|
|
{
|
|
//SetupTestCategoriesAndFeedsAsync();
|
|
}
|
|
private readonly DatabaseService _dbService = new DatabaseService();
|
|
|
|
/*private async void SetupTestCategoriesAndFeedsAsync()
|
|
{
|
|
await _dbService.AddCategoriesAsync(new HashSet<CategoryModel>()
|
|
{
|
|
new CategoryModel() { Name = "All" },
|
|
new CategoryModel() { Name = "RSS" },
|
|
new CategoryModel() { Name = "Tech" },
|
|
new CategoryModel() { Name = "News" }
|
|
});
|
|
await _dbService.AddFeedsAsync(new HashSet<FeedModel>()
|
|
{
|
|
new FeedModel("http://fedoramagazine.org/feed/"),
|
|
new FeedModel("https://www.nasa.gov/rss/dyn/breaking_news.rss"),
|
|
new FeedModel("https://journals.plos.org/plosone/feed/atom"),
|
|
new FeedModel("https://itsfoss.com/feed")
|
|
});
|
|
}*/
|
|
|
|
public async Task<Feed> GetFeedAsync(string rssUrl)
|
|
{
|
|
/*return await FeedCache.GetFeed(rssUrl);*/
|
|
return new Feed();
|
|
}
|
|
|
|
public async Task<HashSet<object>> GetAllUnsortedAsync()
|
|
{
|
|
HashSet<object> items = new HashSet<object>();
|
|
/*var categories = await _dbService.GetCategoriesAsync();
|
|
var feeds = await _dbService.GetFeedsAsync(string.Empty);
|
|
items.UnionWith(categories);
|
|
items.UnionWith(feeds);*/
|
|
return items;
|
|
}
|
|
|
|
public async Task<HashSet<GroupModel>> GetCategoriesAsync()
|
|
{
|
|
/*var result = await _dbService.GetCategoriesAsync();
|
|
return result.OrderBy(x => x.Name).ToHashSet();*/
|
|
return new HashSet<GroupModel>();
|
|
}
|
|
|
|
public async Task<HashSet<FeedModel>> GetFeedsAsync(GroupModel? categoryModel = null)
|
|
{
|
|
HashSet<FeedModel> feeds = new HashSet<FeedModel>();
|
|
/*if (categoryModel != null)
|
|
feeds = await _dbService.GetFeedsAsync(categoryModel.Id);
|
|
else
|
|
feeds = await _dbService.GetFeedsAsync();*/
|
|
return feeds;
|
|
}
|
|
|
|
public async void AddCategoryAsync(string name, string? icon, string hexColor)
|
|
{
|
|
/*GroupModel groupModel = new GroupModel()
|
|
{
|
|
Name = name
|
|
};
|
|
if (icon != null)
|
|
groupModel.PathIcon = icon;
|
|
if (!hexColor.IsNullEmptyWhiteSpace())
|
|
groupModel.HexColor = hexColor;*/
|
|
//await _dbService.AddCategoriesAsync(new HashSet<GroupModel>() { groupModel });
|
|
}
|
|
|
|
public async void AddFeedAsync(string rssUrl, GroupModel? category = null)
|
|
{
|
|
//FeedModel feedModel = new FeedModel(rssUrl, category);
|
|
//await _dbService.AddFeedsAsync(new HashSet<FeedModel>() { feedModel });
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_dbService.Dispose();
|
|
}
|
|
}
|
|
} |