-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Artemis.Storage/Migrations/Profile/M0002NodeProvidersProfileConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Artemis.Storage/Migrations/Storage/M0025NodeProvidersProfileConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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"); | ||
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); | ||
} | ||
} | ||
categoryCollection.Update(profileCategoryBson); | ||
} | ||
} | ||
|
||
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"; | ||
} | ||
} | ||
} |