From 825af3a0b35e822573841f9c5bdadbde05c50020 Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Mon, 29 May 2023 18:02:24 +0200 Subject: [PATCH] Moved to Argotic --- SharpRss/DbAccess.cs | 5 +- SharpRss/Services/RssService.cs | 96 ++++++++++-------------------- SharpRss/SharpRss.csproj | 8 ++- SharpRss/SyndicationManager.cs | 27 +++++++++ WebSharpRSS/Shared/SideGuide.razor | 1 - WebSharpRSS/WebSharpRSS.csproj | 1 + 6 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 SharpRss/SyndicationManager.cs diff --git a/SharpRss/DbAccess.cs b/SharpRss/DbAccess.cs index d2056a3..03eddd2 100644 --- a/SharpRss/DbAccess.cs +++ b/SharpRss/DbAccess.cs @@ -155,12 +155,8 @@ namespace SharpRss new SqliteParameter("originalDoc", feedModel.OriginalDocument ?? string.Empty) } }; - /*await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();*/ await cmd.ExecuteNonQueryAsync(); } - - /*if (reader.Read()) - resultModel = await ReaderToFeedModel(reader);*/ await transaction.CommitAsync(); return resultModel; } @@ -221,6 +217,7 @@ namespace SharpRss } return feedItems; } + public static async Task SetFeedItemsAsync(HashSet items) { int result = 0; diff --git a/SharpRss/Services/RssService.cs b/SharpRss/Services/RssService.cs index 43d1589..e935851 100644 --- a/SharpRss/Services/RssService.cs +++ b/SharpRss/Services/RssService.cs @@ -2,7 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using CodeHollow.FeedReader; +using Argotic.Common; +using Argotic.Syndication; using Serilog; using SharpRss.Models; @@ -31,58 +32,15 @@ namespace SharpRss.Services //TODO: Need to rework this implementation!!! public async Task AddFeedsAsync(string[]? rssUrls, GroupModel? group = null) { - bool result = false; - if (rssUrls == null) return result; - HashSet fetchedFeeds = new HashSet(); - foreach (var rssUrl in rssUrls) - fetchedFeeds.Add(await FetchFeed(rssUrl)); - HashSet feeds = new HashSet(); - HashSet itemModels = new HashSet(); - - foreach (var feed in fetchedFeeds) - { - FeedModel feedModel = new FeedModel(feed.Link) - { - Title = feed.Title, - GroupId = group?.Id ?? string.Empty, - FeedType = feed.Type.ToString(), - Description = feed.Description, - Language = feed.Language, - Copyright = feed.Copyright, - DateAdded = DateTimeOffset.Now, - LastUpdated = DateTimeOffset.Now, - ImageUrl = feed.ImageUrl, - OriginalDocument = feed.OriginalDocument - }; - - feeds.Add(feedModel); - } - /*Feed fetched = await FetchFeed(rssUrl); - - if (fetched == null) - return result; - FeedModel feedModel = new FeedModel(rssUrl) - { - Title = fetched.Title, - GroupId = group?.Id ?? string.Empty, - FeedType = fetched.Type.ToString(), - Description = fetched.Description, - Language = fetched.Language, - Copyright = fetched.Copyright, - DateAdded = DateTimeOffset.Now, - LastUpdated = DateTimeOffset.Now, - ImageUrl = fetched.ImageUrl, - OriginalDocument = fetched.OriginalDocument - }; - FeedModel? dbFeed = await _dbService.SetFeedAsync(feedModel); - result = dbFeed != null; - if (dbFeed == null) - return result;*/ - //itemModels.Add(ConstructFeedItems()); - /*if (await AddFeedItems(fetched.Items, dbFeed) == 0) - Log.Warning("No feed items added to feed: {FeedUrl}", dbFeed.Url);*/ - return result; + return false; } + + public async Task UpdateFeeds() + { + Log.Verbose("Fetching feeds..."); + var feeds = await GetFeedsAsync(); + } + public async Task> GetFeedsAsync(string? groupId = null) => await DbAccess.GetFeedsAsync(groupId); public async Task> GetUngroupedFeedsAsync() => await DbAccess.GetFeedsAsync(""); @@ -93,7 +51,7 @@ namespace SharpRss.Services return items; } - private async Task AddFeedItems(IList items, FeedModel feedModel) + /*private async Task AddFeedItems(IList items, FeedModel feedModel) { int result = 0; if (!items.Any()) @@ -102,9 +60,9 @@ namespace SharpRss.Services // TODO: implement!!! result = await DbAccess.SetFeedItemsAsync(itemModels); return result; - } + }*/ - private IList ConstructFeedItems(IList items, FeedModel feed) + /*private IList ConstructFeedItems(IList items, FeedModel feed) { IList itemModels = new List(); if (!items.Any()) @@ -126,16 +84,19 @@ namespace SharpRss.Services }); } return itemModels; - } + }*/ - private async Task FetchFeed(string url) + private GenericSyndicationFeed? CreateFeed(string url) { - Log.Verbose("Fetching feed: {FeedUrl}", url); - var urls = await FeedReader.ParseFeedUrlsAsStringAsync(url); - string feedUrl = url; - if (urls.Any()) - feedUrl = urls.First(); - return await FeedReader.ReadAsync(feedUrl); + Uri feedUri = new Uri(url); + Log.Verbose("Checking feed: {FeedUrl}", feedUri.ToString()); + if (!SyndicationDiscoveryUtility.UriExists(feedUri)) + { + Log.Warning("Feed: {FeedUri} does not exists!", feedUri.ToString()); + return null; + } + Log.Verbose("Fetching feed: {FeedUrl}", feedUri.ToString()); + return GenericSyndicationFeed.Create(new Uri(url)); } private async void SetupTestGroupsAndFeedsAsync() { @@ -160,6 +121,15 @@ namespace SharpRss.Services Log.Error(e, "Error fetching feeds!"); throw; }*/ + var groups = await GetGroupsAsync(); + GroupModel testGroup = groups.Single(x => x.Name == "News"); + await AddFeedsAsync(new[] + { + "https://www.nu.nl/rss/Algemeen", + "https://www.nu.nl/rss/Economie", + "https://www.nu.nl/rss/Sport", + "http://news.google.com/?output=atom" + }, testGroup); } public void Dispose() diff --git a/SharpRss/SharpRss.csproj b/SharpRss/SharpRss.csproj index 1103e52..1da7f5a 100644 --- a/SharpRss/SharpRss.csproj +++ b/SharpRss/SharpRss.csproj @@ -8,7 +8,9 @@ - + + + @@ -20,4 +22,8 @@ + + + + diff --git a/SharpRss/SyndicationManager.cs b/SharpRss/SyndicationManager.cs new file mode 100644 index 0000000..9dc5e57 --- /dev/null +++ b/SharpRss/SyndicationManager.cs @@ -0,0 +1,27 @@ +using System; +using Argotic.Common; +using Argotic.Syndication; + +namespace SharpRss +{ + public static class SyndicationManager + { + public static bool FeedExists(string feedUrl) + { + Uri feedUri = new Uri(feedUrl); + return SyndicationDiscoveryUtility.UriExists(feedUri); + } + + public static bool TryGetFeed(string feedUrl, out GenericSyndicationFeed? feed) + { + feed = null; + Uri feedUri = new Uri(feedUrl); + return false; + } + + public static void Test() + { + + } + } +} \ No newline at end of file diff --git a/WebSharpRSS/Shared/SideGuide.razor b/WebSharpRSS/Shared/SideGuide.razor index ab8634f..45ffde3 100644 --- a/WebSharpRSS/Shared/SideGuide.razor +++ b/WebSharpRSS/Shared/SideGuide.razor @@ -1,6 +1,5 @@ @using SharpRss.Models; @using MudBlazor.Utilities -@using CodeHollow.FeedReader @using Serilog @using SharpRss.Services @using WebSharpRSS.Models; diff --git a/WebSharpRSS/WebSharpRSS.csproj b/WebSharpRSS/WebSharpRSS.csproj index 335455a..e998e8b 100644 --- a/WebSharpRSS/WebSharpRSS.csproj +++ b/WebSharpRSS/WebSharpRSS.csproj @@ -39,6 +39,7 @@ <_ContentIncludedByDefault Remove="logs\log_20230525.json" /> <_ContentIncludedByDefault Remove="logs\log_20230526.json" /> <_ContentIncludedByDefault Remove="logs\log_20230527.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230529.json" />