mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Storage - Added migration for DB v5 to v6
Conditions - Fixed a conversion issue in operators
This commit is contained in:
parent
26daa8e1dd
commit
bdcca6b4be
@ -7,6 +7,12 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public abstract class ConditionOperator<TLeftSide, TRightSide> : BaseConditionOperator
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Type LeftSideType => typeof(TLeftSide);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Type RightSideType => typeof(TRightSide);
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the operator on a and b
|
||||
/// </summary>
|
||||
@ -21,33 +27,31 @@ namespace Artemis.Core
|
||||
TLeftSide leftSide;
|
||||
if (leftSideValue != null)
|
||||
{
|
||||
if (leftSideValue.GetType() != typeof(TLeftSide))
|
||||
if (leftSideValue.GetType() != typeof(TLeftSide) && leftSideValue is IConvertible)
|
||||
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
||||
else
|
||||
leftSide = (TLeftSide) leftSideValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftSide = default;
|
||||
}
|
||||
|
||||
TRightSide rightSide;
|
||||
if (rightSideValue != null)
|
||||
{
|
||||
if (rightSideValue.GetType() != typeof(TRightSide))
|
||||
if (rightSideValue.GetType() != typeof(TRightSide) && leftSideValue is IConvertible)
|
||||
rightSide = (TRightSide) Convert.ChangeType(rightSideValue, typeof(TRightSide));
|
||||
else
|
||||
rightSide = (TRightSide) rightSideValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
rightSide = default;
|
||||
}
|
||||
|
||||
return Evaluate(leftSide!, rightSide!);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Type LeftSideType => typeof(TLeftSide);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Type RightSideType => typeof(TRightSide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -55,6 +59,14 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public abstract class ConditionOperator<TLeftSide> : BaseConditionOperator
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Type LeftSideType => typeof(TLeftSide);
|
||||
|
||||
/// <summary>
|
||||
/// Always <c>null</c>, not applicable to this type of condition operator
|
||||
/// </summary>
|
||||
public override Type? RightSideType => null;
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the operator on a and b
|
||||
/// </summary>
|
||||
@ -68,23 +80,17 @@ namespace Artemis.Core
|
||||
TLeftSide leftSide;
|
||||
if (leftSideValue != null)
|
||||
{
|
||||
if (leftSideValue.GetType() != typeof(TLeftSide))
|
||||
leftSide = (TLeftSide)Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
||||
if (leftSideValue.GetType() != typeof(TLeftSide) && leftSideValue is IConvertible)
|
||||
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
||||
else
|
||||
leftSide = (TLeftSide)leftSideValue;
|
||||
leftSide = (TLeftSide) leftSideValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftSide = default;
|
||||
}
|
||||
|
||||
return Evaluate(leftSide!);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Type LeftSideType => typeof(TLeftSide);
|
||||
|
||||
/// <summary>
|
||||
/// Always <c>null</c>, not applicable to this type of condition operator
|
||||
/// </summary>
|
||||
public override Type? RightSideType => null;
|
||||
}
|
||||
}
|
||||
@ -1,34 +1,49 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using System;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M6PredicateAbstraction : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 7;
|
||||
public int UserVersion => 6;
|
||||
|
||||
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)
|
||||
{
|
||||
bsonLayer["DisplayCondition"] = null;
|
||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
||||
}
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
{
|
||||
bsonLayer["DisplayCondition"] = null;
|
||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
||||
}
|
||||
Migrate(bsonLayer);
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
|
||||
private void Migrate(BsonValue bsonValue)
|
||||
{
|
||||
if (bsonValue.IsArray)
|
||||
{
|
||||
foreach (BsonValue child in bsonValue.AsArray)
|
||||
Migrate(child);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bsonValue.IsDocument)
|
||||
{
|
||||
// See if the document has a type
|
||||
if (bsonValue.AsDocument.TryGetValue("_type", out BsonValue typeValue))
|
||||
{
|
||||
if (typeValue.AsString == "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionPredicateEntity, Artemis.Storage")
|
||||
bsonValue.AsDocument["_type"] = "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionGeneralPredicateEntity, Artemis.Storage";
|
||||
}
|
||||
|
||||
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
|
||||
Migrate(documentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user