mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 04:44:20 +01:00
Updated submodule 'ToolQit' & reworked some logging
This commit is contained in:
parent
9e4f0172e7
commit
2becd02f53
|
@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ToolQit", "ToolQit\ToolQit\
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSyndicationApi", "SharpSyndicationApi\SharpSyndicationApi.csproj", "{349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolQit.Logging.Serilog", "..\ToolQit\ToolQit.Logging.Serilog\ToolQit.Logging.Serilog.csproj", "{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -33,6 +35,10 @@ Global
|
|||
{349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -6,9 +6,10 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Serilog;
|
||||
using SharpRss.Core.Cache;
|
||||
using SharpRss.Models;
|
||||
using ToolQit;
|
||||
using ToolQit.Logging;
|
||||
|
||||
namespace SharpRss
|
||||
{
|
||||
|
@ -21,6 +22,7 @@ namespace SharpRss
|
|||
}
|
||||
internal static class DbAccess
|
||||
{
|
||||
private static readonly ILog _log = LogManager.CreateLogger(typeof(DbAccess));
|
||||
private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};";
|
||||
private static bool _isInitialized;
|
||||
|
||||
|
@ -129,7 +131,7 @@ namespace SharpRss
|
|||
ImageUrl = syndication.ImageUrl ?? string.Empty
|
||||
});
|
||||
if (affected == 0)
|
||||
Log.Warning("Failed to add feed: {FeedUrl}", syndication.EncodedUrl);
|
||||
_log.Warning("Failed to add feed: {FeedUrl}", syndication.EncodedUrl);
|
||||
}
|
||||
public static async Task<HashSet<SyndicationModel>> GetSyndicationsAsync(string[]? categoryIds = null)
|
||||
{
|
||||
|
@ -165,7 +167,7 @@ namespace SharpRss
|
|||
public static async Task<bool> DeleteSyndicationAsync(SyndicationModel syndication, bool deleteItems = false)
|
||||
{
|
||||
if (syndication == null) return false;
|
||||
Log.Information("Removing syndication...");
|
||||
_log.Information("Removing syndication...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
int affected = await dbc.ExecuteAsync("DELETE FROM syndication WHERE encoded_url=@EncodedUrl", new { EncodedUrl = syndication.EncodedUrl });
|
||||
if (affected > 0 && deleteItems)
|
||||
|
@ -175,7 +177,7 @@ namespace SharpRss
|
|||
|
||||
public static async Task SetSyndicationItemsAsync(HashSet<SyndicationItemModel> items)
|
||||
{
|
||||
Log.Information("Inserting syndication items...");
|
||||
_log.Information("Inserting syndication items...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
int totalAffected = 0;
|
||||
|
@ -237,25 +239,25 @@ namespace SharpRss
|
|||
syndicationItemModel.SyndicationParent = TempCache.GetSyndication(syndicationItemModel.EncodedSyndicationUrl) ?? new SyndicationModel(); // The new syndication should never be initialized, if this hits then the date is not valid for some reason!!!
|
||||
items.Add(syndicationItemModel);
|
||||
}
|
||||
Log.Information("Fetching feed items resulted: {ItemCount} item(s)", items.Count);
|
||||
_log.Information("Fetching feed items resulted: {ItemCount} item(s)", items.Count);
|
||||
state.Items = items;
|
||||
return true;
|
||||
}
|
||||
public static async void Initialize()
|
||||
{
|
||||
if (_isInitialized) return;
|
||||
Log.Verbose("Checking database...");
|
||||
_log.Verbose("Checking database...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
Log.Information("Checking table: {Table}", "category");
|
||||
_log.Information("Checking table: {Table}", "category");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS category (id STRING PRIMARY KEY, name STRING NOT NULL, hex_color STRING NOT NULL, icon STRING, last_updated INT)");
|
||||
|
||||
Log.Information("Checking table: {Table}", "syndication");
|
||||
_log.Information("Checking table: {Table}", "syndication");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS syndication (encoded_url STRING PRIMARY KEY, title STRING, category_id STRING, syndication_type STRING, version STRING, description STRING, language STRING, copyright STRING, last_updated INT, publication_date INT, syn_updated_date INT, categories STRING, image_url STRING)");
|
||||
|
||||
Log.Information("Checking table: {Table}", "syndication_item");
|
||||
_log.Information("Checking table: {Table}", "syndication_item");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS syndication_item (link STRING PRIMARY KEY, encoded_syndication_url STRING, read STRING, type STRING, title STRING, description STRING, last_updated INT, item_updated_date INT, publishing_date INT, authors STRING, categories STRING, content STRING, comments_url STRING)");
|
||||
Log.Information("Checking database done!");
|
||||
_log.Information("Checking database done!");
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
|||
using System.Threading.Tasks;
|
||||
using Argotic.Common;
|
||||
using Argotic.Syndication;
|
||||
using Serilog;
|
||||
using SharpRss.Models;
|
||||
using ToolQit;
|
||||
using ToolQit.Logging;
|
||||
|
||||
namespace SharpRss.Services
|
||||
{
|
||||
|
@ -13,9 +14,11 @@ namespace SharpRss.Services
|
|||
/// </summary>
|
||||
public class SyndicationService
|
||||
{
|
||||
private readonly ILog _log;
|
||||
public SyndicationService()
|
||||
{
|
||||
Log.Information("Constructing SyndicationService...");
|
||||
_log = LogManager.CreateLogger(typeof(SyndicationService));
|
||||
_log.Information("Constructing SyndicationService...");
|
||||
Task.Run(async () => await SetupTestCategoriesAndFeedsAsync());
|
||||
}
|
||||
|
||||
|
@ -47,7 +50,7 @@ namespace SharpRss.Services
|
|||
var syndication = SyndicationManager.CreateSyndication(url);
|
||||
if (!syndication.Fetched)
|
||||
{
|
||||
Log.Warning("Failed to fetch syndication feed!");
|
||||
_log.Warning("Failed to fetch syndication feed!");
|
||||
return false;
|
||||
}
|
||||
if (category != null)
|
||||
|
@ -58,13 +61,13 @@ namespace SharpRss.Services
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e,"Error adding syndication: {FeedUrl} to database!", url);
|
||||
_log.Error(e,"Error adding syndication: {FeedUrl} to database!", url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public async Task UpdateFeeds()
|
||||
{
|
||||
Log.Information("Fetching...");
|
||||
_log.Information("Fetching...");
|
||||
var feeds = await GetSyndicationsAsync();
|
||||
}
|
||||
public async Task<HashSet<SyndicationModel>> GetSyndicationsAsync(string? categoryId = null) => await DbAccess.GetSyndicationsAsync(categoryId == null ? null : new[]{ categoryId });
|
||||
|
@ -79,7 +82,7 @@ namespace SharpRss.Services
|
|||
|
||||
|
||||
|
||||
private static SyndicationModel FromResource(ISyndicationResource resource)
|
||||
/*private static SyndicationModel FromResource(ISyndicationResource resource)
|
||||
{
|
||||
SyndicationModel model = new SyndicationModel();
|
||||
switch (resource.Format)
|
||||
|
@ -98,26 +101,26 @@ namespace SharpRss.Services
|
|||
AtomFeed atomFeed = (AtomFeed)resource;
|
||||
break;
|
||||
default:
|
||||
Log.Information("Syndication implementation missing!");
|
||||
_log.Information("Syndication implementation missing!");
|
||||
break;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}*/
|
||||
private GenericSyndicationFeed? CreateSyndication(string url)
|
||||
{
|
||||
Uri feedUri = new Uri(url);
|
||||
Log.Verbose("Checking syndication: {FeedUrl}", feedUri.ToString());
|
||||
_log.Verbose("Checking syndication: {FeedUrl}", feedUri.ToString());
|
||||
if (!SyndicationDiscoveryUtility.UriExists(feedUri))
|
||||
{
|
||||
Log.Warning("Syndication: {FeedUri} does not exists!", feedUri.ToString());
|
||||
_log.Warning("Syndication: {FeedUri} does not exists!", feedUri.ToString());
|
||||
return null;
|
||||
}
|
||||
Log.Verbose("Fetching syndication: {FeedUrl}", feedUri.ToString());
|
||||
_log.Verbose("Fetching syndication: {FeedUrl}", feedUri.ToString());
|
||||
return GenericSyndicationFeed.Create(new Uri(url));
|
||||
}
|
||||
private async Task SetupTestCategoriesAndFeedsAsync()
|
||||
{
|
||||
Log.Information("Setting up test data...");
|
||||
_log.Information("Setting up test data...");
|
||||
try
|
||||
{
|
||||
CategoryModel? newsCategory = await CreateCategoryAsync(new CategoryModel() { Name = "News", Icon = "<g><rect fill=\"none\" height=\"24\" width=\"24\"/></g><g><path d=\"M22,3l-1.67,1.67L18.67,3L17,4.67L15.33,3l-1.66,1.67L12,3l-1.67,1.67L8.67,3L7,4.67L5.33,3L3.67,4.67L2,3v16 c0,1.1,0.9,2,2,2l16,0c1.1,0,2-0.9,2-2V3z M11,19H4v-6h7V19z M20,19h-7v-2h7V19z M20,15h-7v-2h7V15z M20,11H4V8h16V11z\"/></g>"});
|
||||
|
@ -156,7 +159,7 @@ namespace SharpRss.Services
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Exception!");
|
||||
_log.Error(e, "Exception!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@ using System.Text;
|
|||
using Argotic.Common;
|
||||
using Argotic.Extensions.Core;
|
||||
using Argotic.Syndication;
|
||||
using Serilog;
|
||||
using SharpRss.Models;
|
||||
using ToolQit;
|
||||
using ToolQit.Logging;
|
||||
|
||||
namespace SharpRss
|
||||
{
|
||||
|
@ -21,18 +22,19 @@ namespace SharpRss
|
|||
}
|
||||
public static class SyndicationManager
|
||||
{
|
||||
private static ILog _log = LogManager.CreateLogger(typeof(SyndicationManager));
|
||||
public static SyndicationContainer CreateSyndication(string feedUrl)
|
||||
{
|
||||
GenericSyndicationFeed? syndicationFeed = null;
|
||||
Uri feedUri = new Uri(feedUrl);
|
||||
try
|
||||
{
|
||||
Log.Information("Fetching syndication: {SyndicationUri}", feedUri.ToString());
|
||||
_log.Information("Fetching syndication: {SyndicationUri}", feedUri.ToString());
|
||||
syndicationFeed = GenericSyndicationFeed.Create(feedUri);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e,"Could not get syndication: {SyndicationUrl}", feedUrl);
|
||||
_log.Error(e,"Could not get syndication: {SyndicationUrl}", feedUrl);
|
||||
}
|
||||
return ConstructSyndicationContainer(syndicationFeed, feedUrl);
|
||||
}
|
||||
|
@ -42,7 +44,7 @@ namespace SharpRss
|
|||
MemoryStream memStream = new MemoryStream();
|
||||
syndicationFeed.Resource.Save(memStream);
|
||||
if (memStream.Length <= 0)
|
||||
Log.Warning("Failed to serialize {SyndicationType} feed: {SyndicationUri}", syndicationFeed.Format.ToString(), syndicationFeed.Title);
|
||||
_log.Warning("Failed to serialize {SyndicationType} feed: {SyndicationUri}", syndicationFeed.Format.ToString(), syndicationFeed.Title);
|
||||
memStream.Position = 0;
|
||||
return memStream;
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ namespace SharpRss
|
|||
SyndicationContainer container = new SyndicationContainer();
|
||||
if (syndicationFeed == null)
|
||||
{
|
||||
Log.Error("Could not construct syndication container!");
|
||||
_log.Warning("Could not construct syndication container!");
|
||||
return container;
|
||||
}
|
||||
container.SyndicationFeed = syndicationFeed;
|
||||
|
@ -122,7 +124,7 @@ namespace SharpRss
|
|||
}
|
||||
break;
|
||||
default:
|
||||
Log.Warning("Syndication implementation missing!");
|
||||
_log.Warning("Syndication implementation missing!");
|
||||
break;
|
||||
}
|
||||
container.Fetched = true;
|
||||
|
|
2
ToolQit
2
ToolQit
|
@ -1 +1 @@
|
|||
Subproject commit d8bd813a7261ffd2d8923606d6362644a8e8c6de
|
||||
Subproject commit 4983d4524cbdc424a9e0d8754eb5889f36450b79
|
|
@ -5,6 +5,8 @@ using Serilog.Formatting.Json;
|
|||
using SharpRss;
|
||||
using ToolQit;
|
||||
using ToolQit.Containers;
|
||||
using ToolQit.Logging;
|
||||
using ToolQit.Logging.Serilog;
|
||||
|
||||
namespace WebSharpRSS
|
||||
{
|
||||
|
@ -12,6 +14,7 @@ namespace WebSharpRSS
|
|||
{
|
||||
private static bool _defaultsSet;
|
||||
private static bool _bootstrapped;
|
||||
private static readonly ILog Log = LogManager.CreateLogger(typeof(Bootstrapper));
|
||||
|
||||
public static void Bootstrap()
|
||||
{
|
||||
|
@ -38,12 +41,14 @@ namespace WebSharpRSS
|
|||
if (!_defaultsSet) throw new Exception("Bootstrapper defaults are not initialized!");
|
||||
if (_configuration != null) return;
|
||||
_configuration = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.Enrich.With(new LogEnricher())
|
||||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} - {Sender} | {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||
.WriteTo.File(new JsonFormatter(), Caretaker.Settings["Paths"].GetString("LogPath"),
|
||||
rollingInterval: RollingInterval.Day);
|
||||
/*.MinimumLevel.Verbose(); // ONLY FOR DEBUGGING!!!*/
|
||||
|
||||
Log.Logger = _configuration.CreateLogger();
|
||||
Serilog.Log.Logger = _configuration.CreateLogger();
|
||||
LogManager.RegisterAdapter(new SerilogAdapter(Serilog.Log.Logger));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ToolQit\ToolQit.Logging.Serilog\ToolQit.Logging.Serilog.csproj" />
|
||||
<ProjectReference Include="..\SharpRss\SharpRss.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Binary file not shown.
3
git-cmd.md
Normal file
3
git-cmd.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
## Update all submoduels
|
||||
git submodule update --remote --merge
|
Loading…
Reference in New Issue
Block a user