mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Storage - Replace LiteDB with SQLite + EF Core (#843)
Storage - Added LiteDB to SQLite migration UI - Try to die a bit more gracefully Core - Delay start watching plugins for hot reload after initializing UI - Simplify category management logic UI - Avoid crash during profile icon load Storage - Fix entry metadata retrieval
This commit is contained in:
1 parent
9132301dbf
commit
551921db9f
130 files changed
+2965
-1135
No files matched your search
+2
-2
@@ -74,9 +74,9 @@ public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
try
|
||||
{
|
||||
// Find the profile if still there
|
||||
ProfileConfiguration? profile = _profileService.ProfileConfigurations.FirstOrDefault(c => c.ProfileId == profileId);
|
||||
ProfileConfiguration? profile = _profileService.ProfileCategories.SelectMany(c => c.ProfileConfigurations).FirstOrDefault(c => c.ProfileId == profileId);
|
||||
if (profile != null)
|
||||
_profileService.DeleteProfile(profile);
|
||||
_profileService.RemoveProfileConfiguration(profile);
|
||||
|
||||
// Remove the release
|
||||
_workshopService.RemoveInstalledEntry(installedEntry);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Artemis.Core;
|
||||
using Artemis.Storage.Entities.Workshop;
|
||||
|
||||
@@ -6,7 +8,7 @@ namespace Artemis.WebClient.Workshop.Models;
|
||||
|
||||
public class InstalledEntry
|
||||
{
|
||||
private Dictionary<string, object> _metadata = new();
|
||||
private Dictionary<string, JsonNode> _metadata = new();
|
||||
|
||||
internal InstalledEntry(EntryEntity entity)
|
||||
{
|
||||
@@ -52,7 +54,7 @@ public class InstalledEntry
|
||||
ReleaseVersion = Entity.ReleaseVersion;
|
||||
InstalledAt = Entity.InstalledAt;
|
||||
|
||||
_metadata = Entity.Metadata != null ? new Dictionary<string, object>(Entity.Metadata) : new Dictionary<string, object>();
|
||||
_metadata = Entity.Metadata != null ? new Dictionary<string, JsonNode>(Entity.Metadata) : new Dictionary<string, JsonNode>();
|
||||
}
|
||||
|
||||
internal void Save()
|
||||
@@ -67,7 +69,7 @@ public class InstalledEntry
|
||||
Entity.ReleaseVersion = ReleaseVersion;
|
||||
Entity.InstalledAt = InstalledAt;
|
||||
|
||||
Entity.Metadata = new Dictionary<string, object>(_metadata);
|
||||
Entity.Metadata = new Dictionary<string, JsonNode>(_metadata);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,14 +82,14 @@ public class InstalledEntry
|
||||
/// <returns><see langword="true"/> if the metadata contains an element with the specified key; otherwise, <see langword="false"/>.</returns>
|
||||
public bool TryGetMetadata<T>(string key, [NotNullWhen(true)] out T? value)
|
||||
{
|
||||
if (!_metadata.TryGetValue(key, out object? objectValue) || objectValue is not T result)
|
||||
if (!_metadata.TryGetValue(key, out JsonNode? element))
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
value = result;
|
||||
return true;
|
||||
value = element.GetValue<T>();
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,7 +99,7 @@ public class InstalledEntry
|
||||
/// <param name="value">The value to set.</param>
|
||||
public void SetMetadata(string key, object value)
|
||||
{
|
||||
_metadata[key] = value;
|
||||
_metadata[key] = JsonSerializer.SerializeToNode(value) ?? throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
using Artemis.WebClient.Workshop.Entities;
|
||||
using LiteDB;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Repositories;
|
||||
|
||||
internal class AuthenticationRepository : IAuthenticationRepository
|
||||
{
|
||||
private readonly LiteRepository _repository;
|
||||
private readonly PluginSetting<string> _refreshToken;
|
||||
|
||||
public AuthenticationRepository(LiteRepository repository)
|
||||
public AuthenticationRepository(ISettingsService settingsService)
|
||||
{
|
||||
_repository = repository;
|
||||
_repository.Database.GetCollection<RefreshTokenEntity>().EnsureIndex(s => s.RefreshToken);
|
||||
// Of course anyone can grab these indirectly, but that goes for whatever we do.
|
||||
// ISettingsService is a protected service so we at least don't make it very straightforward.
|
||||
_refreshToken = settingsService.GetSetting<string>("Workshop.RefreshToken");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetRefreshToken(string? refreshToken)
|
||||
{
|
||||
_repository.Database.GetCollection<RefreshTokenEntity>().DeleteAll();
|
||||
|
||||
if (refreshToken != null)
|
||||
_repository.Insert(new RefreshTokenEntity {RefreshToken = refreshToken});
|
||||
_refreshToken.Value = refreshToken;
|
||||
_refreshToken.Save();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? GetRefreshToken()
|
||||
{
|
||||
return _repository.Query<RefreshTokenEntity>().FirstOrDefault()?.RefreshToken;
|
||||
return _refreshToken.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user