mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Move migrations to storage, add Storage migration for nodes change
This commit is contained in:
parent
313b4a0dea
commit
49ed0205b7
@ -5,7 +5,7 @@ using Artemis.Core.DryIoc.Factories;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using Artemis.Storage.Migrations;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using DryIoc;
|
||||
|
||||
@ -36,7 +36,7 @@ public static class ContainerExtensions
|
||||
|
||||
// Bind migrations
|
||||
container.RegisterMany(storageAssembly, type => type.IsAssignableTo<IStorageMigration>(), Reuse.Singleton, nonPublicServiceTypes: true);
|
||||
container.RegisterMany(coreAssembly, type => type.IsAssignableTo<IProfileMigration>(), Reuse.Singleton, nonPublicServiceTypes: true);
|
||||
container.RegisterMany(storageAssembly, type => type.IsAssignableTo<IProfileMigration>(), Reuse.Singleton, nonPublicServiceTypes: true);
|
||||
|
||||
container.RegisterMany(coreAssembly, type => type.IsAssignableTo<ILayoutProvider>(), Reuse.Singleton);
|
||||
container.Register<IPluginSettingsFactory, PluginSettingsFactory>(Reuse.Singleton);
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Core.Services;
|
||||
|
||||
internal interface IProfileMigration
|
||||
{
|
||||
int Version { get; }
|
||||
void Migrate(JObject profileJson);
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Core.Services.ProfileMigrators;
|
||||
|
||||
/// <summary>
|
||||
/// Migrates nodes to be provider-based.
|
||||
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
|
||||
/// </summary>
|
||||
internal class M0001NodeProviders : IProfileMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Version => 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Migrate(JObject profileJson)
|
||||
{
|
||||
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
|
||||
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
|
||||
|
||||
if (folders != null)
|
||||
{
|
||||
foreach (JToken folder in folders)
|
||||
{
|
||||
MigrateProfileElement(folder);
|
||||
}
|
||||
}
|
||||
|
||||
if (layers != null)
|
||||
{
|
||||
foreach (JToken layer in layers)
|
||||
{
|
||||
MigrateProfileElement(layer);
|
||||
MigratePropertyGroup(layer["GeneralPropertyGroup"]);
|
||||
MigratePropertyGroup(layer["TransformPropertyGroup"]);
|
||||
MigratePropertyGroup(layer["LayerBrush"]?["PropertyGroup"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateProfileElement(JToken profileElement)
|
||||
{
|
||||
JArray? layerEffects = (JArray?) profileElement["LayerEffects"]?["$values"];
|
||||
if (layerEffects != null)
|
||||
{
|
||||
foreach (JToken layerEffect in layerEffects)
|
||||
MigratePropertyGroup(layerEffect["PropertyGroup"]);
|
||||
}
|
||||
|
||||
JToken? displayCondition = profileElement["DisplayCondition"];
|
||||
if (displayCondition != null)
|
||||
MigrateNodeScript(displayCondition["Script"]);
|
||||
}
|
||||
|
||||
private void MigratePropertyGroup(JToken? propertyGroup)
|
||||
{
|
||||
if (propertyGroup == null || !propertyGroup.HasValues)
|
||||
return;
|
||||
|
||||
JArray? properties = (JArray?) propertyGroup["Properties"]?["$values"];
|
||||
JArray? propertyGroups = (JArray?) propertyGroup["PropertyGroups"]?["$values"];
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
foreach (JToken property in properties)
|
||||
MigrateNodeScript(property["DataBinding"]?["NodeScript"]);
|
||||
}
|
||||
|
||||
if (propertyGroups != null)
|
||||
{
|
||||
foreach (JToken childPropertyGroup in propertyGroups)
|
||||
MigratePropertyGroup(childPropertyGroup);
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Migrations;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@ -523,10 +524,10 @@ internal class ProfileService : IProfileService
|
||||
public async Task<ProfileConfiguration> OverwriteProfile(MemoryStream archiveStream, ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
ProfileConfiguration imported = await ImportProfile(archiveStream, profileConfiguration.Category, true, true, null, profileConfiguration.Order + 1);
|
||||
|
||||
|
||||
DeleteProfile(profileConfiguration);
|
||||
SaveProfileCategory(imported.Category);
|
||||
|
||||
|
||||
return imported;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
using LiteDB;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Storage.Migrations;
|
||||
|
||||
internal interface IProfileMigration
|
||||
public interface IProfileMigration
|
||||
{
|
||||
int Version { get; }
|
||||
void Migrate(JObject profileJson);
|
||||
void Migrate(BsonDocument profileBson);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations.Interfaces;
|
||||
namespace Artemis.Storage.Migrations;
|
||||
|
||||
public interface IStorageMigration
|
||||
{
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using LiteDB;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Storage.Migrations.Profile;
|
||||
@ -21,9 +20,7 @@ internal class M0001NodeProviders : IProfileMigration
|
||||
if (folders != null)
|
||||
{
|
||||
foreach (JToken folder in folders)
|
||||
{
|
||||
MigrateProfileElement(folder);
|
||||
}
|
||||
}
|
||||
|
||||
if (layers != null)
|
||||
@ -38,12 +35,6 @@ internal class M0001NodeProviders : IProfileMigration
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Migrate(BsonDocument profileBson)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private void MigrateProfileElement(JToken profileElement)
|
||||
{
|
||||
JArray? layerEffects = (JArray?) profileElement["LayerEffects"]?["$values"];
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations;
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0020AvaloniaReset : IStorageMigration
|
||||
{
|
||||
|
||||
@ -3,10 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations;
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0021GradientNodes : IStorageMigration
|
||||
{
|
||||
|
||||
@ -3,10 +3,9 @@ using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Artemis.Storage.Entities.Profile.Conditions;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations;
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0022TransitionNodes : IStorageMigration
|
||||
{
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations;
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0023LayoutProviders : IStorageMigration
|
||||
{
|
||||
|
||||
100
src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs
Normal file
100
src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0024NodeProviders : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 24;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
List<ProfileCategoryEntity> profileCategories = repository.Query<ProfileCategoryEntity>().ToList();
|
||||
foreach (ProfileCategoryEntity profileCategory in profileCategories)
|
||||
{
|
||||
foreach (ProfileConfigurationEntity profileConfigurationEntity in profileCategory.ProfileConfigurations)
|
||||
{
|
||||
profileConfigurationEntity.Version = 1;
|
||||
}
|
||||
repository.Update(profileCategory);
|
||||
}
|
||||
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument profileBson in collection.FindAll())
|
||||
{
|
||||
BsonArray? folders = profileBson["Folders"]?.AsArray;
|
||||
BsonArray? layers = profileBson["Layers"]?.AsArray;
|
||||
|
||||
if (folders != null)
|
||||
{
|
||||
foreach (BsonValue folder in folders)
|
||||
MigrateProfileElement(folder.AsDocument);
|
||||
}
|
||||
|
||||
if (layers != null)
|
||||
{
|
||||
foreach (BsonValue layer in layers)
|
||||
{
|
||||
MigrateProfileElement(layer.AsDocument);
|
||||
MigratePropertyGroup(layer.AsDocument["GeneralPropertyGroup"].AsDocument);
|
||||
MigratePropertyGroup(layer.AsDocument["TransformPropertyGroup"].AsDocument);
|
||||
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument);
|
||||
}
|
||||
}
|
||||
|
||||
collection.Update(profileBson);
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateProfileElement(BsonDocument profileElement)
|
||||
{
|
||||
BsonArray? layerEffects = profileElement["LayerEffects"]?.AsArray;
|
||||
if (layerEffects != null)
|
||||
{
|
||||
foreach (BsonValue layerEffect in layerEffects)
|
||||
MigratePropertyGroup(layerEffect.AsDocument["PropertyGroup"].AsDocument);
|
||||
}
|
||||
|
||||
BsonValue? displayCondition = profileElement["DisplayCondition"];
|
||||
if (displayCondition != null)
|
||||
MigrateNodeScript(displayCondition.AsDocument["Script"].AsDocument);
|
||||
}
|
||||
|
||||
private void MigratePropertyGroup(BsonDocument? propertyGroup)
|
||||
{
|
||||
if (propertyGroup == null || propertyGroup.Keys.Count == 0)
|
||||
return;
|
||||
|
||||
BsonArray? properties = propertyGroup["Properties"]?.AsArray;
|
||||
BsonArray? propertyGroups = propertyGroup["PropertyGroups"]?.AsArray;
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
foreach (BsonValue property in properties)
|
||||
MigrateNodeScript(property.AsDocument["DataBinding"]?["NodeScript"]?.AsDocument);
|
||||
}
|
||||
|
||||
if (propertyGroups != null)
|
||||
{
|
||||
foreach (BsonValue childPropertyGroup in propertyGroups)
|
||||
MigratePropertyGroup(childPropertyGroup.AsDocument);
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using Artemis.Storage.Migrations;
|
||||
using LiteDB;
|
||||
using Serilog;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user