mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data bindings - Added migration to identifier-based storage
This commit is contained in:
parent
6ba3e6941d
commit
a57dda8485
55
src/Artemis.Storage/Migrations/M10BetterDataBindings.cs
Normal file
55
src/Artemis.Storage/Migrations/M10BetterDataBindings.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M10BetterDataBindings : IStorageMigration
|
||||
{
|
||||
private void Migrate(BsonValue bsonValue)
|
||||
{
|
||||
if (!bsonValue.IsDocument || !bsonValue.AsDocument.TryGetValue("PropertyEntities", out BsonValue propertyEntities))
|
||||
return;
|
||||
|
||||
foreach (BsonValue propertyEntity in propertyEntities.AsArray)
|
||||
{
|
||||
if (!propertyEntity.AsDocument.TryGetValue("DataBindingEntities", out BsonValue dataBindingEntities))
|
||||
continue;
|
||||
foreach (BsonValue dataBindingEntity in dataBindingEntities.AsArray)
|
||||
{
|
||||
if (!dataBindingEntity.AsDocument.TryGetValue("TargetExpression", out BsonValue targetExpression))
|
||||
continue;
|
||||
string value = targetExpression.AsString;
|
||||
if (value == "value => value" || value == "b => b")
|
||||
{
|
||||
dataBindingEntity.AsDocument["Identifier"] = "Value";
|
||||
}
|
||||
else
|
||||
{
|
||||
string selector = value.Split("=>")[1];
|
||||
string property = selector.Split(".")[1];
|
||||
dataBindingEntity.AsDocument["Identifier"] = property;
|
||||
}
|
||||
|
||||
dataBindingEntity.AsDocument.Remove("TargetExpression");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int UserVersion => 10;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user