From 323486f36d08d1038462b2ed4cc2a22b75c78a41 Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Mon, 29 May 2023 16:14:26 +0200 Subject: [PATCH] Moved db acces to static class. --- .../DatabaseService.cs => DbAccess.cs} | 165 ++++++++++-------- SharpRss/FeedCache.cs | 43 ----- SharpRss/Services/RssService.cs | 74 +++++--- WebSharpRSS/Program.cs | 2 + WebSharpRSS/WebSharpRSS.csproj | 18 ++ 5 files changed, 159 insertions(+), 143 deletions(-) rename SharpRss/{Services/DatabaseService.cs => DbAccess.cs} (63%) delete mode 100644 SharpRss/FeedCache.cs diff --git a/SharpRss/Services/DatabaseService.cs b/SharpRss/DbAccess.cs similarity index 63% rename from SharpRss/Services/DatabaseService.cs rename to SharpRss/DbAccess.cs index 0ff0f12..d2056a3 100644 --- a/SharpRss/Services/DatabaseService.cs +++ b/SharpRss/DbAccess.cs @@ -9,25 +9,23 @@ using Microsoft.Data.Sqlite; using Serilog; using SharpRss.Models; -namespace SharpRss.Services +namespace SharpRss { - internal class DatabaseService : IDisposable + public static class DbAccess { - internal DatabaseService() - { - InitializeDb(); - } - private readonly string _connectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};"; - private readonly string _groupTable = "group_data"; - private readonly string _feedTable = "feed_data"; - private readonly string _feedItemTable = "feed_item_data"; + private static bool _isInitialized; + private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};"; + private const string GroupTable = "group_data"; + private const string FeedTable = "feed_data"; + private const string FeedItemTable = "feed_item_data"; // Groups - public async Task> GetGroupsAsync(string? groupId = null) + public static async Task> GetGroupsAsync(string? groupId = null) { - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + CheckInitialized(); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {_groupTable} WHERE id=@gId;" : $"SELECT * FROM {_groupTable}", dbc) + await using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {GroupTable} WHERE id=@gId;" : $"SELECT * FROM {GroupTable}", dbc) { Parameters = { @@ -36,7 +34,7 @@ namespace SharpRss.Services }; await using SqliteDataReader reader = await cmd.ExecuteReaderAsync(); HashSet groups = new HashSet(); - await using SqliteCommand cmdFeedCount = new SqliteCommand($"SELECT COUNT(*) FROM {_feedTable} WHERE group_id=@groupId", dbc); + await using SqliteCommand cmdFeedCount = new SqliteCommand($"SELECT COUNT(*) FROM {FeedTable} WHERE group_id=@groupId", dbc); while (reader.Read()) { cmdFeedCount.Parameters.Clear(); @@ -55,12 +53,12 @@ namespace SharpRss.Services } return groups; } - public async Task SetGroupAsync(GroupModel groupModel) + public static async Task SetGroupAsync(GroupModel groupModel) { bool result = false; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {_groupTable} (id, hex_color, icon, name) VALUES (IFNULL((SELECT id FROM {_groupTable} WHERE name=@name), @id), @hexColor, @icon, @name)", dbc) + await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {GroupTable} (id, hex_color, icon, name) VALUES (IFNULL((SELECT id FROM {GroupTable} WHERE name=@name), @id), @hexColor, @icon, @name)", dbc) { Parameters = { @@ -75,13 +73,13 @@ namespace SharpRss.Services result = true; return result; } - public async Task RemoveGroupAsync(GroupModel groupModel) + public static async Task RemoveGroupAsync(GroupModel groupModel) { bool result = false; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); // Remove the group and remove the feeds that were part of the group. - await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {_groupTable} WHERE id=@id; UPDATE {_feedTable} SET group_id=NULL WHERE group_id=@id", dbc) + await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {GroupTable} WHERE id=@id; UPDATE {FeedTable} SET group_id=NULL WHERE group_id=@id", dbc) { Parameters = { @@ -99,12 +97,12 @@ namespace SharpRss.Services /// /// Empty = ungrouped feeds | null = all feeds | id = grouped feeds /// - public async Task> GetFeedsAsync(string? groupId = null) + public static async Task> GetFeedsAsync(string? groupId = null) { HashSet feeds = new HashSet(); - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {_feedTable} WHERE group_id=@groupId" : $"SELECT * FROM {_feedTable}", dbc) + await using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {FeedTable} WHERE group_id=@groupId" : $"SELECT * FROM {FeedTable}", dbc) { Parameters = { @@ -116,12 +114,12 @@ namespace SharpRss.Services feeds.Add(await ReaderToFeedModel(reader)); return feeds; } - public async Task GetFeedAsync(string feedId) + public static async Task GetFeedAsync(string feedId) { - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); FeedModel? feed = null; - await using SqliteCommand cmd = new SqliteCommand($"SELECT * FROM {_feedTable} WHERE id=@id", dbc) + await using SqliteCommand cmd = new SqliteCommand($"SELECT * FROM {FeedTable} WHERE id=@id", dbc) { Parameters = { new SqliteParameter("id", feedId) } }; @@ -130,40 +128,48 @@ namespace SharpRss.Services feed = await ReaderToFeedModel(reader); return feed; } - public async Task SetFeedAsync(FeedModel feedModel) + public static async Task SetFeedsAsync(IEnumerable feedModels) { FeedModel? resultModel = null; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {_feedTable} (id, url, title, group_id, feed_type, description, language, copyright, date_added, last_updated, image_url, original_document) VALUES (IFNULL((SELECT id FROM {_feedTable} WHERE url=@url), @id), @url, @title, @groupId, @feedType, @description, @language, @copyright, IFNULL((SELECT date_added FROM {_feedTable} WHERE id=@id), @dateAdded), @lastUpdated, @imageUrl, @originalDoc); SELECT * FROM {_feedTable} WHERE url=@url", dbc) + await using SqliteTransaction transaction = dbc.BeginTransaction(); + foreach (var feedModel in feedModels) { - Parameters = + //await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {_feedTable} (id, url, title, group_id, feed_type, description, language, copyright, date_added, last_updated, image_url, original_document) VALUES (IFNULL((SELECT id FROM {_feedTable} WHERE url=@url), @id), @url, @title, @groupId, @feedType, @description, @language, @copyright, IFNULL((SELECT date_added FROM {_feedTable} WHERE id=@id), @dateAdded), @lastUpdated, @imageUrl, @originalDoc); SELECT * FROM {_feedTable} WHERE url=@url", dbc) + await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {FeedTable} (id, url, title, group_id, feed_type, description, language, copyright, date_added, last_updated, image_url, original_document) VALUES (IFNULL((SELECT id FROM {FeedTable} WHERE url=@url), @id), @url, @title, @groupId, @feedType, @description, @language, @copyright, IFNULL((SELECT date_added FROM {FeedTable} WHERE id=@id), @dateAdded), @lastUpdated, @imageUrl, @originalDoc)", dbc) { - new SqliteParameter("id", feedModel.Id ?? string.Empty), - new SqliteParameter("url", feedModel.Url ?? string.Empty), - new SqliteParameter("title", feedModel.Title ?? string.Empty), - new SqliteParameter("groupId", feedModel.GroupId ?? string.Empty), - new SqliteParameter("feedType", feedModel.FeedType ?? string.Empty), - new SqliteParameter("description", feedModel.Description ?? string.Empty), - new SqliteParameter("language", feedModel.Language ?? string.Empty), - new SqliteParameter("copyright", feedModel.Copyright ?? string.Empty), - new SqliteParameter("dateAdded", feedModel.DateAdded?.ToUnixTimeMilliseconds()), - new SqliteParameter("lastUpdated", feedModel.LastUpdated?.ToUnixTimeMilliseconds()), - new SqliteParameter("imageUrl", feedModel.ImageUrl ?? string.Empty), - new SqliteParameter("originalDoc", feedModel.OriginalDocument ?? string.Empty) - } - }; - await using SqliteDataReader reader = await cmd.ExecuteReaderAsync(); - if (reader.Read()) - resultModel = await ReaderToFeedModel(reader); + Parameters = + { + new SqliteParameter("id", feedModel.Id ?? string.Empty), + new SqliteParameter("url", feedModel.Url ?? string.Empty), + new SqliteParameter("title", feedModel.Title ?? string.Empty), + new SqliteParameter("groupId", feedModel.GroupId ?? string.Empty), + new SqliteParameter("feedType", feedModel.FeedType ?? string.Empty), + new SqliteParameter("description", feedModel.Description ?? string.Empty), + new SqliteParameter("language", feedModel.Language ?? string.Empty), + new SqliteParameter("copyright", feedModel.Copyright ?? string.Empty), + new SqliteParameter("dateAdded", feedModel.DateAdded?.ToUnixTimeMilliseconds()), + new SqliteParameter("lastUpdated", feedModel.LastUpdated?.ToUnixTimeMilliseconds()), + new SqliteParameter("imageUrl", feedModel.ImageUrl ?? string.Empty), + 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; } - public async Task RemoveFeedAsync(FeedModel feedModel) + public static async Task RemoveFeedAsync(FeedModel feedModel) { bool result = false; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {_feedTable} WHERE id=@id; UPDATE {_feedItemTable} SET feed_id=NULL WHERE feed_id=@id", dbc) + await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {FeedTable} WHERE id=@id; UPDATE {FeedItemTable} SET feed_id=NULL WHERE feed_id=@id", dbc) { Parameters = { @@ -176,16 +182,16 @@ namespace SharpRss.Services return result; } // Feed items - public async Task> GetFeedItemsAsync(string[]? feedIds = null) + public static async Task> GetFeedItemsAsync(string[]? feedIds = null) { List? formattedIds = feedIds?.Select(s => $"'{s}'").ToList(); HashSet feedItems = new HashSet(); - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); await using SqliteCommand cmd = new SqliteCommand( formattedIds != null - ? $"SELECT * FROM {_feedItemTable} WHERE feed_id IN ({string.Join(", ", formattedIds)})" - : $"SELECT * FROM {_feedItemTable}", dbc); + ? $"SELECT * FROM {FeedItemTable} WHERE feed_id IN ({string.Join(", ", formattedIds)})" + : $"SELECT * FROM {FeedItemTable}", dbc); await using SqliteDataReader reader = await cmd.ExecuteReaderAsync(); while (reader.Read()) @@ -215,14 +221,14 @@ namespace SharpRss.Services } return feedItems; } - public async Task SetFeedItemsAsync(HashSet items) + public static async Task SetFeedItemsAsync(HashSet items) { int result = 0; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); await using SqliteTransaction transaction = dbc.BeginTransaction(); - await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {_feedItemTable} (id, feed_id, read, title, description, link, last_updated, publishing_date, author, categories, content)" + - $"VALUES (IFNULL((SELECT id FROM {_feedItemTable} WHERE link=@link), @id), @feedId, @read, @title, @description, @link, @lastUpdated, @publishingDate, @author, @categories, @content)", dbc); + await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {FeedItemTable} (id, feed_id, read, title, description, link, last_updated, publishing_date, author, categories, content)" + + $"VALUES (IFNULL((SELECT id FROM {FeedItemTable} WHERE link=@link), @id), @feedId, @read, @title, @description, @link, @lastUpdated, @publishingDate, @author, @categories, @content)", dbc); foreach (FeedItemModel item in items) { cmd.Parameters.Clear(); @@ -247,14 +253,14 @@ namespace SharpRss.Services result += affected; } transaction.Commit(); - return result; // Return the amount affected rows. + return result; } - public async Task RemoveFeedItemAsync(FeedItemModel itemModel) + public static async Task RemoveFeedItemAsync(FeedItemModel itemModel) { bool result = false; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {_feedItemTable} WHERE id=@id", dbc) + await using SqliteCommand cmd = new SqliteCommand($"DELETE FROM {FeedItemTable} WHERE id=@id", dbc) { Parameters = { @@ -266,12 +272,12 @@ namespace SharpRss.Services result = true; return result; } - public async Task GetGroupFromFeedItemAsync(FeedItemModel feedItem) + public static async Task GetGroupFromFeedItemAsync(FeedItemModel feedItem) { GroupModel? result = null; - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - await using SqliteCommand cmd = new SqliteCommand($"SELECT * FROM {_groupTable} WHERE id=(SELECT group_id FROM {_feedTable} WHERE id=@fId)", dbc) + await using SqliteCommand cmd = new SqliteCommand($"SELECT * FROM {GroupTable} WHERE id=(SELECT group_id FROM {FeedTable} WHERE id=@fId)", dbc) { Parameters = { @@ -286,7 +292,7 @@ namespace SharpRss.Services result = groups.FirstOrDefault(); return result; } - private async Task ReaderToFeedModel(SqliteDataReader reader) + private static async Task ReaderToFeedModel(SqliteDataReader reader) { FeedModel fetchedFeed = new FeedModel(reader["url"].ToString()) { @@ -309,22 +315,29 @@ namespace SharpRss.Services Log.Warning("Could not get group from feed: {FeedId}", fetchedFeed.Id); return fetchedFeed; } - private async void InitializeDb() + + //=== + private static void CheckInitialized() { + if (!_isInitialized) throw new TypeInitializationException(nameof(DbAccess), null); + } + public static async void Initialize() + { + if (_isInitialized) return; Log.Verbose("Checking database..."); HashSet failed = new HashSet(); - await using SqliteConnection dbc = new SqliteConnection(_connectionString); + await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - Log.Verbose("Checking table: {Table}", _groupTable); - var queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {_groupTable} (name STRING NOT NULL, hex_color STRING NOT NULL, icon STRING, id STRING PRIMARY KEY)"); + Log.Verbose("Checking table: {Table}", GroupTable); + var queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {GroupTable} (name STRING NOT NULL, hex_color STRING NOT NULL, icon STRING, id STRING PRIMARY KEY)"); if (queryResponse.Any()) failed.Add("category_data"); - Log.Verbose("Checking table: {Table}", _feedTable); - queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {_feedTable} (id STRING PRIMARY KEY, url STRING NOT NULL, title STRING, group_id STRING, feed_type STRING, description STRING, language STRING, copyright STRING, date_added INT, last_updated INT, image_url STRING, original_document STRING)"); + Log.Verbose("Checking table: {Table}", FeedTable); + queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {FeedTable} (id STRING PRIMARY KEY, url STRING NOT NULL, title STRING, group_id STRING, feed_type STRING, description STRING, language STRING, copyright STRING, date_added INT, last_updated INT, image_url STRING, original_document STRING)"); if (queryResponse.Any()) failed.Add("feed_data"); - Log.Verbose("Checking table: {Table}", _feedItemTable); - queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {_feedItemTable} (id STRING PRIMARY KEY, feed_id STRING, read INT, title STRING, description STRING, link STRING, last_updated INT, publishing_date INT, author STRING, categories STRING, content STRING)"); + Log.Verbose("Checking table: {Table}", FeedItemTable); + queryResponse = await dbc.QueryAsync($"CREATE TABLE IF NOT EXISTS {FeedItemTable} (id STRING PRIMARY KEY, feed_id STRING, read INT, title STRING, description STRING, link STRING, last_updated INT, publishing_date INT, author STRING, categories STRING, content STRING)"); if (queryResponse.Any()) failed.Add("feed_item_data"); if (failed.Any()) @@ -334,9 +347,7 @@ namespace SharpRss.Services } else Log.Verbose("Checking database done!"); - } - public void Dispose() - { + _isInitialized = true; } } } \ No newline at end of file diff --git a/SharpRss/FeedCache.cs b/SharpRss/FeedCache.cs deleted file mode 100644 index fe25ed0..0000000 --- a/SharpRss/FeedCache.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CodeHollow.FeedReader; -using Serilog; -using ToolQit.Extensions; - -namespace SharpRss -{ - /// - /// Global memory feed cache. - /// - public static class FeedCache - { - private static readonly Dictionary CachedFeeds = new Dictionary(); - public static async Task GetFeed(string urlKey) - { - Log.Verbose("Fetching feed: {UrlKey}", urlKey); - if (urlKey.IsNullEmptyWhiteSpace()) - { - Log.Error("RSS Url is empty!"); - return new Feed(); - } - - if (CachedFeeds.TryGetValue(urlKey, out Feed? fModel)) - return fModel; - string feedUrl; - var urls = await FeedReader.GetFeedUrlsFromUrlAsync(urlKey); - if (!urls.Any()) - feedUrl = urlKey; - else - feedUrl = urls.First().Url; - - Feed feed = await FeedReader.ReadAsync(feedUrl); - if (feed != null) - { - Log.Warning("Could not get feed: {FeedUrl}", feedUrl); - CachedFeeds[feedUrl] = feed; - } - return feed; - } - } -} \ No newline at end of file diff --git a/SharpRss/Services/RssService.cs b/SharpRss/Services/RssService.cs index d7f5bff..43d1589 100644 --- a/SharpRss/Services/RssService.cs +++ b/SharpRss/Services/RssService.cs @@ -17,7 +17,6 @@ namespace SharpRss.Services { SetupTestGroupsAndFeedsAsync(); } - private readonly DatabaseService _dbService = new DatabaseService(); public async Task> GetGroupsFeedsAsync() { @@ -26,20 +25,39 @@ namespace SharpRss.Services items.UnionWith(await GetUngroupedFeedsAsync()); return items; } - public async Task CreateGroupAsync(GroupModel group) => await _dbService.SetGroupAsync(group); - public async Task> GetGroupsAsync() => await _dbService.GetGroupsAsync(); + public async Task CreateGroupAsync(GroupModel group) => await DbAccess.SetGroupAsync(group); + public async Task> GetGroupsAsync() => await DbAccess.GetGroupsAsync(); //TODO: Need to rework this implementation!!! - /*public async Task FetchFeeds(string[]? rssUrls, GroupModel? group = null) + 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); + /*Feed fetched = await FetchFeed(rssUrl); if (fetched == null) return result; @@ -59,18 +77,19 @@ namespace SharpRss.Services FeedModel? dbFeed = await _dbService.SetFeedAsync(feedModel); result = dbFeed != null; if (dbFeed == null) - return result; - if (await AddFeedItems(fetched.Items, dbFeed) == 0) - Log.Warning("No feed items added to feed: {FeedUrl}", dbFeed.Url); + 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; - }*/ - public async Task> GetFeedsAsync(string? groupId = null) => await _dbService.GetFeedsAsync(groupId); - public async Task> GetUngroupedFeedsAsync() => await _dbService.GetFeedsAsync(""); + } + public async Task> GetFeedsAsync(string? groupId = null) => await DbAccess.GetFeedsAsync(groupId); + public async Task> GetUngroupedFeedsAsync() => await DbAccess.GetFeedsAsync(""); public async Task> GetFeedItemsAsync(string feedId, string? groupId = null) => await GetFeedItemsFromFeedsAsync(new[] { feedId }, groupId); public async Task> GetFeedItemsFromFeedsAsync(string[] feedIds, string? groupId = null) { - var items = await _dbService.GetFeedItemsAsync(feedIds); + var items = await DbAccess.GetFeedItemsAsync(feedIds); return items; } @@ -80,12 +99,22 @@ namespace SharpRss.Services if (!items.Any()) return result; HashSet itemModels = new HashSet(); + // TODO: implement!!! + result = await DbAccess.SetFeedItemsAsync(itemModels); + return result; + } + + private IList ConstructFeedItems(IList items, FeedModel feed) + { + IList itemModels = new List(); + if (!items.Any()) + return itemModels; foreach (FeedItem item in items) { itemModels.Add(new FeedItemModel() { Id = item.Id, - FeedId = feedModel.Id, + FeedId = feed.Id, Title = item.Title, Description = item.Description, Link = item.Link, @@ -96,10 +125,10 @@ namespace SharpRss.Services Content = item.Content }); } - result = await _dbService.SetFeedItemsAsync(itemModels); - return result; - } - private async Task FetchFeed(string url) + return itemModels; + } + + private async Task FetchFeed(string url) { Log.Verbose("Fetching feed: {FeedUrl}", url); var urls = await FeedReader.ParseFeedUrlsAsStringAsync(url); @@ -133,9 +162,8 @@ namespace SharpRss.Services }*/ } - public void Dispose() - { - _dbService.Dispose(); - } - } + public void Dispose() + { + } + } } \ No newline at end of file diff --git a/WebSharpRSS/Program.cs b/WebSharpRSS/Program.cs index 6c0969b..1f8389e 100644 --- a/WebSharpRSS/Program.cs +++ b/WebSharpRSS/Program.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Hosting; using MudBlazor; using MudBlazor.Services; using Serilog; +using SharpRss; using SharpRss.Services; using ToolQit; using WebSharpRSS; @@ -12,6 +13,7 @@ using WebSharpRSS.Models; Caretaker.Settings.SetAppDefaultSettings(); Bootstrapper.SetupLogging(); Log.Information("Starting..."); +DbAccess.Initialize(); var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); diff --git a/WebSharpRSS/WebSharpRSS.csproj b/WebSharpRSS/WebSharpRSS.csproj index 8283753..335455a 100644 --- a/WebSharpRSS/WebSharpRSS.csproj +++ b/WebSharpRSS/WebSharpRSS.csproj @@ -23,4 +23,22 @@ + + <_ContentIncludedByDefault Remove="logs\log_20230507.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230509.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230512.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230513.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230515.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230517.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230518.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230519.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230521.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230522.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230523.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230524.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230525.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230526.json" /> + <_ContentIncludedByDefault Remove="logs\log_20230527.json" /> + +