Add support for per-feed user agent

This commit is contained in:
2023-06-15 17:28:38 -04:00
parent f5f78c8825
commit 0ddd38e3f2
7 changed files with 126 additions and 43 deletions

View File

@@ -1,22 +1,31 @@
using FeedCenter.Data;
using System;
using System.Linq;
using FeedCenter.Data;
using FeedCenter.Options;
using Realms;
using System;
using System.Linq;
namespace FeedCenter;
public class FeedCenterEntities
{
public Realm RealmInstance { get; }
public RealmObservableCollection<Category> Categories { get; }
public RealmObservableCollection<Feed> Feeds { get; private set; }
public RealmObservableCollection<Setting> Settings { get; private set; }
public FeedCenterEntities()
{
var realmConfiguration = new RealmConfiguration($"{Database.DatabaseFile}");
var realmConfiguration = new RealmConfiguration($"{Database.DatabaseFile}")
{
SchemaVersion = 1,
MigrationCallback = (migration, oldSchemaVersion) =>
{
var newVersionFeeds = migration.NewRealm.All<Feed>();
foreach (var newVersionFeed in newVersionFeeds)
{
if (oldSchemaVersion == 0)
{
newVersionFeed.UserAgent = null;
}
}
}
};
RealmInstance = Realm.GetInstance(realmConfiguration);
@@ -30,6 +39,17 @@ public class FeedCenterEntities
}
}
public RealmObservableCollection<Category> Categories { get; }
public Category DefaultCategory
{
get { return Categories.First(c => c.IsDefault); }
}
public RealmObservableCollection<Feed> Feeds { get; private set; }
private Realm RealmInstance { get; }
public RealmObservableCollection<Setting> Settings { get; private set; }
public void Refresh()
{
RealmInstance.Refresh();
@@ -44,9 +64,4 @@ public class FeedCenterEntities
{
return RealmInstance.BeginWrite();
}
public Category DefaultCategory
{
get { return Categories.First(c => c.IsDefault); }
}
}