mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Dapper dynamic parameters broken.
This commit is contained in:
parent
6bcc053014
commit
3e49e2ebf1
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
@ -22,7 +23,12 @@ namespace SharpRss
|
|||
|
||||
public static async Task SetSyndicationAsync(SyndicationContainer synContainer)
|
||||
{
|
||||
|
||||
if (synContainer.Category != null)
|
||||
await SetCategoryAsync(synContainer.Category);
|
||||
if (synContainer.FeedModel != null)
|
||||
await SetFeedAsync(synContainer.FeedModel);
|
||||
if (synContainer.FeedItems != null && synContainer.FeedItems.Any())
|
||||
await SetFeedItemsAsync(synContainer.FeedItems);
|
||||
}
|
||||
|
||||
public static async Task<HashSet<CategoryModel>> GetCategoriesAsync()
|
||||
|
@ -67,20 +73,34 @@ namespace SharpRss
|
|||
{
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
int affected = await dbc.ExecuteAsync("INSERT OR REPLACE INTO feed (url, title, category_id, feed_type, feed_version, description, language, copyright, publication_date, last_updated, categories, image_url) VALUES (@Url, @Title, @CategoryId, @FeedType, @FeedVersion, @Description, @language, @Copyright, @PublicationDate, @LastUpdated, @Categories, @ImageUrl)", new
|
||||
{
|
||||
Url = feed.OriginalUrl,
|
||||
Title = feed.Title,
|
||||
CategoryId = feed.CategoryId,
|
||||
FeedType = feed.FeedType,
|
||||
Description = feed.Description,
|
||||
Language = feed.Language,
|
||||
Copyright = feed.Copyright,
|
||||
PublicationDate = feed.PublicationDate?.ToUnixTimeMilliseconds() ?? 0,
|
||||
LastUpdated = feed.LastUpdated?.ToUnixTimeMilliseconds() ?? 0,
|
||||
Categories = string.Join(',', feed.Categories),
|
||||
ImageUrl = feed.ImageUrl
|
||||
});
|
||||
DynamicParameters parameters = new DynamicParameters();
|
||||
parameters.Add("url", feed.OriginalUrl ?? string.Empty);
|
||||
parameters.Add("title", feed.Title ?? string.Empty);
|
||||
parameters.Add("categoryId", feed.CategoryId ?? string.Empty);
|
||||
parameters.Add("feedType", feed.FeedType ?? string.Empty);
|
||||
parameters.Add("description", feed.Description ?? string.Empty);
|
||||
parameters.Add("language", feed.Language ?? string.Empty);
|
||||
parameters.Add("copyright", feed.Copyright ?? string.Empty);
|
||||
parameters.Add("publicationDate", feed.PublicationDate?.ToUnixTimeMilliseconds() ?? 0);
|
||||
parameters.Add("lastUpdated", feed.LastUpdated?.ToUnixTimeMilliseconds() ?? 0);
|
||||
parameters.Add("categories", feed.Categories.Any() ? string.Join(',', feed.Categories) : string.Empty);
|
||||
parameters.Add("imageUrl", feed.ImageUrl ?? string.Empty);
|
||||
int affected = await dbc.ExecuteAsync("INSERT OR REPLACE INTO feed (url, title, category_id, feed_type, feed_version, description, language, copyright, publication_date, last_updated, categories, image_url) VALUES (@url, @title, @categoryId, @feedType, @feedVersion, @description, @language, @copyright, @publicationDate, @lastUpdated, @categories, @imageUrl)", param: parameters);
|
||||
/*int affected = await dbc.ExecuteAsync("INSERT OR REPLACE INTO feed (url, title, category_id, feed_type, feed_version, description, language, copyright, publication_date, last_updated, categories, image_url) VALUES (@Url, @Title, @CategoryId, @FeedType, @FeedVersion, @Description, @language, @Copyright, @PublicationDate, @LastUpdated, @Categories, @ImageUrl)",
|
||||
new
|
||||
{
|
||||
Url = feed.OriginalUrl ?? string.Empty,
|
||||
Title = feed.Title ?? string.Empty,
|
||||
CategoryId = feed.CategoryId ?? string.Empty,
|
||||
FeedType = feed.FeedType ?? string.Empty,
|
||||
Description = feed.Description ?? string.Empty,
|
||||
Language = feed.Language ?? string.Empty,
|
||||
Copyright = feed.Copyright ?? string.Empty,
|
||||
PublicationDate = feed.PublicationDate?.ToUnixTimeMilliseconds() ?? 0,
|
||||
LastUpdated = feed.LastUpdated?.ToUnixTimeMilliseconds() ?? 0,
|
||||
Categories = feed.Categories.Any() ? string.Join(',', feed.Categories) : string.Empty,
|
||||
ImageUrl = feed.ImageUrl ?? string.Empty
|
||||
});*/
|
||||
if (affected == 0)
|
||||
Log.Warning("Failed to add feed: {FeedUrl}", feed.OriginalUrl);
|
||||
}
|
||||
|
@ -114,6 +134,44 @@ namespace SharpRss
|
|||
|
||||
public static async Task SetFeedItemsAsync(HashSet<FeedItemModel> items)
|
||||
{
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
int totalAffected = 0;
|
||||
await using SqliteTransaction dbTransaction = dbc.BeginTransaction();
|
||||
foreach (FeedItemModel item in items)
|
||||
{
|
||||
DynamicParameters parameters = new DynamicParameters();
|
||||
parameters.Add("id", item.Id ?? string.Empty);
|
||||
parameters.Add("feedurl", item.FeedUrl ?? string.Empty);
|
||||
parameters.Add("read", item.Read.ToString());
|
||||
parameters.Add("description", item.Description ?? string.Empty);
|
||||
parameters.Add("link", item.Link ?? string.Empty);
|
||||
parameters.Add("lastUpdated", item.LastUpdated?.ToUnixTimeMilliseconds() ?? 0);
|
||||
parameters.Add("publishingDate", item.PublishingDate?.ToUnixTimeMilliseconds() ?? 0);
|
||||
parameters.Add("authors", item.Authors.Any() ? string.Join(',', item.Authors) : string.Empty);
|
||||
parameters.Add("categories", item.Categories.Any() ? string.Join(',', item.Categories) : string.Empty);
|
||||
parameters.Add("content", item.Content ?? string.Empty);
|
||||
int affected = await dbc.ExecuteAsync("INSERT OR REPLACE INTO feed_item (id, feed_url, read, title, description, link, last_updated, publishing_date, authors, categories, content) VALUES (@id, @feedUrl, @read, @title, @description, @link, @lastUpdated, @publishingDate, @authors, @categories, @content)",
|
||||
parameters,
|
||||
transaction: dbTransaction);
|
||||
/*int affected = await dbc.ExecuteAsync("INSERT OR REPLACE INTO feed_item (id, feed_url, read, title, description, link, last_updated, publishing_date, authors, categories, content) VALUES (@Id, @FeedUrl, @Read, @Title, Description, @Link, @LastUpdated, @PublishingDate, @Authors, @Categories, @Content)",
|
||||
transaction: dbTransaction,
|
||||
param: new
|
||||
{
|
||||
Id = item.Id ?? string.Empty,
|
||||
FeedUrl = item.FeedUrl ?? string.Empty,
|
||||
Read = item.Read.ToString(),
|
||||
Description = item.Description ?? string.Empty,
|
||||
Link = item.Link ?? string.Empty,
|
||||
LastUpdated = item.LastUpdated?.ToUnixTimeMilliseconds() ?? 0,
|
||||
PublishingDate = item.PublishingDate?.ToUnixTimeMilliseconds() ?? 0,
|
||||
Authors = item.Authors.Any() ? string.Join(',', item.Authors) : string.Empty,
|
||||
Categories = item.Categories.Any() ? string.Join(',', item.Categories) : string.Empty,
|
||||
Content = item.Content ?? string.Empty
|
||||
});*/
|
||||
totalAffected += affected;
|
||||
}
|
||||
dbTransaction.Commit();
|
||||
}
|
||||
public static async Task<HashSet<FeedItemModel>> GetFeedItemsAsync(string[]? feedUrls)
|
||||
{
|
||||
|
@ -127,7 +185,7 @@ namespace SharpRss
|
|||
{
|
||||
Id = reader["id"].ToString(),
|
||||
FeedUrl = reader["feed_url"].ToString(),
|
||||
Read = int.TryParse(reader["read"].ToString(), out int parsedValue) && parsedValue != 0,
|
||||
Read = bool.Parse(reader["read"].ToString()),
|
||||
Title = reader["title"].ToString(),
|
||||
Description = reader["description"].ToString(),
|
||||
Link = reader["link"].ToString(),
|
||||
|
@ -155,7 +213,7 @@ namespace SharpRss
|
|||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS feed (url STRING PRIMARY KEY, title STRING, category_id STRING, feed_type STRING, feed_version STRING, description STRING, language STRING, copyright STRING, publication_date INT, last_updated INT, categories STRING, image_url STRING)");
|
||||
|
||||
Log.Verbose("Checking table: {Table}", "feed_item");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS feed_item (id STRING PRIMARY KEY, feed_url STRING, read INT, title STRING, description STRING, link STRING, last_updated INT, publishing_date INT, authors STRING, categories STRING, content STRING)");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS feed_item (id STRING PRIMARY KEY, feed_url STRING, read STRING, title STRING, description STRING, link STRING, last_updated INT, publishing_date INT, authors STRING, categories STRING, content STRING)");
|
||||
Log.Verbose("Checking database done!");
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace SharpRss.Services
|
|||
if (category != null)
|
||||
syndication.Category = category;
|
||||
if (!syndication.Fetched) return false;
|
||||
|
||||
await DbAccess.SetSyndicationAsync(syndication);
|
||||
return true;
|
||||
}
|
||||
private static FeedModel FromResource(ISyndicationResource resource)
|
||||
|
@ -131,7 +131,7 @@ namespace SharpRss.Services
|
|||
{
|
||||
/*CategoryModel newModel = new CategoryModel() { Name = "Test" };
|
||||
bool added = await DbAccess.SetCategoryAsync(newModel);*/
|
||||
//await AddSubscriptionAsync("https://en.wikipedia.org/w/api.php?hidebots=1&hidecategorization=1&hideWikibase=1&urlversion=1&days=7&limit=50&action=feedrecentchanges&feedformat=atom");
|
||||
await AddSubscriptionAsync("https://en.wikipedia.org/w/api.php?hidebots=1&hidecategorization=1&hideWikibase=1&urlversion=1&days=7&limit=50&action=feedrecentchanges&feedformat=atom");
|
||||
//TODO: Make multiple adding of feed to a transaction, now throws an exception.
|
||||
/*var groupRes = await CreateGroupAsync(new GroupModel() { Name = "Test" });
|
||||
groupRes = await CreateGroupAsync(new GroupModel() { Name = "News" });
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user