mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 02:33:32 +00:00
Compare commits
5 Commits
110b6b90a0
...
be92701c67
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be92701c67 | ||
|
|
24f470a480 | ||
|
|
6956f09bb6 | ||
|
|
5203e95141 | ||
|
|
2e600e76b0 |
@ -458,19 +458,23 @@ internal class ProfileService : IProfileService
|
|||||||
if (profileEntry == null)
|
if (profileEntry == null)
|
||||||
throw new ArtemisCoreException("Could not import profile, profile.json missing");
|
throw new ArtemisCoreException("Could not import profile, profile.json missing");
|
||||||
|
|
||||||
|
// Deserialize profile configuration to JObject
|
||||||
await using Stream configurationStream = configurationEntry.Open();
|
await using Stream configurationStream = configurationEntry.Open();
|
||||||
using StreamReader configurationReader = new(configurationStream);
|
using StreamReader configurationReader = new(configurationStream);
|
||||||
ProfileConfigurationEntity? configurationEntity = JsonConvert.DeserializeObject<ProfileConfigurationEntity>(await configurationReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
JObject? configurationJson = JsonConvert.DeserializeObject<JObject>(await configurationReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
||||||
if (configurationEntity == null)
|
// Deserialize profile to JObject
|
||||||
throw new ArtemisCoreException("Could not import profile, failed to deserialize configuration.json");
|
|
||||||
|
|
||||||
await using Stream profileStream = profileEntry.Open();
|
await using Stream profileStream = profileEntry.Open();
|
||||||
using StreamReader profileReader = new(profileStream);
|
using StreamReader profileReader = new(profileStream);
|
||||||
JObject? profileJson = JsonConvert.DeserializeObject<JObject>(await profileReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
JObject? profileJson = JsonConvert.DeserializeObject<JObject>(await profileReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
||||||
|
|
||||||
// Before deserializing, apply any pending migrations
|
// Before deserializing, apply any pending migrations
|
||||||
MigrateProfile(configurationEntity, profileJson);
|
MigrateProfile(configurationJson, profileJson);
|
||||||
|
|
||||||
|
// Deserialize profile configuration to ProfileConfigurationEntity
|
||||||
|
ProfileConfigurationEntity? configurationEntity = configurationJson?.ToObject<ProfileConfigurationEntity>(JsonSerializer.Create(IProfileService.ExportSettings));
|
||||||
|
if (configurationEntity == null)
|
||||||
|
throw new ArtemisCoreException("Could not import profile, failed to deserialize configuration.json");
|
||||||
|
// Deserialize profile to ProfileEntity
|
||||||
ProfileEntity? profileEntity = profileJson?.ToObject<ProfileEntity>(JsonSerializer.Create(IProfileService.ExportSettings));
|
ProfileEntity? profileEntity = profileJson?.ToObject<ProfileEntity>(JsonSerializer.Create(IProfileService.ExportSettings));
|
||||||
if (profileEntity == null)
|
if (profileEntity == null)
|
||||||
throw new ArtemisCoreException("Could not import profile, failed to deserialize profile.json");
|
throw new ArtemisCoreException("Could not import profile, failed to deserialize profile.json");
|
||||||
@ -555,18 +559,20 @@ internal class ProfileService : IProfileService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateProfile(ProfileConfigurationEntity configurationEntity, JObject? profileJson)
|
private void MigrateProfile(JObject? configurationJson, JObject? profileJson)
|
||||||
{
|
{
|
||||||
if (profileJson == null)
|
if (configurationJson == null || profileJson == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
configurationJson["Version"] ??= 0;
|
||||||
|
|
||||||
foreach (IProfileMigration profileMigrator in _profileMigrators.OrderBy(m => m.Version))
|
foreach (IProfileMigration profileMigrator in _profileMigrators.OrderBy(m => m.Version))
|
||||||
{
|
{
|
||||||
if (profileMigrator.Version <= configurationEntity.Version)
|
if (profileMigrator.Version <= configurationJson["Version"]!.Value<int>())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
profileMigrator.Migrate(profileJson);
|
profileMigrator.Migrate(configurationJson, profileJson);
|
||||||
configurationEntity.Version = profileMigrator.Version;
|
configurationJson["Version"] = profileMigrator.Version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,5 +5,5 @@ namespace Artemis.Storage.Migrations;
|
|||||||
public interface IProfileMigration
|
public interface IProfileMigration
|
||||||
{
|
{
|
||||||
int Version { get; }
|
int Version { get; }
|
||||||
void Migrate(JObject profileJson);
|
void Migrate(JObject configurationJson, JObject profileJson);
|
||||||
}
|
}
|
||||||
@ -12,7 +12,7 @@ internal class M0001NodeProviders : IProfileMigration
|
|||||||
public int Version => 1;
|
public int Version => 1;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Migrate(JObject profileJson)
|
public void Migrate(JObject configurationJson, JObject profileJson)
|
||||||
{
|
{
|
||||||
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
|
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
|
||||||
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
|
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Artemis.Storage.Migrations.Profile;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Migrates nodes to be provider-based on profile configurations as well..
|
||||||
|
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
|
||||||
|
/// </summary>
|
||||||
|
internal class M0002NodeProvidersProfileConfig : IProfileMigration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int Version => 2;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Migrate(JObject configurationJson, JObject profileJson)
|
||||||
|
{
|
||||||
|
MigrateNodeScript(configurationJson["ActivationCondition"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateNodeScript(JToken? nodeScript)
|
||||||
|
{
|
||||||
|
if (nodeScript == null || !nodeScript.HasValues)
|
||||||
|
return;
|
||||||
|
|
||||||
|
JArray? nodes = (JArray?) nodeScript["Nodes"]?["$values"];
|
||||||
|
if (nodes == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (JToken node in nodes)
|
||||||
|
{
|
||||||
|
node["Type"] = node["Type"]?.Value<string>()?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||||
|
node["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,28 +10,33 @@ public class M0024NodeProviders : IStorageMigration
|
|||||||
|
|
||||||
public void Apply(LiteRepository repository)
|
public void Apply(LiteRepository repository)
|
||||||
{
|
{
|
||||||
List<ProfileCategoryEntity> profileCategories = repository.Query<ProfileCategoryEntity>().ToList();
|
ILiteCollection<BsonDocument> categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity");
|
||||||
foreach (ProfileCategoryEntity profileCategory in profileCategories)
|
List<BsonDocument> categoriesToUpdate = new();
|
||||||
|
foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll())
|
||||||
{
|
{
|
||||||
foreach (ProfileConfigurationEntity profileConfigurationEntity in profileCategory.ProfileConfigurations)
|
BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray;
|
||||||
|
if (profiles != null)
|
||||||
{
|
{
|
||||||
profileConfigurationEntity.Version = 1;
|
foreach (BsonValue profile in profiles)
|
||||||
|
profile["Version"] = 1;
|
||||||
|
categoriesToUpdate.Add(profileCategoryBson);
|
||||||
}
|
}
|
||||||
repository.Update(profileCategory);
|
|
||||||
}
|
}
|
||||||
|
categoryCollection.Update(categoriesToUpdate);
|
||||||
|
|
||||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||||
|
List<BsonDocument> profilesToUpdate = new();
|
||||||
foreach (BsonDocument profileBson in collection.FindAll())
|
foreach (BsonDocument profileBson in collection.FindAll())
|
||||||
{
|
{
|
||||||
BsonArray? folders = profileBson["Folders"]?.AsArray;
|
BsonArray? folders = profileBson["Folders"]?.AsArray;
|
||||||
BsonArray? layers = profileBson["Layers"]?.AsArray;
|
BsonArray? layers = profileBson["Layers"]?.AsArray;
|
||||||
|
|
||||||
if (folders != null)
|
if (folders != null)
|
||||||
{
|
{
|
||||||
foreach (BsonValue folder in folders)
|
foreach (BsonValue folder in folders)
|
||||||
MigrateProfileElement(folder.AsDocument);
|
MigrateProfileElement(folder.AsDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layers != null)
|
if (layers != null)
|
||||||
{
|
{
|
||||||
foreach (BsonValue layer in layers)
|
foreach (BsonValue layer in layers)
|
||||||
@ -42,9 +47,11 @@ public class M0024NodeProviders : IStorageMigration
|
|||||||
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument);
|
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.Update(profileBson);
|
profilesToUpdate.Add(profileBson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collection.Update(profilesToUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateProfileElement(BsonDocument profileElement)
|
private void MigrateProfileElement(BsonDocument profileElement)
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using LiteDB;
|
||||||
|
|
||||||
|
namespace Artemis.Storage.Migrations.Storage;
|
||||||
|
|
||||||
|
public class M0025NodeProvidersProfileConfig : IStorageMigration
|
||||||
|
{
|
||||||
|
public int UserVersion => 25;
|
||||||
|
|
||||||
|
public void Apply(LiteRepository repository)
|
||||||
|
{
|
||||||
|
ILiteCollection<BsonDocument> categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity");
|
||||||
|
List<BsonDocument> toUpdate = new();
|
||||||
|
foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll())
|
||||||
|
{
|
||||||
|
BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray;
|
||||||
|
if (profiles != null)
|
||||||
|
{
|
||||||
|
foreach (BsonValue profile in profiles)
|
||||||
|
{
|
||||||
|
profile["Version"] = 2;
|
||||||
|
MigrateNodeScript(profile["ActivationCondition"]?.AsDocument);
|
||||||
|
}
|
||||||
|
toUpdate.Add(profileCategoryBson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
categoryCollection.Update(toUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateNodeScript(BsonDocument? nodeScript)
|
||||||
|
{
|
||||||
|
if (nodeScript == null || nodeScript.Keys.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BsonArray? nodes = nodeScript["Nodes"]?.AsArray;
|
||||||
|
if (nodes == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (BsonValue node in nodes)
|
||||||
|
{
|
||||||
|
node.AsDocument["Type"] = node.AsDocument["Type"]?.AsString?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||||
|
node.AsDocument["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user